1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.AliasedMap = exports.CaseInsensitiveProxyHandler = exports.createCaseInsensitiveObject = void 0;
|
4 | function createCaseInsensitiveObject() {
|
5 | return new Proxy({}, exports.CaseInsensitiveProxyHandler);
|
6 | }
|
7 | exports.createCaseInsensitiveObject = createCaseInsensitiveObject;
|
8 | exports.CaseInsensitiveProxyHandler = {
|
9 | has: (obj, prop) => {
|
10 | return conformPropertyKey(prop) in obj;
|
11 | },
|
12 | get: (obj, prop) => {
|
13 | return obj[conformPropertyKey(prop)];
|
14 | },
|
15 | set: (obj, prop, value) => {
|
16 | obj[conformPropertyKey(prop)] = value;
|
17 | return true;
|
18 | },
|
19 | deleteProperty: (obj, prop) => {
|
20 | return delete obj[conformPropertyKey(prop)];
|
21 | },
|
22 | };
|
23 | const conformPropertyKey = (prop) => typeof prop === 'string' ? prop.toLowerCase() : prop;
|
24 | class AliasedMap extends Map {
|
25 | getAliases() {
|
26 | const aliasmap = new Map();
|
27 |
|
28 | const aliases = [...this.entries()].filter(([, v]) => typeof v === 'string' || typeof v === 'symbol');
|
29 | aliases.forEach(([alias, cmd]) => {
|
30 | const cmdaliases = aliasmap.get(cmd) || [];
|
31 | cmdaliases.push(alias);
|
32 | aliasmap.set(cmd, cmdaliases);
|
33 | });
|
34 | return aliasmap;
|
35 | }
|
36 | resolveAlias(key) {
|
37 | const r = this.get(key);
|
38 | if (typeof r !== 'string' && typeof r !== 'symbol') {
|
39 | return r;
|
40 | }
|
41 | return this.resolveAlias(r);
|
42 | }
|
43 | keysWithoutAliases() {
|
44 | return [...this.entries()]
|
45 | .filter((entry) => typeof entry[1] !== 'string' && typeof entry[1] !== 'symbol')
|
46 | .map(([k, v]) => k);
|
47 | }
|
48 | }
|
49 | exports.AliasedMap = AliasedMap;
|