Info
chroma
Section titled “chroma”Get the chroma (color intensity) of a color, calculated as (max - min) / 255 from RGB channels.
chroma(input: string): numberReturns a value from 0 (no color, grayscale) to 1 (fully saturated).
import { chroma } from 'colorizr';
chroma('#ff0044'); // 1chroma('#808080'); // 0chroma('#bf4060'); // 0.498Playground
1
luminance
Section titled “luminance”Get the WCAG relative luminance of a color. Returns a value from 0 (black) to 1 (white).
luminance(input: string): numberimport { luminance } from 'colorizr';
luminance('#000000'); // 0luminance('#ff0044'); // 0.2168luminance('#ffffff'); // 1Playground
0.2168
Get the CSS named color that matches the input, or return the hex value if no match.
name(input: string): stringimport { name } from 'colorizr';
name('#ff0000'); // 'red'name('#ff0044'); // '#ff0044' (no exact CSS name match)name('#ffa500'); // 'orange'Playground
red
opacity
Section titled “opacity”Get the opacity value of a color.
opacity(input: string): numberimport { opacity } from 'colorizr';
opacity('#ff0044'); // 1opacity('#ff004480'); // 0.5opacity('rgb(255 0 68 / 50%)'); // 0.5Playground
0.5