JSPM

  • Created
  • Published
  • Downloads 410684
  • Score
    100M100P100Q214382F

Conversion functions and space data. Full list of spaces.

Package Exports

  • color-space
  • color-space/cmyk
  • color-space/hsl
  • color-space/hsv
  • color-space/lab
  • color-space/lchab
  • color-space/rgb
  • color-space/util/to-source
  • color-space/xyz

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (color-space) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Color-space Build Status Code Climate

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.

  1. Color-space has the most complete list of color convertions so far, comparing to color-convert, chromatist, spectra, colorspaces.js and others.
  2. It can be used both in browser and node.
  3. Each space can be required selectively as require('color-space/<space>').
  4. It has immediate conversions between hsv, hsl and hwb, as well as lchuv and lchab, which preserves hue.
  5. It provides meta information about spaces: channel names, minimums, maximums, aliases.

Color converter & tests

Use

In browser:

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.

In node:

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

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

Contribute

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.

NPM