Installations
npm install color-convert
Score
99.5
Supply Chain
89.6
Quality
75.9
Maintenance
100
Vulnerability
100
License
Developer
Qix-
Developer Guide
Module System
Unable to determine the module system for this package.
Min. Node Version
>=7.0.0
Typescript Support
No
Node Version
12.4.0
NPM Version
6.9.0
Statistics
746 Stars
142 Commits
96 Forks
12 Watching
2 Branches
27 Contributors
Updated on 12 Nov 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
33,070,198,056
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
color-convert
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
Install
1$ npm install color-convert
API
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 ]
Arrays
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'
Routing
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.
Color Space Scales
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
rgb
channel | full-scale value |
---|---|
r | 255 |
g | 255 |
b | 255 |
hsl
channel | full-scale value |
---|---|
h | 360 |
s | 100 |
l | 100 |
hsv
channel | full-scale value |
---|---|
h | 360 |
s | 100 |
v | 100 |
hwb
channel | full-scale value |
---|---|
h | 360 |
w | 100 |
b | 100 |
cmyk
channel | full-scale value |
---|---|
c | 100 |
m | 100 |
y | 100 |
k | 100 |
hex
channel | full-scale value |
---|---|
hex | 0xffffff |
keyword
channel | value |
---|---|
name | any key from color-name |
apple
channel | full-scale value |
---|---|
0 | 65535 |
1 | 65535 |
2 | 65535 |
gray
channel | full-scale value |
---|---|
g | 100 |
Contribute
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.
License
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
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
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/Qix-/color-convert/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/Qix-/color-convert/ci.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:32
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 9 are checked with a SAST tool
Score
3.6
/10
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