0.0.8 • Published 1 year ago

ntc-ts v0.0.8

Weekly downloads
104
License
CC-BY-4.0 License
Repository
github
Last release
1 year ago

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

Original licence

0.0.8

1 year ago

0.0.7

2 years ago

0.0.6

3 years ago

0.0.3

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago