2021-03-15 04:23:14 +00:00
|
|
|
const mappings = {};
|
|
|
|
|
|
|
|
async function cacheList() {
|
|
|
|
const data = await fetch(
|
|
|
|
"https://unicode.org/Public/UNIDATA/UnicodeData.txt"
|
|
|
|
).then((res) => res.text());
|
|
|
|
|
|
|
|
data
|
|
|
|
.split("\n")
|
|
|
|
.map((line) => line.split(";").splice(0, 2))
|
|
|
|
.forEach(([character, description]) => {
|
|
|
|
if (character != "") mappings[character.toLowerCase()] = description;
|
|
|
|
});
|
2022-03-29 17:44:09 +00:00
|
|
|
|
|
|
|
global.____unicode_data = mappings;
|
2021-03-15 04:23:14 +00:00
|
|
|
}
|
|
|
|
|
2022-03-29 17:44:09 +00:00
|
|
|
async function getNamesFromString(string) {
|
|
|
|
if (!global.____unicode_data) await cacheList();
|
2021-03-15 04:23:14 +00:00
|
|
|
|
2022-03-29 17:44:09 +00:00
|
|
|
const codes = [...string].map((char) => char.codePointAt().toString(16));
|
2021-03-15 04:23:14 +00:00
|
|
|
|
2022-03-29 17:44:09 +00:00
|
|
|
return codes.map((code) => [
|
|
|
|
code.padStart(4, "0"),
|
|
|
|
global.____unicode_data[code.padStart(4, "0")],
|
|
|
|
]);
|
2021-03-15 04:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
cacheList,
|
|
|
|
getNamesFromString,
|
|
|
|
};
|