Installations
npm install colorspaces
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
6.9.1
NPM Version
3.10.8
Score
71.7
Supply Chain
98.8
Quality
75.4
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (99.09%)
Makefile (0.91%)
Developer
boronine
Download Statistics
Total Downloads
18,285
Last Day
21
Last Week
55
Last Month
264
Last Year
2,314
GitHub Statistics
120 Stars
42 Commits
8 Forks
7 Watching
3 Branches
1 Contributors
Bundle Size
4.28 kB
Minified
1.80 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.1.5
Package Id
colorspaces@0.1.5
Size
6.45 kB
NPM Version
3.10.8
Node Version
6.9.1
Total Downloads
Cumulative downloads
Total Downloads
18,285
Last day
23.5%
21
Compared to previous day
Last week
-17.9%
55
Compared to previous week
Last month
12.8%
264
Compared to previous month
Last year
71.5%
2,314
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
colorspaces.js
NOTE: If all you want is perceptually uniform colors, check out HSLuv instead.
A tiny JavaScript and Node.js library for manipulating colors. Works as a Stylus plugin!
RGB, the color space we use here on the web is based on display technology, not human color perception. Most meaningful color operations are performed on colors in other color spaces, such as CIEXYZ or CIELUV. Read more about color spaces in my blog post.
Installation
On the server, npm install colorspaces
.
On the client, use the latest colorspaces.js or colorspaces.min.js.
Basic Use
colorspaces.make_color
takes two arguments: the name of the color space and an array of values representing the color in the color space.
1var red = $.colorspaces.make_color('sRGB', [1, 0, 0]); 2var green = $.colorspaces.make_color('hex', '#00ff00'); 3var blue = $.colorspaces.make_color('CIEXYZ', [0.1805, 0.0722, 0.9505]);
The returned object has a method, as
, that takes the name of a color space as its only argument and returns the coordinates of the color in that color space as an array.
1> red.as('CIELUV') 2[ 53.23288178584245, 175.05303573649485, 37.75050503266512 ] 3> blue.as('hex') 4'#0000ff'
These color objects also support two methods, both returning a boolean: is_displayable
and is_visible
. The first one determines whether the color is within the sRGB gamut and the second determines whether the color is within the CIE XYZ gamut. Note that both of these methods round the resulting values to three decimal spaces before checking whether they fit into their range; this is a useful policy because of rounding errors.
Lower Level
If you need to do many color conversions per second, you can optimize by using a low-level function converter
that takes two color space names as arguments and returns a converter function.
1> var conv = colorspaces.converter('CIELUV', 'hex') 2> conv([53.233, 175.053, 37.75]) 3'#ff0000'
Stylus Support
You can use colorspaces.js in you Stylus stylesheets. Note that colorspaces does not have Stylus as a dependency, you must install both explicitly before proceeding.
From the command line, you have to run Stylus like this:
1$ stylus -u colorspaces < in.styl
Or if you are using it programmatically:
1var stylus = require('stylus'); 2var colorspaces = require('colorspaces'); 3 4function renderWithColorspaces(str) { 5 return stylus(str).use(colorspaces()).render(); 6}
Now you have access to several functions that take numerical values and return a Stylus color. All color spaces below except for hex
and sRGB
are supported in the Stylus plugin. The Stylus function names match the color space names.
.someclass
color CIELCH(20.470, 74.265, 314.113)
You can still modify its opacity with Stylus' rgba
function:
.someclass
color rgba(CIELCH(20.470, 74.265, 314.113), 0.5)
Supported Color Spaces
All color spaces below define colors via numeric components. Sometimes the ranges for these numbers are strictly defined, sometimes they are unknown (e.g. the upper limit on chroma is undefined in CIE color spaces). This can be a problem if you want to generate colors in a perceptually uniform color space. To get around this problem I created HSLuv, a version of CIELCHuv with a bounded chroma component.
sRGB
: Standard RGB, the color space used on the web. All values range between 0 and 1. Be careful, rounding errors can result in values just outside this range.CIEXYZ
: One of the first mathematically defined color spaces. Values range between 0 and 0.95047, 1.0 and 1.08883 for X, Y and Z respectively. These three numbers together define the white point, which can be different depending on the chosen illuminant. The commonly used illuminant D65 was chosen for this project.CIExyY
: Normalized version of the above.CIELAB
: A color space made for perceptual uniformity. Recommended for characterization of color surfaces and dyes. L is lightness (0-100).CIELCH
: A cylindrical representation of CIELAB. L is lightness (0-100), C is chroma (think saturation) and H is hue (0-360).CIELUV
: Another color space made for perceptual uniformity. Recommended for characterization of color displays. L is lightness (0-100).CIELCHuv
: Same as CIELCH, but based on CIELUV.hex
: A string representation of sRGB.
Development
Run npm install
to install everything necessary to build and test the repo.
See Makefile
.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
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'
Score
3
/10
Last Scanned on 2025-01-27
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