![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
colorparsley
Advanced tools
colorParsley() • a lightweight yet versatile color parsing function with no dependencies. Takes various color strings, numbers, or objects, and turns them into simple arrays. Bonus utilities colorToHex() and colorToRGB() included
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:
let textColor = colorParsley('#111111');
let backgroundColor = colorParsley('rgb(123,23,233,1.0)');
console.log(textColor); // [17,17,17,1,true,'sRGB']
console.log(backgroundColor); // [123,23,233,1,true,'sRGB']
// STRUCTURE
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.
// Entry Key Cleanup for better UX with auto-enter
function entryKeys(colorString,e) {
if (
(
(e.which >= 48 && e.which <= 57 && event.shiftKey == false) || // 0-9
(e.which >= 65 && e.which <= 90) || // a-z
(e.which >= 96 && e.which <= 105) // num keypad
) ||
e.which === 13 || // enter
e.which === 9 || // tab key
e.which === 188 || // comma key
e.which === 194 || // comma num keypad key
//e.which === 8 || // backspace
//e.which === 17 || // ctrl
//e.which === 46 || // delete
//(e.which >= 91 && e.which <= 93) || // OS key
(e.which === 48 && event.shiftKey == true) // close parenthesis
) {
let myNewColor = colorParsley(colorString);
showMeTheColor(myNewColor); // the function to do on entry.
}
}
Then in your input field, use onkeyup =
(or other appropriate event)
<input id="inputColorString"
type="text"
onclick="this.select();"
onkeyup="entryKeys(this.value,event);">
Regex flow chart svg created at https://www.debuggex.com/
//* // hslToRgb() hwbToRgb() from CSS shown here only as a reference
///// ƒ hslToRgb() ///////////////////////////////////////////////////
//// Unused, built into the string parser, here for reference
function hslToRgb (hue, sat, light) { // CSS4 reference implementation
hue = hue % 360;
if (hue < 0) { hue += 360; }
sat /= 100.0;
light /= 100.0;
function f(n) {
let k = (n + hue/30) % 12;
let a = sat * Math.min(light, 1 - light);
return light - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));
}
return [f(0), f(8), f(4)]; // returns 0.0 - 1.0
};
///// ƒ hwbToRgb() ///////////////////////////////////////////////////
//// Unused, built into the string parser, here for reference
function hwbToRgb(hue, white, black) { // CSS4 reference implementation
white /= 100.0;
black /= 100.0;
if (white + black >= 1) {
let gray = white / (white + black);
return [gray, gray, gray];
}
let rgb = hslToRgb(hue, 100.0, 50.0);
for (let i = 0; i < 3; i++) {
rgb[i] *= (1 - white - black);
rgb[i] += white;
}
return rgb; // returns 0.0 - 1.0
};
// */
FAQs
colorParsley() • a lightweight yet versatile color parsing function with no dependencies. Takes various color strings, numbers, or objects, and turns them into simple arrays. Bonus utilities colorToHex() and colorToRGB() included
The npm package colorparsley receives a total of 19,160 weekly downloads. As such, colorparsley popularity was classified as popular.
We found that colorparsley demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.