@mapbox/to-color

Procedurally generate a deterministic, perceptually distributed color palette.

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
101Feb 5, 2021Jul 30, 2015Minified + gzip package size for @mapbox/to-color in KB

Readme

@mapbox/to-color

Procedurally generate a deterministic, perceptually distributed color palette.

Build Status

install

npm install @mapbox/to-color

Usage

import toColor from '@mapbox/to-color'

const color = new toColor('tmcw');

// Or a number
// const color = new toColor(1234);
// Or with options
// const color = new toColor('tmcw', { brightness: 0.25, saturation: 1.1 });

const { hsl } = color.getColor();

/*
Returns

{
  raw: [314, 97.95, 50.98],
  formatted: 'hsl(314, 97.95%, 50.98%)'
}
*/

const { hsl } = color.getColor();

/*
Returns

{
  raw: [2, 78.26, 54],
  formatted: 'hsl(2, 78.26%, 54%)'
}
*/

Options

Option Value Default Description
brightness Number undefined Adjusts brightness percentage from the derived min/max range.
saturation Number undefined Adjusts saturation percentage from the derived min/max range.

Developing

# Demo site
npm install & npm start

# Run tests
npm run test

Credit v2 is adapted from randomColor.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.