Utility functions for working with CSS/HTML colors.
Installation
yarn add @adeira/css-colors
Usage
Get color keywords
import { cssColorNames } from '@adeira/css-colors';
cssColorNames.get('rebeccapurple');
The imported cssColorNames
is actually a Map
of all CSS keywords.
Is it a color?
import { isColor } from '@adeira/css-colors';
isColor('#663399');
isColor('rebeccapurple');
isColor('rgb(255, 255, 128)');
isColor('hsl(50, 33%, 25)');
Is the color bright or dark?
This function can be used to detect whether the color is bright or dark so you can decide whether you should use white or black text for the color background (for example).
import { isDark, isBright } from '@adeira/css-colors';
isDark([0, 0, 0]);
isBright([0, 0, 0]);
isDark([255, 255, 255]);
isBright([255, 255, 255]);
Normalize colors
import { normalizeColor } from '@adeira/css-colors';
normalizeColor('#639');
normalizeColor('#663399');
normalizeColor('rebeccapurple');
HEX to HEX
import { hex3ToHex6, hex6ToHex3 } from '@adeira/css-colors';
hex3ToHex6('#639');
hex6ToHex3('#663399');