@bunt/util
Advanced tools
Comparing version 0.24.9 to 0.24.10
@@ -0,5 +1,6 @@ | ||
export declare type XMapInitializer<K, V> = (key: K) => V; | ||
export declare class XMap<K, V> extends Map<K, V> { | ||
#private; | ||
constructor(initializer?: (key: K) => V); | ||
ensure(key: K, initializer?: (key: K) => V): V; | ||
ensure(key: K, initializer?: XMapInitializer<K, V> | undefined): V; | ||
} |
@@ -17,2 +17,3 @@ "use strict"; | ||
const assert_1 = require("../assert"); | ||
const is_1 = require("../is"); | ||
class XMap extends Map { | ||
@@ -24,7 +25,5 @@ constructor(initializer) { | ||
} | ||
ensure(key, initializer) { | ||
initializer = initializer ?? __classPrivateFieldGet(this, _XMap_initializer, "f"); | ||
const value = this.get(key); | ||
ensure(key, initializer = __classPrivateFieldGet(this, _XMap_initializer, "f")) { | ||
const exists = this.has(key); | ||
if (!exists && initializer) { | ||
if (!exists && (0, is_1.isFunction)(initializer)) { | ||
const value = initializer(key); | ||
@@ -34,4 +33,4 @@ this.set(key, value); | ||
} | ||
(0, assert_1.assert)(!exists, `The key doesn't exists: ${key}`); | ||
return value; | ||
(0, assert_1.assert)(exists, `The key doesn't exists: ${key}`); | ||
return this.get(key); | ||
} | ||
@@ -38,0 +37,0 @@ } |
{ | ||
"name": "@bunt/util", | ||
"version": "0.24.9", | ||
"version": "0.24.10", | ||
"keywords": [ | ||
@@ -29,3 +29,3 @@ "typescript" | ||
"license": "MIT", | ||
"gitHead": "5339d2fa4e496960063b7fa2f5d0e4ce43e421e3" | ||
"gitHead": "c4806b42c01121da77d820a41dc1d4c33e0a3e53" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
146191