-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
249 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"language": "en", | ||
"ignoreWordsList": [], | ||
"mistakeTypeToStatus": { | ||
"Passive voice": "Hint", | ||
"Spelling": "Error", | ||
"Complex Expression": "Disable", | ||
"Hidden Verbs": "Information", | ||
"Hyphen Required": "Disable", | ||
"Redundant Expression": "Disable", | ||
"Did you mean...": "Disable", | ||
"Repeated Word": "Warning", | ||
"Missing apostrophe": "Warning", | ||
"Cliches": "Disable", | ||
"Missing Word": "Disable", | ||
"Make I uppercase": "Warning" | ||
}, | ||
"languageIDs": [ | ||
"markdown", | ||
"plaintext" | ||
], | ||
"ignoreRegExp": [ | ||
"/\\(.*\\.(jpg|jpeg|png|gif|JPG|JPEG|PNG|GIF)\\)/g", | ||
"/((http|https|ftp|git)\\S*)/g" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,64 @@ | ||
import { | ||
HEXA_COLOR | ||
HEXA_COLOR, | ||
RGB_COLOR | ||
} from './color-regex'; | ||
import Color from './color'; | ||
|
||
// Flatten Array | ||
// flatten(arr[[1,2,3],[4,5]]) -> arr[1,2,3,4,5] | ||
const flatten = arr => arr.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []); | ||
|
||
class ColorUtil { | ||
public static getRGB(color: Color): number[] { | ||
let rgb: any[] = []; | ||
if (color.model === 'hexa') { | ||
rgb = /#(.+)/gi.exec(color.value); | ||
if (rgb[1].length === 3) { | ||
return rgb[1].split('').map(_ => parseInt(_ + _, 16)); | ||
} | ||
rgb = rgb[1].split('').map(_ => parseInt(_, 16)); | ||
return [16 * rgb[0] + rgb[1], 16 * rgb[2] + rgb[3], 16 * rgb[4] + rgb[5]]; | ||
} | ||
return []; | ||
} | ||
|
||
public static luminance(color: Color): number { | ||
let rgb = this.getRGB(color); | ||
if (!rgb) { | ||
return null; | ||
} | ||
rgb = rgb.map(_ => { | ||
_ = _ / 255; | ||
if (_ < 0.03928) { | ||
_ = _ / 12.92; | ||
let rgb = color.rgb; | ||
rgb = rgb.map(c => { | ||
c = c / 255; | ||
if (c < 0.03928) { | ||
c = c / 12.92; | ||
} else { | ||
_ = (_ + .055) / 1.055; | ||
_ = Math.pow(_, 2.4); | ||
c = (c + .055) / 1.055; | ||
c = Math.pow(c, 2.4); | ||
} | ||
return _; | ||
return c; | ||
}); | ||
return 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]; | ||
return (0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]); | ||
} | ||
|
||
public static extractColor(text: string):Color[] { | ||
let colors:Color[] = []; | ||
colors = colors.concat(this._extractHexa(text)); | ||
return colors; | ||
public static findColors(text): Promise < Color[] > { | ||
return Promise.all([ | ||
this._extractHexa(text), | ||
this._extractRGB(text) | ||
]).then(colors => { | ||
return flatten(colors); | ||
}); | ||
} | ||
|
||
public static match(text: string, model: string):boolean { | ||
switch(model) { | ||
case 'hexa': | ||
return !!text.match(HEXA_COLOR); | ||
default: | ||
return false; | ||
} | ||
private static _extractHexa(text: string): Promise < Color[] > { | ||
return new Promise((resolve, reject) => { | ||
let match = null; | ||
let colors: Color[] = []; | ||
while ((match = HEXA_COLOR.exec(text)) !== null) { | ||
colors.push(new Color('hexa', match[1], match.index)); | ||
} | ||
return resolve(colors); | ||
}); | ||
} | ||
|
||
private static _extractHexa(text: string): Color[] { | ||
let match = null; | ||
let colors:Color[] = []; | ||
while((match = HEXA_COLOR.exec(text)) !== null) { | ||
colors.push(new Color('hexa', match[1], match.index)) | ||
} | ||
return colors; | ||
|
||
private static _extractRGB(text: string): Promise < Color[] > { | ||
return new Promise((resolve, reject) => { | ||
let match = null; | ||
let colors: Color[] = []; | ||
// Get rgb "like" colors | ||
while ((match = RGB_COLOR.exec(text)) !== null) { | ||
let rgba = match[1].replace(/rgb(a){0,1}\(/, '').replace(/\)/, '').split(/,/gi).map(c => parseFloat(c)); | ||
// Check if it's a valid rgb(a) color | ||
if (rgba.slice(0, 3).every(c => c <= 255) && (rgba[4] || 1) <= 1) { | ||
colors.push(new Color('rgb', match[0], match.index)); | ||
} | ||
} | ||
return resolve(colors); | ||
}); | ||
} | ||
}; | ||
export default ColorUtil; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.