UNPKG

color-2-name

Version:

Finds the closest color name to a given hex, rgb and hsl color (with and without alpha). It uses the Euclidean distance formula to calculate the distance between colors in the RGB color space

1 lines 545 B
import s from'./data/colorSet.js';import {valuesToHex}from'./hex-utils.js';import {valuesToHsl}from'./hsl-utils.js';import {RGB}from'./rgb-utils.js';function E(e,i=s){const n=i.find(r=>r[3]===e);if(typeof n<"u"){const[r,t,o]=n;return {hex:valuesToHex({r,g:t,b:o}),rgb:RGB({r,g:t,b:o}),hsl:valuesToHsl({r,g:t,b:o})}}throw new Error(`Error: invalid color ${e} or empty colorSet`)}function d(){return s.map(e=>{const[i,n,r,t]=e,o={r:i,g:n,b:r};return {name:t,hex:valuesToHex(o),rgb:RGB(o),hsl:valuesToHsl(o)}})}export{E as getColor,d as getColors};