Change hex or rgb color to xterm (8-bit) color.
What?
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.
API
This library has only two methods:
- hex2xterm(hex_color):
convert given hex color (with or without
#
sign) to the xterm color. If there is no exact match, search for the closest one. - rgb2xterm(r, g, b):
convert given rgb color (passed tot he method as 3 separate parameters) to the xterm color. If there is no exact match, search for the closest one.
How to use?
Install simply with:
bash
npm install color2xterm
Then in your code:
```javascript
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
Color table
stolen from Wikimedia