lib.unicode: attempt to make less horrible

This commit is contained in:
Cynthia Foxwell 2022-03-29 11:44:09 -06:00
parent e6de98c9ad
commit 872b379248

View file

@ -13,26 +13,22 @@ async function cacheList() {
.forEach(([character, description]) => {
if (character != "") mappings[character.toLowerCase()] = description;
});
global.____unicode_data = mappings;
}
let getNamesFromString;
async function getNamesFromString(string) {
if (!global.____unicode_data) await cacheList();
if (!global.____unicode_data) {
cacheList().then(() => {
global.____unicode_data = mappings;
getNamesFromString = function (string) {
const codes = [...string].map((char) => char.codePointAt().toString(16));
const codes = [...string].map((char) => char.codePointAt().toString(16));
return codes.map((code) => [
code.padStart(4, "0"),
global.____unicode_data[code.padStart(4, "0")],
]);
};
});
return codes.map((code) => [
code.padStart(4, "0"),
global.____unicode_data[code.padStart(4, "0")],
]);
}
module.exports = {
data: global.____unicode_data,
cacheList,
getNamesFromString,
};