ntc-ts
v0.0.8
Published
"Name That Color" as a typescript library!
Downloads
716
Readme
NTC, but TS
Extracts the work of ntc - "Name That Color" - as a typescript library, with a few more features:
- caches colors already found, instead of looping through the array of available colors.
- extract color sets in different files for tree shaking, so developers can provide their own colors or use a set provided by the library.
Live Demo of ntc
Try Name that Color!
How to use
See the example below:
import { getColorName, initColors, ORIGINAL_COLORS } from "ntc-ts";
// First, init the available colors.
// By default, only the Black color is available
initColors(ORIGINAL_COLORS);
/*
// Returns a formatted color object FORMATTED_COLOR
type FORMATTED_COLOR = {
exactMatch: boolean;
name: string;
rgb: string | null;
};
*/
const color01 = getColorName("#000");
// returns { exactMatch: true, name: 'Black', rgb: '#000000' }
const color01 = getColorName("#9399A7");
// returns { exactMatch: false, name: 'Manatee', rgb: '#9399A7' }
const color03 = getColorName("this is not a color");
// returns { exactMatch: false, name: 'not-a-color', rgb: null }
const color04 = getColorName(undefined);
// returns { exactMatch: false, name: 'not-a-color', rgb: null }
Available color sets
There are 2 available color sets:
ORIGINAL_COLORS
, containing the original set provided by ntc.MINIMAL_COLORS
, containing the original set trimmed down to a few main colors.
Original credits
- Some code from Farbtastic by Steven Wittens was incorporated into the ntc js library.
- The Resene RGB Values List is copyrighted to Resene Paints Ltd, 2001.
- The color names in this list were found via Wikipedia, Crayola, and Color-Name Dictionaries.
Original licence
- The ntc js library is released under the Creative Commons license.