1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
const EMOJI_DATA_URL = "https://unicode.org/Public/emoji/15.1/emoji-zwj-sequences.txt";
export async function getCompoundEmojis(): Promise<string[]> {
const data = await fetchText(EMOJI_DATA_URL);
let result: string[] = [];
const lines = data.split("\n");
for (const line of lines) {
if (line.startsWith("#") || line.trim() === "") continue;
const parts = line.split(";");
if (parts.length < 2) continue;
const codepoints = parts[0].trim().split(" ");
const emoji = codepoints.map(cp => {
const codePoint = parseInt(cp, 16);
if (isNaN(codePoint)) throw new Error(`Invalid code point: ${cp}`);
return String.fromCodePoint(codePoint);
}).join("");
result.push(emoji);
}
return result;
}
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 14, 2024