-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (54 loc) · 1.38 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const emojilib = require("emojilib");
/**
* Maps the dango emoji item to a Dext item
*
* @param {Object} item
* @return {Object}
*/
const mapItems = item =>
Object.assign(
{},
{
title: "",
subtitle: "",
arg: item.char,
icon: {
type: "text",
letter: item.char,
bgColor: "transparent"
},
text: {
copy: item.char
}
}
);
// Check object from search list for a match
const matchesQuery = (query, emojiObj) =>
emojiObj.name === query || emojiObj.keywords.includes(query);
// Build an easier to handle search list: [{ name: 'pizza', keywords: ['food', ...] }, { ... }]
const buildSearchList = (keys, emojiMap) =>
keys.map(key => ({ name: key, keywords: emojiMap[key].keywords }));
// Returns all found results matching the query
const getMatchingEmojis = (query, orderedKeys, emojiMap) => {
const searchList = buildSearchList(orderedKeys, emojiMap);
return searchList.reduce((acc, val) => {
if (matchesQuery(query, val)) {
return acc.concat(emojiMap[val.name]);
}
return acc;
}, []);
};
module.exports = {
keyword: "emoji",
helper: {
title: "Search for emojis",
icon: {
path: "./icon.png"
}
},
query: q =>
new Promise(resolve => {
const results = getMatchingEmojis(q, emojilib.ordered, emojilib.lib);
resolve({ items: results.map(mapItems) });
})
};