lib.unicode: attempt to make less horrible
This commit is contained in:
parent
e6de98c9ad
commit
872b379248
1 changed files with 9 additions and 13 deletions
|
@ -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));
|
||||
|
||||
return codes.map((code) => [
|
||||
code.padStart(4, "0"),
|
||||
global.____unicode_data[code.padStart(4, "0")],
|
||||
]);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
data: global.____unicode_data,
|
||||
cacheList,
|
||||
getNamesFromString,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue