-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (46 loc) · 1.34 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
import fetch from 'node-fetch';
import Fuse from 'fuse.js';
/**
@param an emoji
@returns a promise on the SVG code
*/
export async function fetchSVG(emoji) {
const r = await fetch(`https://raw.githubusercontent.com/hfg-gmuend/openmoji/master/color/svg/${emoji.item.hexcode}.svg`);
return await r.text();
}
/**
@returns a promise on an array containing all the emojis
**/
async function fetchAllEmojis() {
const r = await fetch(`https://raw.githubusercontent.com/hfg-gmuend/openmoji/master/data/openmoji.json`);
return await r.json();
}
/**
@param searchString
@returns a promise on an array containing all the emojis that match the searchString
**/
export async function fetchEmojis(searchString) {
const emojis = await fetchAllEmojis();
const options = {
// isCaseSensitive: false,
// includeScore: false,
// shouldSort: true,
// includeMatches: false,
// findAllMatches: false,
// minMatchCharLength: 1,
// location: 0,
threshold: 0.2,
// distance: 100,
// useExtendedSearch: false,
// ignoreLocation: false,
// ignoreFieldNorm: false,
keys: ["tags"]
};
const fuse = new Fuse(emojis, options);
return fuse.search(searchString);
}
/**
Example:
fetchEmojis("apple").then(json => console.log(json));
fetchEmojis("apple").then(json => fetchSVG(json[0]).then(svgCode => console.log(svgCode)));
**/