-
Notifications
You must be signed in to change notification settings - Fork 7
/
emoji.ts
48 lines (43 loc) · 1.43 KB
/
emoji.ts
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
const apis = {
twemoji: (code: string) =>
"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/" + code.toLowerCase() + ".svg",
openmoji: "https://cdn.jsdelivr.net/npm/@svgmoji/openmoji@2.0.0/svg/",
blobmoji: "https://cdn.jsdelivr.net/npm/@svgmoji/blob@2.0.0/svg/",
noto:
"https://cdn.jsdelivr.net/gh/svgmoji/svgmoji/packages/svgmoji__noto/svg/",
fluent: (code: string) =>
"https://cdn.jsdelivr.net/gh/shuding/fluentui-emoji-unicode/assets/" +
code.toLowerCase() + "_color.svg",
fluentFlat: (code: string) =>
"https://cdn.jsdelivr.net/gh/shuding/fluentui-emoji-unicode/assets/" +
code.toLowerCase() + "_flat.svg",
};
export type EmojiType = keyof typeof apis;
const n = String.fromCharCode(8205), O = /\uFE0F/g;
export function loadEmoji(
code: string,
type?: EmojiType,
): Promise<Response> {
(!type || !apis[type]) && (type = "twemoji");
const A = apis[type];
return fetch(
typeof A == "function" ? A(code) : `${A}${code.toUpperCase()}.svg`,
);
}
export function getIconCode(char: string): string {
return d(char.indexOf(n) < 0 ? char.replace(O, "") : char);
}
function d(j: string) {
const t = [];
let A = 0, k = 0;
for (let E = 0; E < j.length;) {
A = j.charCodeAt(E++),
k
? (t.push((65536 + (k - 55296 << 10) + (A - 56320)).toString(16)),
k = 0)
: 55296 <= A && A <= 56319
? k = A
: t.push(A.toString(16));
}
return t.join("-");
}