Closed meodai closed 6 years ago
any thoughts on this @zeke ?
Thanks for the @-mention. Probably would have missed this otherwise.
I'm definitely open to changing the interface for this module. I don't really like the current API, which produces an object with results from different color sets. It's needlessly slow and probably not what most people actually want.
I haven't use this module in a while, but thinking out loud I would image redoing the API something like this:
namer(color[, list])
The list
is optional. If you don't specify a list, then the one we think is "best" is used. Maybe that's color-name-list
? I don't know.
const namer = require('color-namer')
const names = namer('#FF0000')
Instead of returning an object with keys like roygbiv
and pantone
, we'd just return an array of colors:
[
{ name: 'red',
hex: '#FF0000',
distance: 0
},{
name: 'orangered',
hex: '#FF4500',
distance: 13.170205025755513
}, ...
The optional list
argument could potentially be a dataset or a nickname:
// dataset
const names = namer('#FF0000', require('color-name-list'))
// nickname
const names = namer('#FF0000', 'roygbiv')
So.. sensible defaults, reduced overall computation, and flexibility to BYOC (bring your own colors).
What do you think?
Alternatively, the list
could be an argument to the require
module:
const namer = require('color-namer')('roygbiv')
@zeke this sounds very elegant to me. Will you work on that? PS: Should we still have color-name-list
be default? Its a pretty big file.
I also think you could have the lists as JSON. No need to module.export = []. Will make it easier to import lists.
Will you work on that?
Maybe? But probably not immediately. Currently traveling and focusing on Electron stuff.
Should we still have color-name-list be default? Its a pretty big file.
Oh wow it is big.
$ ls -alh node_modules/color-name-list/dist | grep json
-rw-r--r-- 1 z staff 587K Sep 11 08:40 colornames.json
Maybe the default should be roygbiv
then?
have the lists as JSON
Works for me.
@zeke OK Il create a new pull request. We should close that one ;)
So by adding color-name-list (~16k entries) that this was way to slow.
Would be awesome to preload a list for example something like require('color-namer').load(require('color-name-list'))
What do you think?
Used https://github.com/dtao/nearest-color until now, makes it blazing fast but visually less accurate. (Does not matter that much with that many entries anyway: https://codepen.io/meodai/pen/mEvZRx?editors=0110) click the brush