Home

Awesome

color2xterm by @michalbe

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:

How to use?

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

Color table

colors stolen from Wikimedia