omgovich / colord

👑 A tiny yet powerful tool for high-performance color manipulations and conversions
https://colord.omgovich.ru
MIT License
1.63k stars 48 forks source link

"Nearest color" functionality #117

Open fromaline opened 10 months ago

fromaline commented 10 months ago

First off, great library! Thanks for developing and maintaining it 🙏

I have a feature request: A utility function for finding the nearest color. Similar to what nearest-color does, but with TS support and thorough testing.

// example from nearest-color

var colors = {
  red: '#f00',
  yellow: '#ff0',
  blue: '#00f'
};

var nearestColor = require('nearest-color').from(colors);

nearestColor('#800'); // => { name: 'red', value: '#f00', rgb: { r: 255, g: 0, b: 0 }, distance: 119 }
nearestColor('#ffe'); // => { name: 'yellow', value: '#ff0', rgb: { r: 255, g: 255, b: 0 }, distance: 238 }

Do you think it worth implementing? Or is it's irrelevant for your library?