@ubnt/store.core 11.27.0-beta.7 → 11.27.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/lib/_virtual/_virtual_multi-entry.js +6 -0
- package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
- package/lib/_virtual/_virtual_multi-entry.mjs +6 -0
- package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
- package/lib/assets/ai-dslr.jpg +0 -0
- package/lib/assets/ai-dslr2.jpg +0 -0
- package/lib/assets/ai-turret.jpg +0 -0
- package/lib/assets/ai-turret2.jpg +0 -0
- package/lib/assets/bullet2.svg +1 -1
- package/lib/assets/bullet3.svg +1 -1
- package/lib/assets/compact.svg +1 -1
- package/lib/assets/compact2.svg +1 -1
- package/lib/assets/door-hub-mini.jpg +0 -0
- package/lib/assets/door-hub-mini2.jpg +0 -0
- package/lib/assets/express.jpg +0 -0
- package/lib/assets/express2.jpg +0 -0
- package/lib/assets/g2-reader.jpg +0 -0
- package/lib/assets/g2-reader2.jpg +0 -0
- package/lib/assets/g3-reader-flex.jpg +0 -0
- package/lib/assets/g3-reader-flex2.jpg +0 -0
- package/lib/assets/g3-starter-kit-pro.jpg +0 -0
- package/lib/assets/g3-starter-kit-pro2.jpg +0 -0
- package/lib/assets/g3-starter-kit.jpg +0 -0
- package/lib/assets/g3-starter-kit2.jpg +0 -0
- package/lib/assets/g4-instant.jpg +0 -0
- package/lib/assets/g4-instant2.jpg +0 -0
- package/lib/assets/g4-ptz.jpg +0 -0
- package/lib/assets/g4-ptz2.jpg +0 -0
- package/lib/assets/g5-dome-ultra.jpg +0 -0
- package/lib/assets/g5-dome-ultra2.jpg +0 -0
- package/lib/assets/g5-dome.jpg +0 -0
- package/lib/assets/g5-dome2.jpg +0 -0
- package/lib/assets/ptz2.svg +1 -1
- package/lib/assets/ptz3.svg +1 -1
- package/lib/assets/udmProMax.jpg +0 -0
- package/lib/assets/udmProMax2.jpg +0 -0
- package/lib/assets/udmProSpecial.jpg +0 -0
- package/lib/assets/udmProSpecial2.jpg +0 -0
- package/lib/assets/udr2.jpg +0 -0
- package/lib/assets/udr3.jpg +0 -0
- package/lib/assets/udr7.jpg +0 -0
- package/lib/assets/udr72.jpg +0 -0
- package/lib/assets/video-recorders.png +0 -0
- package/lib/constants/modelCompareData/assets/Bullet/ai-dslr.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/Bullet/ai-dslr.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/Bullet/bullet.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/Bullet/bullet.svg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/Compact/g4-instant.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/Compact/g4-instant.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/Consoles/bigCompare/express.jpg.js +5 -5
- package/lib/constants/modelCompareData/assets/Consoles/bigCompare/express.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udmProMax.jpg.js +5 -5
- package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udmProMax.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udmProSpecial.jpg.js +5 -5
- package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udmProSpecial.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udr.jpg.js +5 -5
- package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udr.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udr7.jpg.js +5 -5
- package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udr7.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/Consoles/express.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/Consoles/express.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/Consoles/udmProMax.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/Consoles/udmProMax.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/Consoles/udmProSpecial.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/Consoles/udmProSpecial.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/Consoles/udr.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/Consoles/udr.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/Consoles/udr7.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/Consoles/udr7.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DomeTurret/ai-turret.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DomeTurret/ai-turret.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome-ultra.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome-ultra.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DoorAccess/door-hub-mini.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DoorAccess/door-hub-mini.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-flex.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-flex.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit-pro.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit-pro.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/PTZ/g4-ptz.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/PTZ/g4-ptz.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/compact.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/compact.svg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/bullet.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/bullet.svg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-dslr.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-dslr.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/compact/g4-instant.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/compact/g4-instant.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-turret.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-turret.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome-ultra.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome-ultra.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub-mini.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub-mini.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-flex.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-flex.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit-pro.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit-pro.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/ptz/g4-ptz.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/ptz/g4-ptz.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/compact.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/compact.svg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/ptz.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/ptz.svg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/ptz.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/ptz.svg.mjs +2 -2
- package/lib/constants/modelCompareData/data/CloudGateways.js +9 -9
- package/lib/constants/modelCompareData/data/CloudGateways.mjs +6 -6
- package/lib/constants/modelCompareData/data/DreamMachineConsolev4.js +12 -12
- package/lib/constants/modelCompareData/data/DreamMachineConsolev4.mjs +8 -8
- package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Bullet.js +1 -1
- package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Bullet.mjs +1 -1
- package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Compact.js +1 -1
- package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Compact.mjs +1 -1
- package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Ptz.js +1 -1
- package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Ptz.mjs +1 -1
- package/lib/constants/modelCompareData/data/product-list-groups/bullet.js +1 -1
- package/lib/constants/modelCompareData/data/product-list-groups/bullet.mjs +1 -1
- package/lib/constants/modelCompareData/data/product-list-groups/compact.js +1 -1
- package/lib/constants/modelCompareData/data/product-list-groups/compact.mjs +1 -1
- package/lib/constants/modelCompareData/data/product-list-groups/ptz.js +1 -1
- package/lib/constants/modelCompareData/data/product-list-groups/ptz.mjs +1 -1
- package/lib/constants/modelCompareData/data/products/aiDslr.js +2 -2
- package/lib/constants/modelCompareData/data/products/aiDslr.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/aiTurret.js +2 -2
- package/lib/constants/modelCompareData/data/products/aiTurret.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/doorHubMini.js +2 -2
- package/lib/constants/modelCompareData/data/products/doorHubMini.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/express.js +1 -1
- package/lib/constants/modelCompareData/data/products/express.mjs +1 -1
- package/lib/constants/modelCompareData/data/products/g2Reader.js +2 -2
- package/lib/constants/modelCompareData/data/products/g2Reader.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/g3ReaderFlex.js +2 -2
- package/lib/constants/modelCompareData/data/products/g3ReaderFlex.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/g3StarterKit.js +2 -2
- package/lib/constants/modelCompareData/data/products/g3StarterKit.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/g3StarterKitPro.js +2 -2
- package/lib/constants/modelCompareData/data/products/g3StarterKitPro.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/g4Instant.js +2 -2
- package/lib/constants/modelCompareData/data/products/g4Instant.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/g4Ptz.js +2 -2
- package/lib/constants/modelCompareData/data/products/g4Ptz.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/g5Dome.js +2 -2
- package/lib/constants/modelCompareData/data/products/g5Dome.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/g5DomeUltra.js +2 -2
- package/lib/constants/modelCompareData/data/products/g5DomeUltra.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/udmProMax.js +1 -1
- package/lib/constants/modelCompareData/data/products/udmProMax.mjs +1 -1
- package/lib/constants/modelCompareData/data/products/udmProSpecial.js +1 -1
- package/lib/constants/modelCompareData/data/products/udmProSpecial.mjs +1 -1
- package/lib/constants/modelCompareData/data/products/udr.js +1 -1
- package/lib/constants/modelCompareData/data/products/udr.mjs +1 -1
- package/lib/constants/modelCompareData/data/products/udr7.js +1 -1
- package/lib/constants/modelCompareData/data/products/udr7.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/ar.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/ar.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/ca.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/ca.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/cs.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/cs.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/da.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/da.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/de.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/de.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/el.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/el.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/en.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/en.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/es-ES.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/es-ES.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/es-MX.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/es-MX.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/fr.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/fr.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/it.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/it.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/ja.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/ja.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/ko.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/ko.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/nl.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/nl.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/no.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/no.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/pl.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/pl.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/pt-BR.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/pt-BR.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/pt-PT.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/pt-PT.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/ru.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/ru.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/sv.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/sv.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/tr.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/tr.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/zh-Hans.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/zh-Hans.json.mjs +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/zh-Hant-TW.json.js +1 -1
- package/lib/contexts/MicrositeMenuContext/translations/zh-Hant-TW.json.mjs +1 -1
- package/lib/utils/KeyMap.d.ts +51 -0
- package/lib/utils/KeyMap.js +97 -0
- package/lib/utils/KeyMap.js.map +1 -0
- package/lib/utils/KeyMap.mjs +95 -0
- package/lib/utils/KeyMap.mjs.map +1 -0
- package/lib/utils/KeyMap.test.d.ts +1 -0
- package/lib/utils/array.d.ts +6 -0
- package/lib/utils/array.js +9 -0
- package/lib/utils/array.js.map +1 -1
- package/lib/utils/array.mjs +9 -1
- package/lib/utils/array.mjs.map +1 -1
- package/lib/utils/index.d.ts +3 -0
- package/lib/utils/index.js +6 -0
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/index.mjs +6 -0
- package/lib/utils/index.mjs.map +1 -1
- package/lib/utils/makeMap.d.ts +44 -0
- package/lib/utils/makeMap.js +28 -0
- package/lib/utils/makeMap.js.map +1 -0
- package/lib/utils/makeMap.mjs +25 -0
- package/lib/utils/makeMap.mjs.map +1 -0
- package/lib/utils/makeMap.test.d.ts +1 -0
- package/lib/utils/makeSet.d.ts +14 -0
- package/lib/utils/makeSet.js +8 -0
- package/lib/utils/makeSet.js.map +1 -0
- package/lib/utils/makeSet.mjs +7 -0
- package/lib/utils/makeSet.mjs.map +1 -0
- package/lib/utils/makeSet.test.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var array = require('./array.js');
|
|
4
|
+
"use strict";
|
|
5
|
+
class KeyMap {
|
|
6
|
+
#map;
|
|
7
|
+
#keyParser;
|
|
8
|
+
#keyValidator;
|
|
9
|
+
constructor(parser, entries, validator) {
|
|
10
|
+
this.#keyParser = parser;
|
|
11
|
+
this.#keyValidator = validator || (() => {});
|
|
12
|
+
this.#map = Array.isArray(entries) ? new Map(entries.map(([key, value]) => {
|
|
13
|
+
this.#keyValidator(key);
|
|
14
|
+
return [this.#keyParser(key), value];
|
|
15
|
+
})) : /* @__PURE__ */new Map();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get a value by key with runtime validation
|
|
19
|
+
*/
|
|
20
|
+
get(key) {
|
|
21
|
+
this.#keyValidator(key);
|
|
22
|
+
return this.#map.get(this.#keyParser(key));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Set a value by key with runtime validation
|
|
26
|
+
*/
|
|
27
|
+
set(key, value) {
|
|
28
|
+
this.#keyValidator(key);
|
|
29
|
+
this.#map.set(this.#keyParser(key), value);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check if a key exists with runtime validation
|
|
33
|
+
*/
|
|
34
|
+
has(key) {
|
|
35
|
+
this.#keyValidator(key);
|
|
36
|
+
return this.#map.has(this.#keyParser(key));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get all values
|
|
40
|
+
*/
|
|
41
|
+
values() {
|
|
42
|
+
return this.#map.values();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get all keys (returns stringified keys)
|
|
46
|
+
*/
|
|
47
|
+
keys() {
|
|
48
|
+
return this.#map.keys();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get all entries (returns stringified keys)
|
|
52
|
+
*/
|
|
53
|
+
entries() {
|
|
54
|
+
return this.#map.entries();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get the size of the map
|
|
58
|
+
*/
|
|
59
|
+
get size() {
|
|
60
|
+
return this.#map.size;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Clear all entries
|
|
64
|
+
*/
|
|
65
|
+
clear() {
|
|
66
|
+
this.#map.clear();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Delete an entry by key
|
|
70
|
+
*/
|
|
71
|
+
delete(key) {
|
|
72
|
+
this.#keyValidator(key);
|
|
73
|
+
return this.#map.delete(this.#keyParser(key));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Create a KeyMap for database composite keys with automatic validation
|
|
77
|
+
*/
|
|
78
|
+
static createForCompositeKey(keyFieldObject, entries) {
|
|
79
|
+
const keyFields = array.createArrayFromInterfaceKeys(keyFieldObject);
|
|
80
|
+
const parser = key => {
|
|
81
|
+
return keyFields.map(field => String(key[field])).join("_");
|
|
82
|
+
};
|
|
83
|
+
const validator = key => {
|
|
84
|
+
for (const field of keyFields) {
|
|
85
|
+
if (!(field in key)) {
|
|
86
|
+
throw new Error(`Missing required key field: ${String(field)}`);
|
|
87
|
+
}
|
|
88
|
+
if (key[field] == null) {
|
|
89
|
+
throw new Error(`Key field ${String(field)} cannot be null or undefined`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
return new KeyMap(parser, entries, validator);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.KeyMap = KeyMap;
|
|
97
|
+
//# sourceMappingURL=KeyMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyMap.js","sources":["../../src/utils/KeyMap.ts"],"sourcesContent":["import { createArrayFromInterfaceKeys } from \"./array\";\n\n/**\n * Type-safe key parser that ensures all properties of the key are used\n */\nexport type KeyParser<Key> = (key: Key) => string;\n\n/**\n * Type-safe KeyMap implementation with compile-time validation\n */\nexport class KeyMap<Key, Value> {\n #map: Map<string, Value>;\n #keyParser: KeyParser<Key>;\n #keyValidator: (key: Key) => void;\n\n constructor(\n parser: KeyParser<Key>,\n entries?: readonly (readonly [Key, Value])[] | null | undefined,\n validator?: (key: Key) => void,\n ) {\n this.#keyParser = parser;\n this.#keyValidator = validator || (() => {});\n this.#map = Array.isArray(entries)\n ? new Map(\n entries.map(([key, value]) => {\n this.#keyValidator(key);\n return [this.#keyParser(key), value];\n }),\n )\n : new Map();\n }\n\n /**\n * Get a value by key with runtime validation\n */\n get(key: Key): Value | undefined {\n this.#keyValidator(key);\n return this.#map.get(this.#keyParser(key));\n }\n\n /**\n * Set a value by key with runtime validation\n */\n set(key: Key, value: Value): void {\n this.#keyValidator(key);\n this.#map.set(this.#keyParser(key), value);\n }\n\n /**\n * Check if a key exists with runtime validation\n */\n has(key: Key): boolean {\n this.#keyValidator(key);\n return this.#map.has(this.#keyParser(key));\n }\n\n /**\n * Get all values\n */\n values(): IterableIterator<Value> {\n return this.#map.values();\n }\n\n /**\n * Get all keys (returns stringified keys)\n */\n keys(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n /**\n * Get all entries (returns stringified keys)\n */\n entries(): IterableIterator<[string, Value]> {\n return this.#map.entries();\n }\n\n /**\n * Get the size of the map\n */\n get size(): number {\n return this.#map.size;\n }\n\n /**\n * Clear all entries\n */\n clear(): void {\n this.#map.clear();\n }\n\n /**\n * Delete an entry by key\n */\n delete(key: Key): boolean {\n this.#keyValidator(key);\n return this.#map.delete(this.#keyParser(key));\n }\n\n /**\n * Create a KeyMap for database composite keys with automatic validation\n */\n static createForCompositeKey<\n Key extends Record<string, string | number>,\n Value,\n >(\n keyFieldObject: Record<keyof Key, true>,\n entries?: readonly (readonly [Key, Value])[] | null | undefined,\n ): KeyMap<Key, Value> {\n const keyFields = createArrayFromInterfaceKeys(keyFieldObject);\n\n const parser: KeyParser<Key> = (key) => {\n return keyFields.map((field) => String(key[field])).join(\"_\");\n };\n\n const validator = (key: Key) => {\n for (const field of keyFields) {\n if (!(field in key)) {\n throw new Error(`Missing required key field: ${String(field)}`);\n }\n if (key[field] == null) {\n throw new Error(\n `Key field ${String(field)} cannot be null or undefined`,\n );\n }\n }\n };\n\n return new KeyMap(parser, entries, validator);\n }\n}\n"],"names":["KeyMap","map","keyParser","keyValidator","constructor","parser","entries","validator","Array","isArray","Map","key","value","get","set","has","values","keys","size","clear","delete","createForCompositeKey","keyFieldObject","keyFields","createArrayFromInterfaceKeys","field","String","join","Error"],"mappings":"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"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { createArrayFromInterfaceKeys } from './array.mjs';
|
|
2
|
+
"use strict";
|
|
3
|
+
class KeyMap {
|
|
4
|
+
#map;
|
|
5
|
+
#keyParser;
|
|
6
|
+
#keyValidator;
|
|
7
|
+
constructor(parser, entries, validator) {
|
|
8
|
+
this.#keyParser = parser;
|
|
9
|
+
this.#keyValidator = validator || (() => {});
|
|
10
|
+
this.#map = Array.isArray(entries) ? new Map(entries.map(([key, value]) => {
|
|
11
|
+
this.#keyValidator(key);
|
|
12
|
+
return [this.#keyParser(key), value];
|
|
13
|
+
})) : /* @__PURE__ */new Map();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get a value by key with runtime validation
|
|
17
|
+
*/
|
|
18
|
+
get(key) {
|
|
19
|
+
this.#keyValidator(key);
|
|
20
|
+
return this.#map.get(this.#keyParser(key));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Set a value by key with runtime validation
|
|
24
|
+
*/
|
|
25
|
+
set(key, value) {
|
|
26
|
+
this.#keyValidator(key);
|
|
27
|
+
this.#map.set(this.#keyParser(key), value);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Check if a key exists with runtime validation
|
|
31
|
+
*/
|
|
32
|
+
has(key) {
|
|
33
|
+
this.#keyValidator(key);
|
|
34
|
+
return this.#map.has(this.#keyParser(key));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get all values
|
|
38
|
+
*/
|
|
39
|
+
values() {
|
|
40
|
+
return this.#map.values();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get all keys (returns stringified keys)
|
|
44
|
+
*/
|
|
45
|
+
keys() {
|
|
46
|
+
return this.#map.keys();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get all entries (returns stringified keys)
|
|
50
|
+
*/
|
|
51
|
+
entries() {
|
|
52
|
+
return this.#map.entries();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get the size of the map
|
|
56
|
+
*/
|
|
57
|
+
get size() {
|
|
58
|
+
return this.#map.size;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Clear all entries
|
|
62
|
+
*/
|
|
63
|
+
clear() {
|
|
64
|
+
this.#map.clear();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Delete an entry by key
|
|
68
|
+
*/
|
|
69
|
+
delete(key) {
|
|
70
|
+
this.#keyValidator(key);
|
|
71
|
+
return this.#map.delete(this.#keyParser(key));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Create a KeyMap for database composite keys with automatic validation
|
|
75
|
+
*/
|
|
76
|
+
static createForCompositeKey(keyFieldObject, entries) {
|
|
77
|
+
const keyFields = createArrayFromInterfaceKeys(keyFieldObject);
|
|
78
|
+
const parser = key => {
|
|
79
|
+
return keyFields.map(field => String(key[field])).join("_");
|
|
80
|
+
};
|
|
81
|
+
const validator = key => {
|
|
82
|
+
for (const field of keyFields) {
|
|
83
|
+
if (!(field in key)) {
|
|
84
|
+
throw new Error(`Missing required key field: ${String(field)}`);
|
|
85
|
+
}
|
|
86
|
+
if (key[field] == null) {
|
|
87
|
+
throw new Error(`Key field ${String(field)} cannot be null or undefined`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return new KeyMap(parser, entries, validator);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export { KeyMap };
|
|
95
|
+
//# sourceMappingURL=KeyMap.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyMap.mjs","sources":["../../src/utils/KeyMap.ts"],"sourcesContent":["import { createArrayFromInterfaceKeys } from \"./array\";\n\n/**\n * Type-safe key parser that ensures all properties of the key are used\n */\nexport type KeyParser<Key> = (key: Key) => string;\n\n/**\n * Type-safe KeyMap implementation with compile-time validation\n */\nexport class KeyMap<Key, Value> {\n #map: Map<string, Value>;\n #keyParser: KeyParser<Key>;\n #keyValidator: (key: Key) => void;\n\n constructor(\n parser: KeyParser<Key>,\n entries?: readonly (readonly [Key, Value])[] | null | undefined,\n validator?: (key: Key) => void,\n ) {\n this.#keyParser = parser;\n this.#keyValidator = validator || (() => {});\n this.#map = Array.isArray(entries)\n ? new Map(\n entries.map(([key, value]) => {\n this.#keyValidator(key);\n return [this.#keyParser(key), value];\n }),\n )\n : new Map();\n }\n\n /**\n * Get a value by key with runtime validation\n */\n get(key: Key): Value | undefined {\n this.#keyValidator(key);\n return this.#map.get(this.#keyParser(key));\n }\n\n /**\n * Set a value by key with runtime validation\n */\n set(key: Key, value: Value): void {\n this.#keyValidator(key);\n this.#map.set(this.#keyParser(key), value);\n }\n\n /**\n * Check if a key exists with runtime validation\n */\n has(key: Key): boolean {\n this.#keyValidator(key);\n return this.#map.has(this.#keyParser(key));\n }\n\n /**\n * Get all values\n */\n values(): IterableIterator<Value> {\n return this.#map.values();\n }\n\n /**\n * Get all keys (returns stringified keys)\n */\n keys(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n /**\n * Get all entries (returns stringified keys)\n */\n entries(): IterableIterator<[string, Value]> {\n return this.#map.entries();\n }\n\n /**\n * Get the size of the map\n */\n get size(): number {\n return this.#map.size;\n }\n\n /**\n * Clear all entries\n */\n clear(): void {\n this.#map.clear();\n }\n\n /**\n * Delete an entry by key\n */\n delete(key: Key): boolean {\n this.#keyValidator(key);\n return this.#map.delete(this.#keyParser(key));\n }\n\n /**\n * Create a KeyMap for database composite keys with automatic validation\n */\n static createForCompositeKey<\n Key extends Record<string, string | number>,\n Value,\n >(\n keyFieldObject: Record<keyof Key, true>,\n entries?: readonly (readonly [Key, Value])[] | null | undefined,\n ): KeyMap<Key, Value> {\n const keyFields = createArrayFromInterfaceKeys(keyFieldObject);\n\n const parser: KeyParser<Key> = (key) => {\n return keyFields.map((field) => String(key[field])).join(\"_\");\n };\n\n const validator = (key: Key) => {\n for (const field of keyFields) {\n if (!(field in key)) {\n throw new Error(`Missing required key field: ${String(field)}`);\n }\n if (key[field] == null) {\n throw new Error(\n `Key field ${String(field)} cannot be null or undefined`,\n );\n }\n }\n };\n\n return new KeyMap(parser, entries, validator);\n }\n}\n"],"names":["KeyMap","map","keyParser","keyValidator","constructor","parser","entries","validator","Array","isArray","Map","key","value","get","set","has","values","keys","size","clear","delete","createForCompositeKey","keyFieldObject","keyFields","createArrayFromInterfaceKeys","field","String","join","Error"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/utils/array.d.ts
CHANGED
|
@@ -28,3 +28,9 @@ export declare const arraySafeIndexFind: <T>(array: T[], index: number) => T | u
|
|
|
28
28
|
* Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts
|
|
29
29
|
*/
|
|
30
30
|
export declare const normalizeSortResult: (sortResult: number) => number;
|
|
31
|
+
/**
|
|
32
|
+
* Returns an array of keys from an interface where the value is true
|
|
33
|
+
*
|
|
34
|
+
* @example createArrayFromInterfaceKeys<{a: string, b: number, c: Date}>({ a: true, b: false, c: true }) => ['a', 'c']
|
|
35
|
+
*/
|
|
36
|
+
export declare function createArrayFromInterfaceKeys<T extends object>(keyRecord: Record<keyof T, boolean>): (keyof T)[];
|
package/lib/utils/array.js
CHANGED
|
@@ -24,9 +24,18 @@ const arraySafeIndexFind = (array, index) => {
|
|
|
24
24
|
return array[safeIndex];
|
|
25
25
|
};
|
|
26
26
|
const normalizeSortResult = sortResult => number.clamp(sortResult, -1, 1);
|
|
27
|
+
function createArrayFromInterfaceKeys(keyRecord) {
|
|
28
|
+
return Object.entries(keyRecord).reduce((acc, [key, include]) => {
|
|
29
|
+
if (include) {
|
|
30
|
+
acc.push(key);
|
|
31
|
+
}
|
|
32
|
+
return acc;
|
|
33
|
+
}, []);
|
|
34
|
+
}
|
|
27
35
|
exports.areEqualArrays = areEqualArrays;
|
|
28
36
|
exports.arraySafeIndex = arraySafeIndex;
|
|
29
37
|
exports.arraySafeIndexFind = arraySafeIndexFind;
|
|
38
|
+
exports.createArrayFromInterfaceKeys = createArrayFromInterfaceKeys;
|
|
30
39
|
exports.dedupe = dedupe;
|
|
31
40
|
exports.ensureArray = ensureArray;
|
|
32
41
|
exports.normalizeSortResult = normalizeSortResult;
|
package/lib/utils/array.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.js","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp"],"mappings":";;;;AAMO,SAASA,YAAeC,KAAA,EAAqB;EAClD,OAAOC,MAAMC,OAAA,CAAQF,KAAK,CAAA,GAAIA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOO,MAAMG,MAAA,GAAaC,GAAA,IAAa,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAShD,MAAME,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAA,KAAyB;EACnE,IAAID,CAAA,CAAEE,MAAA,KAAWD,CAAA,CAAEC,MAAA,EAAQ;IACzB,OAAO,KAAA;EACT;EACA,IAAI,CAACF,EAAEG,KAAA,CAAOC,MAAOH,CAAA,CAAEI,QAAA,CAASD,EAAE,CAAC,CAAA,EAAG;IACpC,OAAO,KAAA;EACT;EACA,OAAO,CAACH,CAAA,CAAEE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAA,CAASD,EAAE,CAAC,CAAA,GAAI,KAAA,GAAQ,IAAA;AACpD,CAAA;AAOO,MAAME,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAAA,KAA0B;EACtE,MAAMC,YAAYF,KAAA,CAAML,MAAA;EAExB,OAAA,CAASM,KAAA,GAAQC,YAAaA,SAAA,IAAaA,SAAA;AAC7C,CAAA;AAEO,MAAMC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KAAA,KACkB;EAClB,MAAMG,SAAA,GAAYL,cAAA,CAAeC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,MAAAA,CAAAA,KAAA,CAAMD,UAAA,EAAY,IAAI,CAAC,CAAA
|
|
1
|
+
{"version":3,"file":"array.js","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n\n/**\n * Returns an array of keys from an interface where the value is true\n *\n * @example createArrayFromInterfaceKeys<{a: string, b: number, c: Date}>({ a: true, b: false, c: true }) => ['a', 'c']\n */\nexport function createArrayFromInterfaceKeys<T extends object>(\n keyRecord: Record<keyof T, boolean>,\n) {\n return Object.entries(keyRecord).reduce(\n (acc: (keyof T)[], [key, include]) => {\n if (include) {\n acc.push(key);\n }\n return acc;\n },\n [],\n );\n}\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp","createArrayFromInterfaceKeys","keyRecord","Object","entries","reduce","acc","key","include","push"],"mappings":";;;;AAMO,SAASA,YAAeC,KAAA,EAAqB;EAClD,OAAOC,MAAMC,OAAA,CAAQF,KAAK,CAAA,GAAIA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOO,MAAMG,MAAA,GAAaC,GAAA,IAAa,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAShD,MAAME,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAA,KAAyB;EACnE,IAAID,CAAA,CAAEE,MAAA,KAAWD,CAAA,CAAEC,MAAA,EAAQ;IACzB,OAAO,KAAA;EACT;EACA,IAAI,CAACF,EAAEG,KAAA,CAAOC,MAAOH,CAAA,CAAEI,QAAA,CAASD,EAAE,CAAC,CAAA,EAAG;IACpC,OAAO,KAAA;EACT;EACA,OAAO,CAACH,CAAA,CAAEE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAA,CAASD,EAAE,CAAC,CAAA,GAAI,KAAA,GAAQ,IAAA;AACpD,CAAA;AAOO,MAAME,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAAA,KAA0B;EACtE,MAAMC,YAAYF,KAAA,CAAML,MAAA;EAExB,OAAA,CAASM,KAAA,GAAQC,YAAaA,SAAA,IAAaA,SAAA;AAC7C,CAAA;AAEO,MAAMC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KAAA,KACkB;EAClB,MAAMG,SAAA,GAAYL,cAAA,CAAeC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,MAAAA,CAAAA,KAAA,CAAMD,UAAA,EAAY,IAAI,CAAC,CAAA;AAOlB,SAASE,6BACdC,SAAA,EACA;EACA,OAAOC,MAAA,CAAOC,OAAA,CAAQF,SAAS,CAAA,CAAEG,MAAA,CAC/B,CAACC,GAAA,EAAkB,CAACC,GAAA,EAAKC,OAAO,CAAA,KAAM;IACpC,IAAIA,OAAA,EAAS;MACXF,GAAA,CAAIG,KAAKF,GAAG,CAAA;IACd;IACA,OAAOD,GAAA;EACT,CAAA,EACA,EAAC,CACH;AACF;;;;;;;"}
|
package/lib/utils/array.mjs
CHANGED
|
@@ -22,5 +22,13 @@ const arraySafeIndexFind = (array, index) => {
|
|
|
22
22
|
return array[safeIndex];
|
|
23
23
|
};
|
|
24
24
|
const normalizeSortResult = sortResult => clamp(sortResult, -1, 1);
|
|
25
|
-
|
|
25
|
+
function createArrayFromInterfaceKeys(keyRecord) {
|
|
26
|
+
return Object.entries(keyRecord).reduce((acc, [key, include]) => {
|
|
27
|
+
if (include) {
|
|
28
|
+
acc.push(key);
|
|
29
|
+
}
|
|
30
|
+
return acc;
|
|
31
|
+
}, []);
|
|
32
|
+
}
|
|
33
|
+
export { areEqualArrays, arraySafeIndex, arraySafeIndexFind, createArrayFromInterfaceKeys, dedupe, ensureArray, normalizeSortResult };
|
|
26
34
|
//# sourceMappingURL=array.mjs.map
|
package/lib/utils/array.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.mjs","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp"],"mappings":";;AAMO,SAASA,YAAeC,KAAA,EAAqB;EAClD,OAAOC,MAAMC,OAAA,CAAQF,KAAK,CAAA,GAAIA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOO,MAAMG,MAAA,GAAaC,GAAA,IAAa,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAShD,MAAME,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAA,KAAyB;EACnE,IAAID,CAAA,CAAEE,MAAA,KAAWD,CAAA,CAAEC,MAAA,EAAQ;IACzB,OAAO,KAAA;EACT;EACA,IAAI,CAACF,EAAEG,KAAA,CAAOC,MAAOH,CAAA,CAAEI,QAAA,CAASD,EAAE,CAAC,CAAA,EAAG;IACpC,OAAO,KAAA;EACT;EACA,OAAO,CAACH,CAAA,CAAEE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAA,CAASD,EAAE,CAAC,CAAA,GAAI,KAAA,GAAQ,IAAA;AACpD,CAAA;AAOO,MAAME,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAAA,KAA0B;EACtE,MAAMC,YAAYF,KAAA,CAAML,MAAA;EAExB,OAAA,CAASM,KAAA,GAAQC,YAAaA,SAAA,IAAaA,SAAA;AAC7C,CAAA;AAEO,MAAMC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KAAA,KACkB;EAClB,MAAMG,SAAA,GAAYL,cAAA,CAAeC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,KAAA,CAAMD,UAAA,EAAY,IAAI,CAAC,CAAA;"}
|
|
1
|
+
{"version":3,"file":"array.mjs","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n\n/**\n * Returns an array of keys from an interface where the value is true\n *\n * @example createArrayFromInterfaceKeys<{a: string, b: number, c: Date}>({ a: true, b: false, c: true }) => ['a', 'c']\n */\nexport function createArrayFromInterfaceKeys<T extends object>(\n keyRecord: Record<keyof T, boolean>,\n) {\n return Object.entries(keyRecord).reduce(\n (acc: (keyof T)[], [key, include]) => {\n if (include) {\n acc.push(key);\n }\n return acc;\n },\n [],\n );\n}\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp","createArrayFromInterfaceKeys","keyRecord","Object","entries","reduce","acc","key","include","push"],"mappings":";;AAMO,SAASA,YAAeC,KAAA,EAAqB;EAClD,OAAOC,MAAMC,OAAA,CAAQF,KAAK,CAAA,GAAIA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOO,MAAMG,MAAA,GAAaC,GAAA,IAAa,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAShD,MAAME,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAA,KAAyB;EACnE,IAAID,CAAA,CAAEE,MAAA,KAAWD,CAAA,CAAEC,MAAA,EAAQ;IACzB,OAAO,KAAA;EACT;EACA,IAAI,CAACF,EAAEG,KAAA,CAAOC,MAAOH,CAAA,CAAEI,QAAA,CAASD,EAAE,CAAC,CAAA,EAAG;IACpC,OAAO,KAAA;EACT;EACA,OAAO,CAACH,CAAA,CAAEE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAA,CAASD,EAAE,CAAC,CAAA,GAAI,KAAA,GAAQ,IAAA;AACpD,CAAA;AAOO,MAAME,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAAA,KAA0B;EACtE,MAAMC,YAAYF,KAAA,CAAML,MAAA;EAExB,OAAA,CAASM,KAAA,GAAQC,YAAaA,SAAA,IAAaA,SAAA;AAC7C,CAAA;AAEO,MAAMC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KAAA,KACkB;EAClB,MAAMG,SAAA,GAAYL,cAAA,CAAeC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,KAAA,CAAMD,UAAA,EAAY,IAAI,CAAC,CAAA;AAOlB,SAASE,6BACdC,SAAA,EACA;EACA,OAAOC,MAAA,CAAOC,OAAA,CAAQF,SAAS,CAAA,CAAEG,MAAA,CAC/B,CAACC,GAAA,EAAkB,CAACC,GAAA,EAAKC,OAAO,CAAA,KAAM;IACpC,IAAIA,OAAA,EAAS;MACXF,GAAA,CAAIG,KAAKF,GAAG,CAAA;IACd;IACA,OAAOD,GAAA;EACT,CAAA,EACA,EAAC,CACH;AACF;"}
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -20,3 +20,6 @@ export * as styles from "./styles";
|
|
|
20
20
|
export * as storeId from "./storeId";
|
|
21
21
|
export * as blackFriday from "./blackFriday";
|
|
22
22
|
export * as sales from "./sales";
|
|
23
|
+
export * as keyMap from "./KeyMap";
|
|
24
|
+
export * as makeMap from "./makeMap";
|
|
25
|
+
export * as makeSet from "./makeSet";
|
package/lib/utils/index.js
CHANGED
|
@@ -22,6 +22,9 @@ var styles$1 = require('./styles.js');
|
|
|
22
22
|
var storeId$1 = require('./storeId.js');
|
|
23
23
|
var blackFriday$1 = require('./blackFriday.js');
|
|
24
24
|
var sales$1 = require('./sales.js');
|
|
25
|
+
var KeyMap = require('./KeyMap.js');
|
|
26
|
+
var makeMap$1 = require('./makeMap.js');
|
|
27
|
+
var makeSet$1 = require('./makeSet.js');
|
|
25
28
|
"use strict";
|
|
26
29
|
exports.url = url$1;
|
|
27
30
|
exports.money = index;
|
|
@@ -45,4 +48,7 @@ exports.styles = styles$1;
|
|
|
45
48
|
exports.storeId = storeId$1;
|
|
46
49
|
exports.blackFriday = blackFriday$1;
|
|
47
50
|
exports.sales = sales$1;
|
|
51
|
+
exports.keyMap = KeyMap;
|
|
52
|
+
exports.makeMap = makeMap$1;
|
|
53
|
+
exports.makeSet = makeSet$1;
|
|
48
54
|
//# sourceMappingURL=index.js.map
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/utils/index.mjs
CHANGED
|
@@ -42,5 +42,11 @@ import * as blackFriday$1 from './blackFriday.mjs';
|
|
|
42
42
|
export { blackFriday$1 as blackFriday };
|
|
43
43
|
import * as sales$1 from './sales.mjs';
|
|
44
44
|
export { sales$1 as sales };
|
|
45
|
+
import * as KeyMap from './KeyMap.mjs';
|
|
46
|
+
export { KeyMap as keyMap };
|
|
47
|
+
import * as makeMap$1 from './makeMap.mjs';
|
|
48
|
+
export { makeMap$1 as makeMap };
|
|
49
|
+
import * as makeSet$1 from './makeSet.mjs';
|
|
50
|
+
export { makeSet$1 as makeSet };
|
|
45
51
|
"use strict";
|
|
46
52
|
//# sourceMappingURL=index.mjs.map
|
package/lib/utils/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a Map from a plain object.
|
|
3
|
+
*
|
|
4
|
+
* @url https://www.builder.io/blog/maps
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```
|
|
8
|
+
* const map = makeMap({a: 1, b: 2, c: 3})
|
|
9
|
+
* expect(map).toBe(new Map([["a", 1], ["b", 2], ["c", 3]]))
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const makeMap: <V = unknown>(obj: Record<string, V>) => Map<string, V>;
|
|
13
|
+
/**
|
|
14
|
+
* Converts an array of objects to a Map of arrays, using a specified key from each
|
|
15
|
+
* object as the Map key. Multiple objects with the same key value will be grouped together.
|
|
16
|
+
*
|
|
17
|
+
* @param array - The array of objects to convert
|
|
18
|
+
* @param keyField - The field name to use as the Map key (must be a key of T)
|
|
19
|
+
* @returns A Map where keys are the values of the specified field and values
|
|
20
|
+
* are arrays of the original objects that share that key
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```
|
|
24
|
+
* const map = makeMapCollectionBy([{key: "a", val: 1}, {key: "a", val: 2}, {key: "c", val: 3}], "key")
|
|
25
|
+
* expect(map).toBe(new Map([["a", [{key: "a", val: 1}, {key: "a", val: 2}]], ["c", [{key: "c", val: 3}]]]))
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function makeMapCollectionBy<T, K extends keyof T>(array: T[], keyField: K): Map<T[K], T[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Converts an array of objects to a Map, using a specified key from each
|
|
31
|
+
* object as the Map key.
|
|
32
|
+
*
|
|
33
|
+
* @param array - The array of objects to convert
|
|
34
|
+
* @param keyField - The field name to use as the Map key (must be a key of T)
|
|
35
|
+
* @returns A Map where keys are the values of the specified field and values
|
|
36
|
+
* are the original objects
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```
|
|
40
|
+
* const map = makeMapBy([{key: "a", val: 1}, {key: "b", val: 2}, {key: "c", val: 3}], "key")
|
|
41
|
+
* expect(map).toBe(new Map([["a", {key: "a", val: 1}], ["b", {key: "b", val: 2}], ["c", {key: "c", val: 3}]]))
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function makeMapBy<T, K extends keyof T>(array: T[], keyField: K): Map<T[K], T>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const makeMap = obj => new Map(Object.entries(obj));
|
|
5
|
+
function makeMapCollectionBy(array, keyField) {
|
|
6
|
+
const map = /* @__PURE__ */new Map();
|
|
7
|
+
for (const item of array) {
|
|
8
|
+
const key = item[keyField];
|
|
9
|
+
const existing = map.get(key);
|
|
10
|
+
if (existing) {
|
|
11
|
+
existing.push(item);
|
|
12
|
+
} else {
|
|
13
|
+
map.set(key, [item]);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return map;
|
|
17
|
+
}
|
|
18
|
+
function makeMapBy(array, keyField) {
|
|
19
|
+
const map = /* @__PURE__ */new Map();
|
|
20
|
+
for (const item of array) {
|
|
21
|
+
map.set(item[keyField], item);
|
|
22
|
+
}
|
|
23
|
+
return map;
|
|
24
|
+
}
|
|
25
|
+
exports.makeMap = makeMap;
|
|
26
|
+
exports.makeMapBy = makeMapBy;
|
|
27
|
+
exports.makeMapCollectionBy = makeMapCollectionBy;
|
|
28
|
+
//# sourceMappingURL=makeMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeMap.js","sources":["../../src/utils/makeMap.ts"],"sourcesContent":["/**\n * Creates a Map from a plain object.\n *\n * @url https://www.builder.io/blog/maps\n *\n * @example\n * ```\n * const map = makeMap({a: 1, b: 2, c: 3})\n * expect(map).toBe(new Map([[\"a\", 1], [\"b\", 2], [\"c\", 3]]))\n * ```\n */\nexport const makeMap = <V = unknown>(obj: Record<string, V>) =>\n new Map<string, V>(Object.entries(obj));\n\n/**\n * Converts an array of objects to a Map of arrays, using a specified key from each\n * object as the Map key. Multiple objects with the same key value will be grouped together.\n *\n * @param array - The array of objects to convert\n * @param keyField - The field name to use as the Map key (must be a key of T)\n * @returns A Map where keys are the values of the specified field and values\n * are arrays of the original objects that share that key\n *\n * @example\n * ```\n * const map = makeMapCollectionBy([{key: \"a\", val: 1}, {key: \"a\", val: 2}, {key: \"c\", val: 3}], \"key\")\n * expect(map).toBe(new Map([[\"a\", [{key: \"a\", val: 1}, {key: \"a\", val: 2}]], [\"c\", [{key: \"c\", val: 3}]]]))\n * ```\n */\nexport function makeMapCollectionBy<T, K extends keyof T>(\n array: T[],\n keyField: K,\n): Map<T[K], T[]> {\n const map = new Map<T[K], T[]>();\n\n for (const item of array) {\n const key = item[keyField];\n const existing = map.get(key);\n\n if (existing) {\n existing.push(item);\n } else {\n map.set(key, [item]);\n }\n }\n\n return map;\n}\n\n/**\n * Converts an array of objects to a Map, using a specified key from each\n * object as the Map key.\n *\n * @param array - The array of objects to convert\n * @param keyField - The field name to use as the Map key (must be a key of T)\n * @returns A Map where keys are the values of the specified field and values\n * are the original objects\n *\n * @example\n * ```\n * const map = makeMapBy([{key: \"a\", val: 1}, {key: \"b\", val: 2}, {key: \"c\", val: 3}], \"key\")\n * expect(map).toBe(new Map([[\"a\", {key: \"a\", val: 1}], [\"b\", {key: \"b\", val: 2}], [\"c\", {key: \"c\", val: 3}]]))\n * ```\n */\nexport function makeMapBy<T, K extends keyof T>(\n array: T[],\n keyField: K,\n): Map<T[K], T> {\n const map = new Map<T[K], T>();\n\n for (const item of array) {\n map.set(item[keyField], item);\n }\n\n return map;\n}\n"],"names":["makeMap","obj","Map","Object","entries","makeMapCollectionBy","array","keyField","map","item","key","existing","get","push","set","makeMapBy"],"mappings":";;;AAWO,MAAMA,OAAA,GAAwBC,GAAA,IACnC,IAAIC,IAAeC,MAAA,CAAOC,OAAA,CAAQH,GAAG,CAAC,CAAA;AAiBjC,SAASI,mBAAAA,CACdC,OACAC,QAAA,EACgB;EAChB,MAAMC,GAAA,GAAA,mBAAUN,GAAA,CAAA,CAAe;EAE/B,KAAA,MAAWO,QAAQH,KAAA,EAAO;IACxB,MAAMI,GAAA,GAAMD,KAAKF,QAAQ,CAAA;IACzB,MAAMI,QAAA,GAAWH,GAAA,CAAII,GAAA,CAAIF,GAAG,CAAA;IAE5B,IAAIC,QAAA,EAAU;MACZA,QAAA,CAASE,KAAKJ,IAAI,CAAA;IACpB,CAAA,MAAO;MACLD,GAAA,CAAIM,GAAA,CAAIJ,GAAA,EAAK,CAACD,IAAI,CAAC,CAAA;IACrB;EACF;EAEA,OAAOD,GAAA;AACT;AAiBO,SAASO,SAAAA,CACdT,OACAC,QAAA,EACc;EACd,MAAMC,GAAA,GAAA,mBAAUN,GAAA,CAAA,CAAa;EAE7B,KAAA,MAAWO,QAAQH,KAAA,EAAO;IACxBE,GAAA,CAAIM,GAAA,CAAIL,IAAA,CAAKF,QAAQ,CAAA,EAAGE,IAAI,CAAA;EAC9B;EAEA,OAAOD,GAAA;AACT;;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const makeMap = obj => new Map(Object.entries(obj));
|
|
4
|
+
function makeMapCollectionBy(array, keyField) {
|
|
5
|
+
const map = /* @__PURE__ */new Map();
|
|
6
|
+
for (const item of array) {
|
|
7
|
+
const key = item[keyField];
|
|
8
|
+
const existing = map.get(key);
|
|
9
|
+
if (existing) {
|
|
10
|
+
existing.push(item);
|
|
11
|
+
} else {
|
|
12
|
+
map.set(key, [item]);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return map;
|
|
16
|
+
}
|
|
17
|
+
function makeMapBy(array, keyField) {
|
|
18
|
+
const map = /* @__PURE__ */new Map();
|
|
19
|
+
for (const item of array) {
|
|
20
|
+
map.set(item[keyField], item);
|
|
21
|
+
}
|
|
22
|
+
return map;
|
|
23
|
+
}
|
|
24
|
+
export { makeMap, makeMapBy, makeMapCollectionBy };
|
|
25
|
+
//# sourceMappingURL=makeMap.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeMap.mjs","sources":["../../src/utils/makeMap.ts"],"sourcesContent":["/**\n * Creates a Map from a plain object.\n *\n * @url https://www.builder.io/blog/maps\n *\n * @example\n * ```\n * const map = makeMap({a: 1, b: 2, c: 3})\n * expect(map).toBe(new Map([[\"a\", 1], [\"b\", 2], [\"c\", 3]]))\n * ```\n */\nexport const makeMap = <V = unknown>(obj: Record<string, V>) =>\n new Map<string, V>(Object.entries(obj));\n\n/**\n * Converts an array of objects to a Map of arrays, using a specified key from each\n * object as the Map key. Multiple objects with the same key value will be grouped together.\n *\n * @param array - The array of objects to convert\n * @param keyField - The field name to use as the Map key (must be a key of T)\n * @returns A Map where keys are the values of the specified field and values\n * are arrays of the original objects that share that key\n *\n * @example\n * ```\n * const map = makeMapCollectionBy([{key: \"a\", val: 1}, {key: \"a\", val: 2}, {key: \"c\", val: 3}], \"key\")\n * expect(map).toBe(new Map([[\"a\", [{key: \"a\", val: 1}, {key: \"a\", val: 2}]], [\"c\", [{key: \"c\", val: 3}]]]))\n * ```\n */\nexport function makeMapCollectionBy<T, K extends keyof T>(\n array: T[],\n keyField: K,\n): Map<T[K], T[]> {\n const map = new Map<T[K], T[]>();\n\n for (const item of array) {\n const key = item[keyField];\n const existing = map.get(key);\n\n if (existing) {\n existing.push(item);\n } else {\n map.set(key, [item]);\n }\n }\n\n return map;\n}\n\n/**\n * Converts an array of objects to a Map, using a specified key from each\n * object as the Map key.\n *\n * @param array - The array of objects to convert\n * @param keyField - The field name to use as the Map key (must be a key of T)\n * @returns A Map where keys are the values of the specified field and values\n * are the original objects\n *\n * @example\n * ```\n * const map = makeMapBy([{key: \"a\", val: 1}, {key: \"b\", val: 2}, {key: \"c\", val: 3}], \"key\")\n * expect(map).toBe(new Map([[\"a\", {key: \"a\", val: 1}], [\"b\", {key: \"b\", val: 2}], [\"c\", {key: \"c\", val: 3}]]))\n * ```\n */\nexport function makeMapBy<T, K extends keyof T>(\n array: T[],\n keyField: K,\n): Map<T[K], T> {\n const map = new Map<T[K], T>();\n\n for (const item of array) {\n map.set(item[keyField], item);\n }\n\n return map;\n}\n"],"names":["makeMap","obj","Map","Object","entries","makeMapCollectionBy","array","keyField","map","item","key","existing","get","push","set","makeMapBy"],"mappings":";;AAWO,MAAMA,OAAA,GAAwBC,GAAA,IACnC,IAAIC,IAAeC,MAAA,CAAOC,OAAA,CAAQH,GAAG,CAAC,CAAA;AAiBjC,SAASI,mBAAAA,CACdC,OACAC,QAAA,EACgB;EAChB,MAAMC,GAAA,GAAA,mBAAUN,GAAA,CAAA,CAAe;EAE/B,KAAA,MAAWO,QAAQH,KAAA,EAAO;IACxB,MAAMI,GAAA,GAAMD,KAAKF,QAAQ,CAAA;IACzB,MAAMI,QAAA,GAAWH,GAAA,CAAII,GAAA,CAAIF,GAAG,CAAA;IAE5B,IAAIC,QAAA,EAAU;MACZA,QAAA,CAASE,KAAKJ,IAAI,CAAA;IACpB,CAAA,MAAO;MACLD,GAAA,CAAIM,GAAA,CAAIJ,GAAA,EAAK,CAACD,IAAI,CAAC,CAAA;IACrB;EACF;EAEA,OAAOD,GAAA;AACT;AAiBO,SAASO,SAAAA,CACdT,OACAC,QAAA,EACc;EACd,MAAMC,GAAA,GAAA,mBAAUN,GAAA,CAAA,CAAa;EAE7B,KAAA,MAAWO,QAAQH,KAAA,EAAO;IACxBE,GAAA,CAAIM,GAAA,CAAIL,IAAA,CAAKF,QAAQ,CAAA,EAAGE,IAAI,CAAA;EAC9B;EAEA,OAAOD,GAAA;AACT;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a Set containing unique values extracted from a specified field of objects in an array.
|
|
3
|
+
*
|
|
4
|
+
* @param array - The array of objects to extract values from
|
|
5
|
+
* @param keyField - The field name to extract values from (must be a key of T)
|
|
6
|
+
* @returns A Set containing unique values from the specified field
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```
|
|
10
|
+
* const set = makeSetOf([{key: "a", val: 1}, {key: "b", val: 2}, {key: "a", val: 3}], "key")
|
|
11
|
+
* expect(set).toBe(new Set(["a", "b"]))
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const makeSetOf: <T, K extends keyof T>(array: T[], keyField: K) => Set<T[K]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeSet.js","sources":["../../src/utils/makeSet.ts"],"sourcesContent":["/**\n * Creates a Set containing unique values extracted from a specified field of objects in an array.\n *\n * @param array - The array of objects to extract values from\n * @param keyField - The field name to extract values from (must be a key of T)\n * @returns A Set containing unique values from the specified field\n *\n * @example\n * ```\n * const set = makeSetOf([{key: \"a\", val: 1}, {key: \"b\", val: 2}, {key: \"a\", val: 3}], \"key\")\n * expect(set).toBe(new Set([\"a\", \"b\"]))\n * ```\n */\nexport const makeSetOf = <T, K extends keyof T>(\n array: T[],\n keyField: K,\n): Set<T[K]> => {\n return new Set(array.map((item) => item[keyField]));\n};\n"],"names":["makeSetOf","array","keyField","Set","map","item"],"mappings":";;;AAaO,MAAMA,SAAA,GAAYA,CACvBC,KAAA,EACAC,QAAA,KACc;EACd,OAAO,IAAIC,IAAIF,KAAA,CAAMG,GAAA,CAAKC,IAAA,IAASA,IAAA,CAAKH,QAAQ,CAAC,CAAC,CAAA;AACpD,CAAA;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeSet.mjs","sources":["../../src/utils/makeSet.ts"],"sourcesContent":["/**\n * Creates a Set containing unique values extracted from a specified field of objects in an array.\n *\n * @param array - The array of objects to extract values from\n * @param keyField - The field name to extract values from (must be a key of T)\n * @returns A Set containing unique values from the specified field\n *\n * @example\n * ```\n * const set = makeSetOf([{key: \"a\", val: 1}, {key: \"b\", val: 2}, {key: \"a\", val: 3}], \"key\")\n * expect(set).toBe(new Set([\"a\", \"b\"]))\n * ```\n */\nexport const makeSetOf = <T, K extends keyof T>(\n array: T[],\n keyField: K,\n): Set<T[K]> => {\n return new Set(array.map((item) => item[keyField]));\n};\n"],"names":["makeSetOf","array","keyField","Set","map","item"],"mappings":";;AAaO,MAAMA,SAAA,GAAYA,CACvBC,KAAA,EACAC,QAAA,KACc;EACd,OAAO,IAAIC,IAAIF,KAAA,CAAMG,GAAA,CAAKC,IAAA,IAASA,IAAA,CAAKH,QAAQ,CAAC,CAAC,CAAA;AACpD,CAAA;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED