JSPM

wColor

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

The module in JavaScript provides convenient means for color conversion

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

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

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