Gathering detailed insights and metrics for colorparsley
Gathering detailed insights and metrics for colorparsley
Gathering detailed insights and metrics for colorparsley
Gathering detailed insights and metrics for colorparsley
@ergofriend/random-pair-colors
A simple library to generate Computational Theming Colors.
@ergofriend/focus-pair-reader
A Custom Element that applies a pair of colors to the focused element.
seestars
See Stars • a lightweight set of utilities to take an sRGB or displayP3 color, and extract the CIE Y relative luminance, and then convert to CIE L* (perceptual lightness). Takes RGB colors as simple arrays (as created with colorParsley). Bonus utilities t
A lightweight but versatile mini-lib to parse color strings, objects, or numbers, returning a simple rgba array, and related string utilities. This was developed as part of the basic APCA distro.
npm install colorparsley
Typescript
Module System
Node Version
NPM Version
95.5
Supply Chain
99.5
Quality
75.8
Maintenance
100
Vulnerability
81.3
License
JavaScript (84.25%)
HTML (15.75%)
Total Downloads
862,901
Last Day
4,588
Last Week
18,790
Last Month
72,599
Last Year
549,606
17 Stars
48 Commits
4 Forks
2 Watching
1 Branches
3 Contributors
Minified
Minified + Gzipped
Latest Version
0.1.8
Package Id
colorparsley@0.1.8
Unpacked Size
1.26 MB
Size
1.03 MB
File Count
11
NPM Version
8.12.1
Node Version
18.3.0
Cumulative downloads
Total Downloads
Last day
38.4%
4,588
Compared to previous day
Last week
1.2%
18,790
Compared to previous week
Last month
24%
72,599
Compared to previous month
Last year
91.9%
549,606
Compared to previous year
1
Current Version: 0.1.8
NEW in 0.1.8: colorToHex and colorToRGB now round by default, and input strings using CSS color() have output array values multiplied by 255 for consistency with all other arrays.. NEW in 0.1.7: output array will now always have an alpha value, with the default as 1 for inputs that lack an alpha. "Failed" parsings will return an alpha of 0.
ColoR PaRsLeY is a spin off of the SAPC/APCA project. It is a lightweight but powerful tool for parsing color values out of various string types. It supports HEX, RGB INT, HTML & CSS Named Colors, and a variety of additional color models.
ColoR PaRsLeY returns a simple four element array of RGBA INT for HEX or RGB INT inputs, but longer arrays are available for the specialty category.
NPM Install: npm i colorparsley
"colorParsley()" send it a string, it returns an rgba INT array:
1 let textColor = colorParsley('#111111'); 2 let backgroundColor = colorParsley('rgb(123,23,233,1.0)'); 3 4 console.log(textColor); // [17,17,17,1,true,'sRGB'] 5 console.log(backgroundColor); // [123,23,233,1,true,'sRGB'] 6 7 // STRUCTURE 8 returnedArray = [R,G,B,A,isValidBool,colorspaceString]
The following are the available input types for colorParsley(). All are automatically recognized:
'#abc'
or 'abc'
(interpreted as 'aabbcc'
)'#abcdef'
or 'abcdef'
(hash is ignored)'rgb(123, 45, 67)'
or '123,45,67'
'aquamarine'
or 'magenta'
(full CSS4 named colors list)'color(srgb 0.765 0.89 0.556)'
'#abcf'
or 'abcf'
(interpreted as 'aabbccff'
)'#123456ff'
or '123456ff'
(hash is ignored)'rgba(123, 45, 67, 1.0)'
'color(srgb 0.765 0.89 0.556 / 1)'
'#ab'
or 'ab'
(interpreted as if'ababab'
)'123,'
(interpreted as if'rgb(123, 123, 123)'
)'87%'
(interpreted as if 'rgb(87%, 87%, 87%)' = [221.85,221.85,221.85]
)color(srgb 0.765 0.89 0.556 / 1)
hsl(310,40%,60%, 1)
(alpha optional)colorToHex(colorParsley('rgb(170,187,204)'))
returns abc
colorToRGB(colorParsley('abc'))
returns rgb(170,187,204)
#a7a7a7
rgb(123,123,123)
%
: 87% means rgb(87%,87%,87%)
[221.85,221.85,221.85,'',...]
0xabcdef
11259375
No alpha parsing for numbers
All hex and rgb() inputs return a 6 element rgba NUMBER array
[255,255,255,1,true,'sRGB']
A value input with a percentage symbol % is divided by 100.0
Values are assumed to be 8bit unless a decimal point is found.
The "isValid" boolean is the 5th element in the return array.
The 6th array element is colorspace or model (i.e. hsl) (default sRGB)
[255,255,255,1,true,'sRGB']
Passthrough values to be added to the array to be returned.
[322,0.7,0.5,1,'hsv',2.2]
[0.95,1.1,0.76,1,'RGB','1.0','32.0f','D65']
[123,123,123,1,'ProPhoto','1.8','D50']
Thoughts? Discuss at the repo!
The following code snippet is useful for auto-enter entry fields where you want instant response. This function cleans up entry keys as needed — adjust the keys to allow for your interface.
Here the function just calls colorParsley(), but of course add whatever calls you need.
1 // Entry Key Cleanup for better UX with auto-enter 2 3 function entryKeys(colorString,e) { 4 if ( 5 ( 6 (e.which >= 48 && e.which <= 57 && event.shiftKey == false) || // 0-9 7 (e.which >= 65 && e.which <= 90) || // a-z 8 (e.which >= 96 && e.which <= 105) // num keypad 9 ) || 10 e.which === 13 || // enter 11 e.which === 9 || // tab key 12 e.which === 188 || // comma key 13 e.which === 194 || // comma num keypad key 14 //e.which === 8 || // backspace 15 //e.which === 17 || // ctrl 16 //e.which === 46 || // delete 17 //(e.which >= 91 && e.which <= 93) || // OS key 18 (e.which === 48 && event.shiftKey == true) // close parenthesis 19 ) { 20 let myNewColor = colorParsley(colorString); 21 showMeTheColor(myNewColor); // the function to do on entry. 22 } 23 }
Then in your input field, use onkeyup =
(or other appropriate event)
1 <input id="inputColorString" 2 type="text" 3 onclick="this.select();" 4 onkeyup="entryKeys(this.value,event);">
Regex flow chart svg created at https://www.debuggex.com/
1 2//* // hslToRgb() hwbToRgb() from CSS shown here only as a reference 3 4///// ƒ hslToRgb() /////////////////////////////////////////////////// 5 6 //// Unused, built into the string parser, here for reference 7function hslToRgb (hue, sat, light) { // CSS4 reference implementation 8 hue = hue % 360; 9 if (hue < 0) { hue += 360; } 10 sat /= 100.0; 11 light /= 100.0; 12 function f(n) { 13 let k = (n + hue/30) % 12; 14 let a = sat * Math.min(light, 1 - light); 15 return light - a * Math.max(-1, Math.min(k - 3, 9 - k, 1)); 16 } 17 return [f(0), f(8), f(4)]; // returns 0.0 - 1.0 18}; 19 20 21///// ƒ hwbToRgb() /////////////////////////////////////////////////// 22 23 //// Unused, built into the string parser, here for reference 24function hwbToRgb(hue, white, black) { // CSS4 reference implementation 25 white /= 100.0; 26 black /= 100.0; 27 if (white + black >= 1) { 28 let gray = white / (white + black); 29 return [gray, gray, gray]; 30 } 31 let rgb = hslToRgb(hue, 100.0, 50.0); 32 for (let i = 0; i < 3; i++) { 33 rgb[i] *= (1 - white - black); 34 rgb[i] += white; 35 } 36 return rgb; // returns 0.0 - 1.0 37}; 38// */
No vulnerabilities found.
No security vulnerabilities found.