Usage

Installation

npm install --save @thebespokepixel/trucolor

Usage

import {trucolor, palette, chalkish, simple} from 'trucolor'

const simpleColor = trucolor('bright red')
console.log(`${simpleColor.in}simpleColor${simpleColor.out}`)

const simplePalette = simple()
console.log(`${simplePalette.red}simplePalette Red${simplePalette.red.out}`)
console.log(`${simplePalette.blue}simplePalette Blue${simplePalette.blue.out}`)

const myPalette = palette({}, {
  red: '#F00',
  blue: 'lighten 30 blue'
})
console.log(`${myPalette.red}myPalette Red${myPalette.red.out}`)
console.log(`${myPalette.blue}myPalette Blue${myPalette.blue.out}`)

const myChalkishPalette = chalkish(palette({}, {
  red: '#F00',
  blue: 'lighten 30 blue'
}))
console.log(myChalkishPalette.red('myChalkishPalette Red'))
console.log(myChalkishPalette.blue('myChalkishPalette Blue'))

API

Color retreival API. Will return different values if called with a cli or sgr context.

Trucolor

Type: Trucolor

Properties
name (string) : Human readable color name.
in (string) : Opening SGR code
out (string) : Closing SGR code
hex (string) : #RRGGBB Hexadecimal color value (or SGR reset name)
rgb (string) : 'rgb(red, green, blue)' CSS format (or SGR reset name)
toString (function) : Returns a Hex code, SGR in code or CLI arguments with formatting flags, depending on format.
toSwatch (function) : Returns a graphic swatch of the color.

Create an SGR-aware color from a loose text definition.

trucolor(color: string, options: Object) → Trucolor
Parameters
color (string) A color definition.
options (Object = {}) Options.
Returns
Trucolor: A Trucolor instance.

Create a map of trucolor instances from a map of name/color values.

palette(options: Object, palette: Object) → Object
Parameters
options (Object) Options to pass to trucolor creation.
palette (Object) A map of name/color definitions.
Returns
Object: The resultant name/trucolor map.

Create a map of nestable functions, allowing color to be applied a-lá-chalk.

chalkish(palette: Object) → function
Parameters
palette (Object) A map of name/color definitions.
Returns
function: The resultant name/function map.

Create a simple, sharable palette

simple(options: Object) → Object
Parameters
options (Object) Options to pass to trucolor creation.
Returns
Object: The resultant name/trucolor map.
Example
{
  white: '#BBB',
  black: '#111',
  red: '#B00',
  green: '#0B0',
  blue: '#44B',
  cyan: '#0BB',
  yellow: '#BB0',
  magenta: '#B0B',
  brightWhite: '#FFF',
  brightRed: '#F33',
  brightGreen: '#3F3',
  brightBlue: '#44F',
  brightCyan: '#3FF',
  brightYellow: '#FF3',
  brightMagenta: '#F3F',
  dim: 'dim',
  bold: 'bold',
  italic: 'italic',
  invert: 'invert',
  example: '#CC99FF',
  command: '#31A0FF',
  argument: '#7DC3FF',
  option: '#C1BA89',
  operator: '#FFFFFF',
  grey: '#808080',
  title: 'bold #80C480',
  normal: 'normal',
  reset: 'reset'
}