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
58
59
60
61
62
63
64
65
66
interface Emoji {
name: string;
codepoints: string[];
qualification: string;
version: string;
group: string;
subgroup: string;
}
export async function emojiData(): Promise<Emoji[]> {
const res = await fetch("https://www.unicode.org/Public/draft/emoji/emoji-test.txt");
const text = await res.text();
const lines = text.split("\n");
const emoji = [];
let currentGroup = null;
let currentSubgroup = null;
for (const line of lines) {
// Parse group
if (line.startsWith("# group:")) {
currentGroup = line.replace("# group:", "").trim();
continue;
}
// Parse subgroup
if (line.startsWith("# subgroup:")) {
currentSubgroup = line.replace("# subgroup:", "").trim();
continue;
}
// Ignore all other comments
if (line.startsWith("#")) {
continue;
}
// Split the line into columns
// The format of which is quite awkward and not \t separated
//
// 1F600 ; fully-qualified # 😀 E1.0 grinning face
// 0023 FE0F 20E3 ; fully-qualified # #️⃣ E0.6 keycap: #
const columns = line.split(/;|(?:#\s)/);
if (columns.length < 3) {
continue;
}
// Extract the codepoints, qualification, version, and name
const codepoints = columns[0].trim();
const qualification = columns[1].trim();
const comment = columns[2].trim();
const [, version, ...nameParts] = comment.split(" ");
emoji.push({
name: nameParts.join(" "),
codepoints: codepoints.split(" "),
qualification,
version: version.slice(1),
group: currentGroup,
subgroup: currentSubgroup,
});
}
return emoji;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
June 15, 2024