@zelgadis87/utils-core 5.5.0-beta.0 → 5.5.0-beta.1
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/.rollup/index.cjs +12 -11
- package/.rollup/index.cjs.map +1 -1
- package/.rollup/index.d.ts +3 -2
- package/.rollup/index.mjs +12 -11
- package/.rollup/index.mjs.map +1 -1
- package/.rollup/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/lazy/LazyDictionary.ts +13 -14
package/.rollup/index.cjs
CHANGED
|
@@ -1694,7 +1694,7 @@ class LazyAsync {
|
|
|
1694
1694
|
*/
|
|
1695
1695
|
class LazyDictionary {
|
|
1696
1696
|
_generator;
|
|
1697
|
-
|
|
1697
|
+
_map = new Map();
|
|
1698
1698
|
constructor(_generator) {
|
|
1699
1699
|
this._generator = _generator;
|
|
1700
1700
|
}
|
|
@@ -1710,13 +1710,14 @@ class LazyDictionary {
|
|
|
1710
1710
|
* The generator is invoked at most once per key.
|
|
1711
1711
|
* @param key - The key to look up or generate.
|
|
1712
1712
|
* @returns The value associated with `key`.
|
|
1713
|
-
*/
|
|
1714
|
-
|
|
1715
|
-
|
|
1713
|
+
*/
|
|
1714
|
+
getOrCreate(key) {
|
|
1715
|
+
if (!this._map.has(key)) {
|
|
1716
|
+
const value = this._generator(key);
|
|
1717
|
+
this._map.set(key, value);
|
|
1718
|
+
return value;
|
|
1716
1719
|
}
|
|
1717
|
-
|
|
1718
|
-
this._dictionary[key] = value;
|
|
1719
|
-
return value;
|
|
1720
|
+
return this._map.get(key);
|
|
1720
1721
|
}
|
|
1721
1722
|
/**
|
|
1722
1723
|
* Returns the cached value for `key`, or throws if the key has not been generated yet.
|
|
@@ -1727,8 +1728,8 @@ class LazyDictionary {
|
|
|
1727
1728
|
* @returns The value associated with `key`.
|
|
1728
1729
|
*/
|
|
1729
1730
|
getOrThrow(key, errorMessage) {
|
|
1730
|
-
if (
|
|
1731
|
-
return this.
|
|
1731
|
+
if (this._map.has(key)) {
|
|
1732
|
+
return this._map.get(key);
|
|
1732
1733
|
}
|
|
1733
1734
|
throw new Error(errorMessage);
|
|
1734
1735
|
}
|
|
@@ -1737,7 +1738,7 @@ class LazyDictionary {
|
|
|
1737
1738
|
* @param key - The key to check.
|
|
1738
1739
|
*/
|
|
1739
1740
|
hasKey(key) {
|
|
1740
|
-
return
|
|
1741
|
+
return this._map.has(key);
|
|
1741
1742
|
}
|
|
1742
1743
|
/**
|
|
1743
1744
|
* Returns all key-value pairs that have been generated so far.
|
|
@@ -1745,7 +1746,7 @@ class LazyDictionary {
|
|
|
1745
1746
|
* @returns An array of `[key, value]` tuples.
|
|
1746
1747
|
*/
|
|
1747
1748
|
getEntries() {
|
|
1748
|
-
return
|
|
1749
|
+
return [...this._map.entries()];
|
|
1749
1750
|
}
|
|
1750
1751
|
}
|
|
1751
1752
|
|