From 872b379248ea1a59bcaef13a1aeb1962c9b470ac Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Tue, 29 Mar 2022 11:44:09 -0600 Subject: [PATCH] lib.unicode: attempt to make less horrible --- src/lib/unicode.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/lib/unicode.js b/src/lib/unicode.js index a20d3c2..eea5d8b 100644 --- a/src/lib/unicode.js +++ b/src/lib/unicode.js @@ -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, };