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
npm install color-convert
99.5
Supply Chain
89.6
Quality
75.9
Maintenance
100
Vulnerability
100
License
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
746 Stars
142 Commits
96 Forks
12 Watching
2 Branches
27 Contributors
Updated on 12 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-9.7%
40,922,729
Compared to previous day
Last week
-2.6%
217,499,114
Compared to previous week
Last month
-1.8%
960,642,129
Compared to previous month
Last year
18.1%
11,514,370,308
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
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).
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 |
---|---|
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 |
---|---|
g | 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
Found 8/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
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
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
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