@e280/stz 0.2.33 → 0.2.34
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/README.md +3 -3
- package/package.json +1 -1
- package/s/g/map.ts +17 -4
- package/s/g/weak-map.ts +17 -4
- package/x/g/map.d.ts +6 -2
- package/x/g/map.js +15 -4
- package/x/g/map.js.map +1 -1
- package/x/g/weak-map.d.ts +6 -2
- package/x/g/weak-map.js +15 -4
- package/x/g/weak-map.js.map +1 -1
package/README.md
CHANGED
|
@@ -186,9 +186,9 @@ import {disposer} from "@e280/stz"
|
|
|
186
186
|
[2, "world"],
|
|
187
187
|
])
|
|
188
188
|
```
|
|
189
|
-
- `map.
|
|
189
|
+
- `map.need(key)` — returns the value for key.. if missing, throw an error
|
|
190
190
|
```ts
|
|
191
|
-
const value = map.
|
|
191
|
+
const value = map.need(1)
|
|
192
192
|
// "hello"
|
|
193
193
|
```
|
|
194
194
|
- `map.guarantee(key, makeFn)` — returns the value for `key`.. if missing, run `makeFn` to set and return the value
|
|
@@ -206,7 +206,7 @@ import {disposer} from "@e280/stz"
|
|
|
206
206
|
#### GWeakMap
|
|
207
207
|
> extended js WeakMap
|
|
208
208
|
- `new GWeakMap<K, V>()`
|
|
209
|
-
- `weakMap.
|
|
209
|
+
- `weakMap.need(key)` — returns value for key.. if missing, throw an error
|
|
210
210
|
- `weakMap.guarantee(key, makeFn)` — returns the value for key.. if missing, run `makeFn` to set and return the value
|
|
211
211
|
|
|
212
212
|
|
package/package.json
CHANGED
package/s/g/map.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
/** extended js map with handy methods like `require` and `guarantee` */
|
|
3
3
|
export class GMap<K, V> extends Map<K, V> {
|
|
4
|
-
static
|
|
4
|
+
static need<K, V>(map: Map<K, V>, key: K) {
|
|
5
5
|
if (map.has(key))
|
|
6
6
|
return map.get(key) as V
|
|
7
7
|
else
|
|
8
|
-
throw new Error(`
|
|
8
|
+
throw new Error(`needed key not found: "${key}"`)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
static guarantee<K, V>(map: Map<K, V>, key: K, make: () => V) {
|
|
@@ -22,13 +22,26 @@ export class GMap<K, V> extends Map<K, V> {
|
|
|
22
22
|
return [...this]
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
return GMap.
|
|
25
|
+
need(key: K) {
|
|
26
|
+
return GMap.need(this, key)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
guarantee(key: K, make: () => V) {
|
|
30
30
|
return GMap.guarantee(this, key, make)
|
|
31
31
|
}
|
|
32
|
+
|
|
33
|
+
/** @deprecated renamed to `need` */
|
|
34
|
+
require(key: K) {
|
|
35
|
+
return GMap.require(this, key)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @deprecated renamed to `need` */
|
|
39
|
+
static require<K, V>(map: Map<K, V>, key: K) {
|
|
40
|
+
if (map.has(key))
|
|
41
|
+
return map.get(key) as V
|
|
42
|
+
else
|
|
43
|
+
throw new Error(`required key not found: "${key}"`)
|
|
44
|
+
}
|
|
32
45
|
}
|
|
33
46
|
|
|
34
47
|
/** @deprecated renamed to `GMap` */
|
package/s/g/weak-map.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
/** extended weak map with handy methods like `require` and `guarantee` */
|
|
3
3
|
export class GWeakMap<K extends WeakKey, V> extends WeakMap<K, V> {
|
|
4
|
-
static
|
|
4
|
+
static need<K extends WeakKey, V>(map: WeakMap<K, V>, key: K) {
|
|
5
5
|
if (map.has(key))
|
|
6
6
|
return map.get(key) as V
|
|
7
7
|
else
|
|
8
|
-
throw new Error(`
|
|
8
|
+
throw new Error(`needed key not found`)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
static guarantee<K extends WeakKey, V>(map: WeakMap<K, V>, key: K, make: () => V) {
|
|
@@ -18,13 +18,26 @@ export class GWeakMap<K extends WeakKey, V> extends WeakMap<K, V> {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
return GWeakMap.
|
|
21
|
+
need(key: K) {
|
|
22
|
+
return GWeakMap.need(this, key)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
guarantee(key: K, make: () => V) {
|
|
26
26
|
return GWeakMap.guarantee(this, key, make)
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
/** @deprecated renamed to `need` */
|
|
30
|
+
require(key: K) {
|
|
31
|
+
return GWeakMap.require(this, key)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @deprecated renamed to `need` */
|
|
35
|
+
static require<K extends WeakKey, V>(map: WeakMap<K, V>, key: K) {
|
|
36
|
+
if (map.has(key))
|
|
37
|
+
return map.get(key) as V
|
|
38
|
+
else
|
|
39
|
+
throw new Error(`required key not found`)
|
|
40
|
+
}
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
/** @deprecated renamed to `GWeakMap` */
|
package/x/g/map.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/** extended js map with handy methods like `require` and `guarantee` */
|
|
2
2
|
export declare class GMap<K, V> extends Map<K, V> {
|
|
3
|
-
static
|
|
3
|
+
static need<K, V>(map: Map<K, V>, key: K): V;
|
|
4
4
|
static guarantee<K, V>(map: Map<K, V>, key: K, make: () => V): V;
|
|
5
5
|
array(): [K, V][];
|
|
6
|
-
|
|
6
|
+
need(key: K): V;
|
|
7
7
|
guarantee(key: K, make: () => V): V;
|
|
8
|
+
/** @deprecated renamed to `need` */
|
|
9
|
+
require(key: K): V;
|
|
10
|
+
/** @deprecated renamed to `need` */
|
|
11
|
+
static require<K, V>(map: Map<K, V>, key: K): V;
|
|
8
12
|
}
|
|
9
13
|
/** @deprecated renamed to `GMap` */
|
|
10
14
|
export declare const MapG: typeof GMap;
|
package/x/g/map.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/** extended js map with handy methods like `require` and `guarantee` */
|
|
2
2
|
export class GMap extends Map {
|
|
3
|
-
static
|
|
3
|
+
static need(map, key) {
|
|
4
4
|
if (map.has(key))
|
|
5
5
|
return map.get(key);
|
|
6
6
|
else
|
|
7
|
-
throw new Error(`
|
|
7
|
+
throw new Error(`needed key not found: "${key}"`);
|
|
8
8
|
}
|
|
9
9
|
static guarantee(map, key, make) {
|
|
10
10
|
if (map.has(key))
|
|
@@ -18,12 +18,23 @@ export class GMap extends Map {
|
|
|
18
18
|
array() {
|
|
19
19
|
return [...this];
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
return GMap.
|
|
21
|
+
need(key) {
|
|
22
|
+
return GMap.need(this, key);
|
|
23
23
|
}
|
|
24
24
|
guarantee(key, make) {
|
|
25
25
|
return GMap.guarantee(this, key, make);
|
|
26
26
|
}
|
|
27
|
+
/** @deprecated renamed to `need` */
|
|
28
|
+
require(key) {
|
|
29
|
+
return GMap.require(this, key);
|
|
30
|
+
}
|
|
31
|
+
/** @deprecated renamed to `need` */
|
|
32
|
+
static require(map, key) {
|
|
33
|
+
if (map.has(key))
|
|
34
|
+
return map.get(key);
|
|
35
|
+
else
|
|
36
|
+
throw new Error(`required key not found: "${key}"`);
|
|
37
|
+
}
|
|
27
38
|
}
|
|
28
39
|
/** @deprecated renamed to `GMap` */
|
|
29
40
|
export const MapG = GMap;
|
package/x/g/map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../s/g/map.ts"],"names":[],"mappings":"AACA,wEAAwE;AACxE,MAAM,OAAO,IAAW,SAAQ,GAAS;IACxC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../s/g/map.ts"],"names":[],"mappings":"AACA,wEAAwE;AACxE,MAAM,OAAO,IAAW,SAAQ,GAAS;IACxC,MAAM,CAAC,IAAI,CAAO,GAAc,EAAE,GAAM;QACvC,IAAI,GAAG,CAA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+1,13 @@
|
|
|
1
1
|
/** extended weak map with handy methods like `require` and `guarantee` */
|
|
2
2
|
export declare class GWeakMap<K extends WeakKey, V> extends WeakMap<K, V> {
|
|
3
|
-
static
|
|
3
|
+
static need<K extends WeakKey, V>(map: WeakMap<K, V>, key: K): V;
|
|
4
4
|
static guarantee<K extends WeakKey, V>(map: WeakMap<K, V>, key: K, make: () => V): V;
|
|
5
|
-
|
|
5
|
+
need(key: K): V;
|
|
6
6
|
guarantee(key: K, make: () => V): V;
|
|
7
|
+
/** @deprecated renamed to `need` */
|
|
8
|
+
require(key: K): V;
|
|
9
|
+
/** @deprecated renamed to `need` */
|
|
10
|
+
static require<K extends WeakKey, V>(map: WeakMap<K, V>, key: K): V;
|
|
7
11
|
}
|
|
8
12
|
/** @deprecated renamed to `GWeakMap` */
|
|
9
13
|
export declare const WeakMapG: typeof GWeakMap;
|
package/x/g/weak-map.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/** extended weak map with handy methods like `require` and `guarantee` */
|
|
2
2
|
export class GWeakMap extends WeakMap {
|
|
3
|
-
static
|
|
3
|
+
static need(map, key) {
|
|
4
4
|
if (map.has(key))
|
|
5
5
|
return map.get(key);
|
|
6
6
|
else
|
|
7
|
-
throw new Error(`
|
|
7
|
+
throw new Error(`needed key not found`);
|
|
8
8
|
}
|
|
9
9
|
static guarantee(map, key, make) {
|
|
10
10
|
if (map.has(key))
|
|
@@ -15,12 +15,23 @@ export class GWeakMap extends WeakMap {
|
|
|
15
15
|
return value;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
return GWeakMap.
|
|
18
|
+
need(key) {
|
|
19
|
+
return GWeakMap.need(this, key);
|
|
20
20
|
}
|
|
21
21
|
guarantee(key, make) {
|
|
22
22
|
return GWeakMap.guarantee(this, key, make);
|
|
23
23
|
}
|
|
24
|
+
/** @deprecated renamed to `need` */
|
|
25
|
+
require(key) {
|
|
26
|
+
return GWeakMap.require(this, key);
|
|
27
|
+
}
|
|
28
|
+
/** @deprecated renamed to `need` */
|
|
29
|
+
static require(map, key) {
|
|
30
|
+
if (map.has(key))
|
|
31
|
+
return map.get(key);
|
|
32
|
+
else
|
|
33
|
+
throw new Error(`required key not found`);
|
|
34
|
+
}
|
|
24
35
|
}
|
|
25
36
|
/** @deprecated renamed to `GWeakMap` */
|
|
26
37
|
export const WeakMapG = GWeakMap;
|
package/x/g/weak-map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"weak-map.js","sourceRoot":"","sources":["../../s/g/weak-map.ts"],"names":[],"mappings":"AACA,0EAA0E;AAC1E,MAAM,OAAO,QAA+B,SAAQ,OAAa;IAChE,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"weak-map.js","sourceRoot":"","sources":["../../s/g/weak-map.ts"],"names":[],"mappings":"AACA,0EAA0E;AAC1E,MAAM,OAAO,QAA+B,SAAQ,OAAa;IAChE,MAAM,CAAC,IAAI,CAAuB,GAAkB,EAAE,GAAM;QAC3D,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;YACf,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAM,CAAA;;YAExB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;IACzC,CAAC;IAED,MAAM,CAAC,SAAS,CAAuB,GAAkB,EAAE,GAAM,EAAE,IAAa;QAC/E,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;YACf,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAE,CAAA;aAChB,CAAC;YACL,MAAM,KAAK,GAAG,IAAI,EAAE,CAAA;YACpB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YACnB,OAAO,KAAK,CAAA;QACb,CAAC;IACF,CAAC;IAED,IAAI,CAAC,GAAM;QACV,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAChC,CAAC;IAED,SAAS,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