Change hex or rgb color to xterm (8-bit) color.
MIT License
Change hex or rgb color to xterm (8-bit) color.
Change hex or rgb color to xterm colors (one of the 256 basic 8-bit colors). Code is based on Python colortrans.py script by Micah Elliott.
This library has only two methods:
#
sign) to the xterm color. If there is no exact match, search for the closest one.Install simply with:
npm install color2xterm
Then in your code:
var c2xterm = require('color2xterm');
c2xterm.hex2xterm('#ffffff'); // result: 15
c2xterm.rgb2xterm(255, 255, 255); // result: 15
// Find closest color:
c2xterm.hex2xterm('#0DADD6'); // closest color is #00AFD7 so the result is 38
stolen from Wikimedia