Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
normalize-unicode.js34 linesDownload Raw Back to esm
1// warning: extremely hot code path.
2// This has been meticulously optimized for use
3// within npm install on large package trees.
4// Do not edit without careful benchmarking.
5const normalizeCache = Object.create(null);
6// Limit the size of this. Very low-sophistication LRU cache
7const MAX = 10000;
8const cache = new Set();
9export const normalizeUnicode = (s) => {
10    if (!cache.has(s)) {
11        // shake out identical accents and ligatures
12        normalizeCache[s] = s
13            .normalize('NFD')
14            .toLocaleLowerCase('en')
15            .toLocaleUpperCase('en');
16    }
17    else {
18        cache.delete(s);
19    }
20    cache.add(s);
21    const ret = normalizeCache[s];
22    let i = cache.size - MAX;
23    // only prune when we're 10% over the max
24    if (i > MAX / 10) {
25        for (const s of cache) {
26            cache.delete(s);
27            delete normalizeCache[s];
28            if (--i <= 0)
29                break;
30        }
31    }
32    return ret;
33};
34//# sourceMappingURL=normalize-unicode.js.map
codekingpro/portable-devtools · Team Ai