Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
color-space
Advanced tools
Convert color from/to any color space or get space data. Spaces can be required selectively.
The color-space npm package provides a comprehensive set of tools for color space conversion and manipulation. It supports a wide range of color spaces and allows for easy conversion between them.
RGB to HSL Conversion
This feature allows you to convert colors from the RGB color space to the HSL color space. The code sample demonstrates converting a red color in RGB to its HSL representation.
const colorSpace = require('color-space');
const rgb = [255, 0, 0];
const hsl = colorSpace.rgb.hsl(rgb);
console.log(hsl); // [0, 100, 50]
HSL to RGB Conversion
This feature allows you to convert colors from the HSL color space to the RGB color space. The code sample demonstrates converting a red color in HSL to its RGB representation.
const colorSpace = require('color-space');
const hsl = [0, 100, 50];
const rgb = colorSpace.hsl.rgb(hsl);
console.log(rgb); // [255, 0, 0]
CMYK to RGB Conversion
This feature allows you to convert colors from the CMYK color space to the RGB color space. The code sample demonstrates converting a red color in CMYK to its RGB representation.
const colorSpace = require('color-space');
const cmyk = [0, 1, 1, 0];
const rgb = colorSpace.cmyk.rgb(cmyk);
console.log(rgb); // [255, 0, 0]
XYZ to LAB Conversion
This feature allows you to convert colors from the XYZ color space to the LAB color space. The code sample demonstrates converting a color in XYZ to its LAB representation.
const colorSpace = require('color-space');
const xyz = [41.24, 21.26, 1.93];
const lab = colorSpace.xyz.lab(xyz);
console.log(lab); // [53.23288178584245, 80.10930952982204, 67.22006831026425]
The color-convert package provides similar functionality for converting between different color spaces. It supports a wide range of color spaces and offers a simple API for conversions. Compared to color-space, color-convert is more focused on providing a straightforward conversion API without additional manipulation features.
Chroma.js is a powerful library for color manipulation and conversion. It supports a wide range of color spaces and provides additional features for color interpolation, blending, and more. Compared to color-space, Chroma.js offers more advanced color manipulation capabilities and a more user-friendly API.
TinyColor is a small, fast library for color manipulation and conversion. It supports a variety of color spaces and provides a simple API for common color operations. Compared to color-space, TinyColor is more lightweight and focused on providing essential color manipulation features.
Color-space provides conversions and data for the following color spaces: RGB, HSl, HSV (HSB), HWB, CMYK, CMY, XYZ, XYY (YXY), LAB, LCHab, LUV, LCHuv, HuSL, HuSLp, LABHunter, LMS.
Include color-space.js or color-space.min.js on the page (before you’ll use it):
<script src="path-to/color-space.js"></script>
Alternately you can include a CDN version:
<script src="https://cdn.rawgit.com/dfcreative/color-space/master/dist/color-space.min.js"></script>
Now you have a window.colorSpace
object, so you can play around with it:
<script>
var rgb = colorSpace.rgb;
//convert rgb to hsl
var hslColor = rgb.hsl([255,0,0]);
</script>
If you aware of final size, you can get your own build via browserify, including only needed target spaces. See how to include spaces separately below.
First install color-space as a local module:
$ npm install --save color-space
Then include color-space
:
var colorSpace = require('color-space');
//convert lab to lch
var result = colorSpace.lab.lch([80,50,60]);
Each space can also be required separately as require('color-space/<space>')
:
var rgb = require('color-space/rgb');
var hsl = require('color-space/hsl');
//convert rgb to hsl
rgb.hsl([200,230,100]);
Note that in case of requiring specific spaces you might need to add absent conversions via color-space/util/add-convertor
.
API of color-space is straightforward.
You can convert one space to another:
<fromSpace>.<toSpace>(array);
Also you can get space data:
<space>.name //space name
<space>.min //channel minimums
<space>.max //channel maximums
<space>.channel //channel names
<space>.alias //alias space names, if any
xyz.whitepoint //list of whitepoint references
lms.transform //list of transform matrices
Please fork, add color space with basic conversions to/from XYZ or RGB and tests. Color-space is supposed to be a basic library to work with color conversions, an enhanced replacement for color-convert.
FAQs
Collection of color space conversions
The npm package color-space receives a total of 298,617 weekly downloads. As such, color-space popularity was classified as popular.
We found that color-space demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers 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.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.