-
Notifications
You must be signed in to change notification settings - Fork 38
/
index.js
36 lines (32 loc) · 875 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"use strict";
var distance = require('euclidean-distance')
var chroma = require('chroma-js')
var color
var key
// These `require` statements are all explicit
// to keep the browserify build from breaking
var lists = {
basic: require('./lib/colors/basic'),
html: require('./lib/colors/html'),
ntc: require('./lib/colors/ntc'),
pantone: require('./lib/colors/pantone'),
roygbiv: require('./lib/colors/roygbiv'),
x11: require('./lib/colors/x11')
}
var namer = module.exports = function(color) {
color = chroma(color)
var results = {}
for (key in lists) {
results[key] = lists[key]
.map (function(name) {
name.distance = distance(color.lab(), chroma(name.hex).lab())
return name
})
.sort (function(a, b) {
return a.distance - b.distance
})
}
return results
}
namer.chroma = chroma
namer.lists = lists