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