dot-colors

Color conversion utilities

dot-colors

Author: Robert Ginda rginda@google.com Port to Node.js: Mike Acton macton@gmail.com

The bulk of this file is color palettes. The rest is a few simple utility functions

For node with npm:

npm install dot-colors

And use with var colors = require("dot-colors")

colors   = require('dot-colors');
x11Value = colors.rgbToX11( rgbValue );

Convert a CSS rgb(ddd,ddd,ddd) color value into an X11 color value. Other CSS color values are ignored to ensure sanitary data handling. Each 'ddd' component is a one byte value specified in decimal.

The X11 color value or null if the value could not be converted.

(Return to API)

colors   = require('dot-colors');
cssValue = colors.x11ToCSS( x11Value );

Convert an X11 color value into an CSS rgb(...) color value.

The X11 value may be an X11 color name, or an RGB value of the form rgb:hhhh/hhhh/hhhh. If a component value is less than 4 digits it is padded out to 4, then scaled down to fit in a single byte.

The CSS color value or null if the value could not be converted.

(Return to API)

colors   = require('dot-colors');
rgbValue = colors.hexToRGB( hexValue );

Converts one or more CSS '#RRGGBB' color values into their rgb(...) form.

Arrays are converted in place. If a value cannot be converted, it is replaced with null.

The converted value or values.

(Return to API)

colors   = require('dot-colors');
hexValue = colors.rgbToHex( rgbValue );

Converts one or more CSS rgb(...) forms into their '#RRGGBB' color values.

If given an rgba(...) form, the alpha field is thrown away.

Arrays are converted in place. If a value cannot be converted, it is replaced with null.

The converted value or values.

(Return to API)

colors          = require('dot-colors');
normalizedValue = colors.normalizeCSS( cssValue );

Take any valid css color definition and turn it into an rgb or rgba value.

Returns null if the value could not be normalized.

(Return to API)

colors    = require('dot-colors');
rgbaValue = colors.template( arrayValueValue );

Convert a 3 or 4 element array into an rgba(...) string.

(Return to API)

colors    = require('dot-colors');
rgbaValue = colors.setAlpha( rgbValue );

Overwrite the alpha channel of an rgb/rgba color.

(Return to API)

colors      = require('dot-colors');
resultColor = colors.template( base, tint, percent );

Mix a percentage of a tint color into a base color.

(Return to API)

colors    = require('dot-colors');
rgbaValue = colors.crackRGB( colorValue );

Split an rgb/rgba color into an array of its components.

On success, a 4 element array will be returned. For rgb values, the alpha will be set to 1.

(Return to API)

colors   = require('dot-colors');
rgbColor = colors.nameToRGB( colorName );

Convert an X11 color name into a CSS rgb(...) value.

Names are stripped of spaces and converted to lowercase. If the name is unknown, null is returned.

This list of color name to RGB mapping is derived from the stock X11 rgb.txt file.

The corresponding CSS rgb(...) value.

(Return to API)

colors   = require('dot-colors');
palette  = colors.stockColorPalette;

The stock color palette. in RGB form.

Array of 256 colors, in this order:

  • The "ANSI 16"
  • The 6x6 color cubes
  • The greyscale ramp

(Return to API)