Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
The 'color' npm package is a library for immutable color conversion and manipulation with support for CSS color strings.
Color Parsing
Parse a CSS string to create a Color object.
const Color = require('color');
const color = Color('rgb(255, 255, 255)');
Color Manipulation
Manipulate colors by lightening, darkening, saturating, desaturating, etc., and then output as a string in a specified format.
const Color = require('color');
const color = Color('blue');
const lighterColor = color.lighten(0.5).hex();
Color Conversion
Convert colors between different models like RGB, HSL, HEX, etc.
const Color = require('color');
const color = Color('blue');
const rgbString = color.rgb().string();
chroma-js is a powerful library for all kinds of color conversions and color scales. It offers more complex color scale functions and color blending capabilities compared to 'color'.
tinycolor2 is a small, fast library for color manipulation and conversion in JavaScript. It provides similar functionality to 'color' but with a different API design and additional functions for color analysis.
color-convert is a library that handles the conversion between different color models. It is more focused on conversion than manipulation, unlike 'color' which offers both.
JavaScript library for immutable color conversion and manipulation with support for CSS color strings.
const color = Color('#7743CE').alpha(0.5).lighten(0.5);
console.log(color.hsl().string()); // 'hsla(262, 59%, 81%, 0.5)'
console.log(color.cmyk().round().array()); // [ 16, 25, 0, 8, 0.5 ]
console.log(color.ansi256().object()); // { ansi256: 183, alpha: 0.5 }
$ npm install color
const Color = require('color');
const color = Color('rgb(255, 255, 255)')
const color = Color({r: 255, g: 255, b: 255})
const color = Color.rgb(255, 255, 255)
const color = Color.rgb([255, 255, 255])
Set the values for individual channels with alpha
, red
, green
, blue
, hue
, saturationl
(hsl), saturationv
(hsv), lightness
, whiteness
, blackness
, cyan
, magenta
, yellow
, black
String constructors are handled by color-string
color.hsl();
Convert a color to a different space (hsl()
, cmyk()
, etc.).
color.object(); // {r: 255, g: 255, b: 255}
Get a hash of the color value. Reflects the color's current model (see above).
color.rgb().array() // [255, 255, 255]
Get an array of the values with array()
. Reflects the color's current model (see above).
color.rgbNumber() // 16777215 (0xffffff)
Get the rgb number value.
color.hex() // #ffffff
Get the hex value. (NOTE: .hex()
does not return alpha values; use .hexa()
for an RGBA representation)
color.red() // 255
Get the value for an individual channel.
color.hsl().string() // 'hsl(320, 50%, 100%)'
Calling .string()
with a number rounds the numbers to that decimal place. It defaults to 1.
color.luminosity(); // 0.412
The WCAG luminosity of the color. 0 is black, 1 is white.
color.contrast(Color("blue")) // 12
The WCAG contrast ratio to another color, from 1 (same color) to 21 (contrast b/w white and black).
color.isLight(); // true
color.isDark(); // false
Get whether the color is "light" or "dark", useful for deciding text color.
color.negate() // rgb(0, 100, 255) -> rgb(255, 155, 0)
color.lighten(0.5) // hsl(100, 50%, 50%) -> hsl(100, 50%, 75%)
color.lighten(0.5) // hsl(100, 50%, 0) -> hsl(100, 50%, 0)
color.darken(0.5) // hsl(100, 50%, 50%) -> hsl(100, 50%, 25%)
color.darken(0.5) // hsl(100, 50%, 0) -> hsl(100, 50%, 0)
color.lightness(50) // hsl(100, 50%, 10%) -> hsl(100, 50%, 50%)
color.saturate(0.5) // hsl(100, 50%, 50%) -> hsl(100, 75%, 50%)
color.desaturate(0.5) // hsl(100, 50%, 50%) -> hsl(100, 25%, 50%)
color.grayscale() // #5CBF54 -> #969696
color.whiten(0.5) // hwb(100, 50%, 50%) -> hwb(100, 75%, 50%)
color.blacken(0.5) // hwb(100, 50%, 50%) -> hwb(100, 50%, 75%)
color.fade(0.5) // rgba(10, 10, 10, 0.8) -> rgba(10, 10, 10, 0.4)
color.opaquer(0.5) // rgba(10, 10, 10, 0.8) -> rgba(10, 10, 10, 1.0)
color.rotate(180) // hsl(60, 20%, 20%) -> hsl(240, 20%, 20%)
color.rotate(-90) // hsl(60, 20%, 20%) -> hsl(330, 20%, 20%)
color.mix(Color("yellow")) // cyan -> rgb(128, 255, 128)
color.mix(Color("yellow"), 0.3) // cyan -> rgb(77, 255, 179)
// chaining
color.green(100).grayscale().lighten(0.6)
The API was inspired by color-js. Manipulation functions by CSS tools like Sass, LESS, and Stylus.
FAQs
Color conversion and manipulation with CSS string support
We found that color 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
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.