Gathering detailed insights and metrics for color-convert
Gathering detailed insights and metrics for color-convert
Gathering detailed insights and metrics for color-convert
Gathering detailed insights and metrics for color-convert
Plain color conversion functions in JavaScript
npm install color-convert
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.6
Supply Chain
99.6
Quality
81
Maintenance
100
Vulnerability
100
License
JavaScript (69.41%)
TypeScript (30.59%)
Total Downloads
38,258,913,609
Last Day
12,725,607
Last Week
207,426,431
Last Month
903,037,641
Last Year
11,008,692,237
MIT License
792 Stars
149 Commits
98 Forks
12 Watchers
2 Branches
29 Contributors
Updated on Jul 03, 2025
Minified
Minified + Gzipped
Latest Version
3.1.0
Package Id
color-convert@3.1.0
Unpacked Size
46.72 kB
Size
12.74 kB
File Count
7
NPM Version
10.9.2
Node Version
22.15.0
Published on
May 13, 2025
Cumulative downloads
Total Downloads
Last Day
-10.5%
12,725,607
Compared to previous day
Last Week
-9%
207,426,431
Compared to previous week
Last Month
2.3%
903,037,641
Compared to previous month
Last Year
2.2%
11,008,692,237
Compared to previous year
1
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):
1import convert from 'color-convert'; 2 3convert.rgb.hsl(140, 200, 100); // [96, 48, 59] 4convert.keyword.rgb('blue'); // [0, 0, 255] 5 6const rgbChannels = convert.rgb.channels; // 3 7const cmykChannels = convert.cmyk.channels; // 4 8const ansiChannels = convert.ansi16.channels; // 1
1npm 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).
1import convert from 'color-convert'; 2 3// Hex to LAB 4convert.hex.lab('DEADBF'); // [ 76, 21, -2 ] 5convert.hex.lab.raw('DEADBF'); // [ 75.56213190997677, 20.653827952644754, -2.290532499330533 ] 6 7// RGB to CMYK 8convert.rgb.cmyk(167, 255, 4); // [ 35, 0, 98, 0 ] 9convert.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.)
1import convert from 'color-convert'; 2 3convert.rgb.hex(123, 45, 67); // '7B2D43' 4convert.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.
Conversions rely on an agreed upon 'full-scale' value for each of the channels. Listed here are those values for the most common color spaces
channel | full-scale value |
---|---|
r | 255 |
g | 255 |
b | 255 |
channel | full-scale value |
---|---|
h | 360 |
s | 100 |
l | 100 |
channel | full-scale value |
---|---|
h | 360 |
s | 100 |
v | 100 |
channel | full-scale value |
---|---|
h | 360 |
w | 100 |
b | 100 |
channel | full-scale value |
---|---|
x | 94 |
y | 99 |
z | 108 |
channel | full-scale value |
---|---|
l | 100 |
a | -86, 98 |
b | -108, 94 |
channel | full-scale value |
---|---|
l | 100 |
c | 133 |
h | 360 |
channel | full-scale value |
---|---|
l | 100 |
a | -23, 28 |
b | -31, 20 |
channel | full-scale value |
---|---|
l | 100 |
c | 32 |
h | 360 |
channel | full-scale value |
---|---|
c | 100 |
m | 100 |
y | 100 |
k | 100 |
channel | full-scale value |
---|---|
hex | 0xffffff |
channel | value |
---|---|
name | any key from color-name |
channel | full-scale value |
---|---|
0 | 65535 |
1 | 65535 |
2 | 65535 |
channel | full-scale value |
---|---|
gray | 100 |
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. Copyright © 2016-2021, Josh Junon.
Licensed under the MIT License.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
branch protection is not maximal on development and all release branches
Details
Reason
Found 8/30 approved changesets -- score normalized to 2
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More