dtao / nearest-color

Find the nearest color
danieltao.com/nearest-color
MIT License
346 stars 31 forks source link

makes it possible to return every color only once #7

Closed meodai closed 6 years ago

meodai commented 7 years ago

I had some time this weekend to read and understand your code. I figured I make a proposal for #3. Made me think that we could do caching in the same fashion. Meaning when the stringified needle is already in a "needleCache" object.

meodai commented 7 years ago

PS: Autodoc is pretty cool

meodai commented 7 years ago

demo.js =>

const nc = require('.');

let n = nc.from({
  aqua: '#0ff',
  black: '#000',
  blue: '#00f',
  fuchsia: '#f0f',
  gray: '#808080',
  green: '#008000',
  lime: '#0f0',
  maroon: '#800000',
  navy: '#000080',
  olive: '#808000',
  orange: '#ffa500',
  purple: '#800080',
  red: '#f00',
  silver: '#c0c0c0',
  teal: '#008080',
  white: '#fff',
  yellow: '#ff0'
}, true);

console.log(
n('#f00'), // => red
 n('#f00') // => teal
)
meodai commented 7 years ago

@dtao any thoughts on this? I kinda need this feature.

meodai commented 6 years ago

@dtao ok I needed this so I implemented it myself: https://github.com/meodai/ClosestVector