-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
39 lines (33 loc) · 953 Bytes
/
test.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
37
38
39
//var request = require('request');
var fuse = require('./fuse.js');
var colors = require('./colors.js');
var _ = require('lodash');
function matchColor(speech) {
var match;
var options = {
keys: ['name'],
threshold: 0.4,
includeScore: true
};
var f = new fuse(colors.colors, options);
var result = f.search(speech);
var exactMatches = _.filter(result, function (item) {
return item.score === 0;
});
if (exactMatches.length) {
match = _.filter(exactMatches, function (match) {
return match.item.name.length === speech.length;
})[0].item;
} else if (result.length) {
match = result[0].item;
}
return match;
}
console.log(matchColor('blue').hex);
console.log(matchColor('red'));
console.log(matchColor('orange'));
console.log(matchColor('burnt orange'));
console.log(matchColor('aqua'));
console.log(matchColor('teal'));
console.log(matchColor('light blue'));
console.log(matchColor('white'));