JSPM

wColor

0.3.87
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 329
  • Score
    100M100P100Q90101F
  • License MIT

Collection of routines to operate colors conveniently. Color provides functions to convert color from one color space to another color space, from name to color and from color to the closest name of a color. The module does not introduce any specific storage format of color what is a benefit. Color has a short list of the most common colors. Use the module for formatted colorful output or other sophisticated operations with colors.

Package Exports

  • wColor

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 (wColor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

wColor Build Status

Collection of routines to operate colors conveniently. Color provides functions to convert color from one color space to another color space, from name to color and from color to the closest name of a color. The module does not introduce any specific storage format of color what is a benefit. Color has a short list of the most common colors. Use the module for formatted colorful output or other sophisticated operations with colors.

The module in JavaScript provides convenient means for color conversion. Contains map of predefined colors( ColorMap ) with rgb channels in [ 0,1 ] range and methods to convert colors between different formats and notations.

Installation

npm install wColor

Try out

npm install
node sample/Sample.s

Usage

After installation module becomes a part of wTools package and can be used as its 'color' property:

wTools.color

Colors map is avaible at:

wTools.color.ColorMap

Methods

Example #1
/*Get color by name*/
let _ = wTools;
let rgb = _.color.colorByName( 'red' );
console.log( rgb );
/*
[ 1, 0, 0 ]
*/
Example #2
/*Get color by name directly*/
let _ = wTools;
let rgb = _.color.ColorMap['red'];
console.log( rgb );
/*
[ 1, 0, 0 ]
*/
Example #3
/*Get color by hex value*/
let _ = wTools;
let rgb = _.color.rgbFrom( 'ffffff' )
console.log( rgb );
/*
[ 1, 1, 1 ]
*/
Example #4
/*Get color by bitmask*/
let _ = wTools;
let rgb = _.color.rgbByBitmask( 0x00ff00 )
console.log( rgb );
/*
[ 0, 1, 0 ]
*/
Example #5
/*Find nearest color*/
let _ = wTools;
let name = _.color.colorNameNearest( 'ff0032' );
let rgb = _.color.ColorMap[ name ];
console.log( name, rgb );
/*
  red [ 1, 0, 0 ]
*/
Example #6
/*Convert color to browser compatible rgb notation*/
let _ = wTools;
let rgb = _.color.ColorMap[ 'red' ];
let browser = _.color.colorToRgbHtml( rgb );
console.log( rgb, browser );
/*
  [ 1, 0, 0 ] 'rgb( 255, 0, 0 )'
*/