<commit_before># colorspaces.js

A tiny JavaScript and [Node.js](http://nodejs.org) library for manipulating colors. Works as a [Stylus](http://learnboost.github.com/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][CIEXYZ] or [CIELUV][CIELUV]. Read more about color spaces in [my blog post](http://boronine.com/2012/03/26/Color-Spaces-for-Human-Beings/).

## Installation

On the server, `npm install colorspaces`.

On the client, use the latest [colorspaces.js][dist-regular] or [colorspaces.min.js][dist-min].

## 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.

```javascript
var red = $.colorspaces.make_color('sRGB', [1, 0, 0]);
var green = $.colorspaces.make_color('hex', '#00ff00');
var 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.

```javascript
> red.as('CIELUV')
[ 53.23288178584245, 175.05303573649485, 37.75050503266512 ]
> blue.as('hex')
'#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.

```javascript
> var conv = colorspaces.converter('CIELUV', 'hex')
> conv([53.233, 175.053, 37.75])
'#ff0000'
```

## Stylus Support

You can use colorspaces.js in you Stylus stylesheets. From the command line, you have to run Stylus like this:

```bash
$ stylus -u colorspaces < in.styl
```

Or if you are using it as middleware:

```javascript
var colorspaces = require('colorspaces');
app.use(stylus.middleware({
  src: __dirname + '/app/views',
  dest: __dirname + '/public',
  compile: function(str, path) {
    return stylus(str)
      .set('filename', path)
      .use(colorspaces());
  }
});
```<commit_msg>Mention that Stylus must be installed explicitly. Fixes #4<commit_after># colorspaces.js

A tiny JavaScript and [Node.js](http://nodejs.org) library for manipulating colors. Works as a [Stylus](http://learnboost.github.com/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][CIEXYZ] or [CIELUV][CIELUV]. Read more about color spaces in [my blog post](http://boronine.com/2012/03/26/Color-Spaces-for-Human-Beings/).

## Installation

On the server, `npm install colorspaces`.

On the client, use the latest [colorspaces.js][dist-regular] or [colorspaces.min.js][dist-min].

## 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.

```javascript
var red = $.colorspaces.make_color('sRGB', [1, 0, 0]);
var green = $.colorspaces.make_color('hex', '#00ff00');
var 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.

```javascript
> red.as('CIELUV')
[ 53.23288178584245, 175.05303573649485, 37.75050503266512 ]
> blue.as('hex')
'#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.

```javascript
> var conv = colorspaces.converter('CIELUV', 'hex')
> conv([53.233, 175.053, 37.75])
'#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:

```bash
$ stylus -u colorspaces < in.styl
```

Or if you are using it programmatically:

```javascript
var stylus = require('stylus');
var colorspaces = require('colorspaces');

function renderWithColorspaces(str) {
	return stylus(str).use(colorspaces()).render();
}
```
{'fraction_non_alphanumeric': 0.10484330484330484, 'fraction_numerical': 0.0389363722697056, 'mean_word_length': 4.742639040348964, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6730837', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1536, 'n_words': 664}