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 779 B
'use strict';var s=require('./data/colorSet.js'),hexUtils_js=require('./hex-utils.js'),hslUtils_js=require('./hsl-utils.js'),rgbUtils_js=require('./rgb-utils.js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var s__default=/*#__PURE__*/_interopDefault(s);function g(e,i=s__default.default){const n=i.find(r=>r[3]===e);if(typeof n<"u"){const[r,t,o]=n;return {hex:hexUtils_js.valuesToHex({r,g:t,b:o}),rgb:rgbUtils_js.RGB({r,g:t,b:o}),hsl:hslUtils_js.valuesToHsl({r,g:t,b:o})}}throw new Error(`Error: invalid color ${e} or empty colorSet`)}function E(){return s__default.default.map(e=>{const[i,n,r,t]=e,o={r:i,g:n,b:r};return {name:t,hex:hexUtils_js.valuesToHex(o),rgb:rgbUtils_js.RGB(o),hsl:hslUtils_js.valuesToHsl(o)}})}exports.getColor=g;exports.getColors=E;