Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
color-convert
Advanced tools
The color-convert npm package is a library for converting colors between different color models such as RGB, HSL, HSV, HEX, and more. It provides functions for one-to-one, one-to-many, and many-to-one conversions.
RGB to HEX conversion
Converts an RGB color value to its HEX representation.
const convert = require('color-convert');
const hexColor = convert.rgb.hex(255, 255, 255);
HEX to HSL conversion
Converts a HEX color value to its HSL representation.
const convert = require('color-convert');
const hslColor = convert.hex.hsl('FFFFFF');
HSL to HSV conversion
Converts an HSL color value to its HSV representation.
const convert = require('color-convert');
const hsvColor = convert.hsl.hsv(360, 100, 100);
Keyword to RGB conversion
Converts a CSS keyword color value to its RGB representation.
const convert = require('color-convert');
const rgbColor = convert.keyword.rgb('blue');
ANSI 16 to HEX conversion
Converts an ANSI 16 color code to its HEX representation.
const convert = require('color-convert');
const hexColor = convert.ansi16.hex(90);
chroma-js is a powerful library for all kinds of color conversions and manipulations. It supports a wide range of color models, similar to color-convert, but also includes functions for color scale generation, interpolation, and more complex color operations.
tinycolor2 is a small, fast library for color manipulation and conversion in JavaScript. It provides many of the same conversion capabilities as color-convert but also includes additional features for checking color properties, such as brightness and readability.
color is a JavaScript library for immutable color conversion and manipulation with support for CSS color strings. It offers a chainable API and is similar to color-convert in terms of conversion features but also includes manipulation functions like lighten, darken, saturate, and desaturate.
Color-convert is a color conversion library for JavaScript and node.
It converts all ways between rgb
, hsl
, hsv
, hwb
, cmyk
, ansi
, ansi16
, hex
strings, and CSS keyword
s (will round to closest):
var convert = require('color-convert');
convert.rgb.hsl(140, 200, 100); // [96, 48, 59]
convert.keyword.rgb('blue'); // [0, 0, 255]
var rgbChannels = convert.rgb.channels; // 3
var cmykChannels = convert.cmyk.channels; // 4
var ansiChannels = convert.ansi16.channels; // 1
$ npm install color-convert
Simply get the property of the from and to conversion that you're looking for.
All functions have a rounded and unrounded variant. By default, return values are rounded. To get the unrounded (raw) results, simply tack on .raw
to the function.
All 'from' functions have a hidden property called .channels
that indicates the number of channels the function expects (not including alpha).
var convert = require('color-convert');
// Hex to LAB
convert.hex.lab('DEADBF'); // [ 76, 21, -2 ]
convert.hex.lab.raw('DEADBF'); // [ 75.56213190997677, 20.653827952644754, -2.290532499330533 ]
// RGB to CMYK
convert.rgb.cmyk(167, 255, 4); // [ 35, 0, 98, 0 ]
convert.rgb.cmyk.raw(167, 255, 4); // [ 34.509803921568626, 0, 98.43137254901961, 0 ]
All functions that accept multiple arguments also support passing an array.
Note that this does not apply to functions that convert from a color that only requires one value (e.g. keyword
, ansi256
, hex
, etc.)
var convert = require('color-convert');
convert.rgb.hex(123, 45, 67); // '7B2D43'
convert.rgb.hex([123, 45, 67]); // '7B2D43'
Conversions that don't have an explicitly defined conversion (in conversions.js), but can be converted by means of sub-conversions (e.g. XYZ -> RGB -> CMYK), are automatically routed together. This allows just about any color model supported by color-convert
to be converted to any other model, so long as a sub-conversion path exists. This is also true for conversions requiring more than one step in between (e.g. LCH -> LAB -> XYZ -> RGB -> Hex).
Keep in mind that extensive conversions may result in a loss of precision, and exist only to be complete. For a list of "direct" (single-step) conversions, see conversions.js.
If there is a new model you would like to support, or want to add a direct conversion between two existing models, please send us a pull request.
Copyright © 2011-2016, Heather Arthur and Josh Junon. Licensed under the MIT License.
FAQs
Plain color conversion functions
The npm package color-convert receives a total of 163,774,284 weekly downloads. As such, color-convert popularity was classified as popular.
We found that color-convert 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.