@e280/stz 0.0.0-33 → 0.0.0-35
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 +6 -6
- package/package.json +2 -2
- package/s/map-g.ts +8 -9
- package/x/map-g.d.ts +2 -2
- package/x/map-g.js +8 -7
- package/x/map-g.js.map +1 -1
package/README.md
CHANGED
|
@@ -23,12 +23,12 @@ const map = new MapG<number, string>([
|
|
|
23
23
|
])
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
- `map.require(key)` —
|
|
26
|
+
- `map.require(key)` — returns the value for key — if missing, throw an error
|
|
27
27
|
```ts
|
|
28
28
|
const value = map.require(1)
|
|
29
29
|
// "hello"
|
|
30
30
|
```
|
|
31
|
-
- `map.guarantee(key, make)` — returns the value for `key
|
|
31
|
+
- `map.guarantee(key, make)` — returns the value for `key` — if missing, run `make` to set the value and return it
|
|
32
32
|
```ts
|
|
33
33
|
const value = map.guarantee(3, () => "rofl")
|
|
34
34
|
// "rofl"
|
|
@@ -121,7 +121,7 @@ import {pub, sub} from "@e280/stz"
|
|
|
121
121
|
|
|
122
122
|
<br/>
|
|
123
123
|
|
|
124
|
-
## 🧰 FN TOOLS
|
|
124
|
+
## 🧰 STZ FN TOOLS
|
|
125
125
|
|
|
126
126
|
### 🍏 `queue(fn)`
|
|
127
127
|
> execute calls in sequence (not concurrent)
|
|
@@ -178,7 +178,7 @@ we use `debounce` a lot in ui code, like on a user's keyboard input in a form fi
|
|
|
178
178
|
import {debounce} from "@e280/stz"
|
|
179
179
|
|
|
180
180
|
const fn = debounce(100, async() => {
|
|
181
|
-
await
|
|
181
|
+
await coolAction()
|
|
182
182
|
})
|
|
183
183
|
|
|
184
184
|
// each fn() call resets the timer
|
|
@@ -186,7 +186,7 @@ fn()
|
|
|
186
186
|
fn()
|
|
187
187
|
fn()
|
|
188
188
|
|
|
189
|
-
//
|
|
189
|
+
// coolAction is only called once here, other calls are redundant
|
|
190
190
|
```
|
|
191
191
|
|
|
192
192
|
### 🍏 `repeat(fn)`
|
|
@@ -211,7 +211,7 @@ stop()
|
|
|
211
211
|
|
|
212
212
|
<br/>
|
|
213
213
|
|
|
214
|
-
## 🧰 DATA UTILITIES
|
|
214
|
+
## 🧰 STZ DATA UTILITIES
|
|
215
215
|
|
|
216
216
|
### 🍏 Hex
|
|
217
217
|
> convert to/from hexadecimal string format
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e280/stz",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-35",
|
|
4
4
|
"description": "everyday ts fns for everything",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Chase Moskal <chasemoskal@gmail.com>",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"_tscw": "tsc -w"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@e280/science": "^0.0.
|
|
29
|
+
"@e280/science": "^0.0.6",
|
|
30
30
|
"@types/node": "^24.2.0",
|
|
31
31
|
"npm-run-all": "^4.1.5",
|
|
32
32
|
"typescript": "^5.9.2"
|
package/s/map-g.ts
CHANGED
|
@@ -2,21 +2,20 @@
|
|
|
2
2
|
/** extended js map with handy methods like `require` and `guarantee` */
|
|
3
3
|
export class MapG<K, V> extends Map<K, V> {
|
|
4
4
|
static require<K, V>(map: Map<K, V>, key: K) {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
if (map.has(key))
|
|
6
|
+
return map.get(key)!
|
|
7
|
+
else
|
|
7
8
|
throw new Error(`required key not found: "${key}"`)
|
|
8
|
-
return value as V
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
static guarantee<K, V>(map: Map<K, V>, key: K, make: () => V) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
value = make()
|
|
12
|
+
if (map.has(key))
|
|
13
|
+
return map.get(key)!
|
|
14
|
+
else {
|
|
15
|
+
const value = make()
|
|
16
16
|
map.set(key, value)
|
|
17
|
+
return value
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
return value
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
array() {
|
package/x/map-g.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** extended js map with handy methods like `require` and `guarantee` */
|
|
2
2
|
export declare class MapG<K, V> extends Map<K, V> {
|
|
3
|
-
static require<K, V>(map: Map<K, V>, key: K): V
|
|
3
|
+
static require<K, V>(map: Map<K, V>, key: K): NonNullable<V>;
|
|
4
4
|
static guarantee<K, V>(map: Map<K, V>, key: K, make: () => V): V;
|
|
5
5
|
array(): [K, V][];
|
|
6
|
-
require(key: K): V
|
|
6
|
+
require(key: K): NonNullable<V>;
|
|
7
7
|
guarantee(key: K, make: () => V): V;
|
|
8
8
|
}
|
|
9
9
|
export type Identifiable<Id = any> = {
|
package/x/map-g.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
/** extended js map with handy methods like `require` and `guarantee` */
|
|
2
2
|
export class MapG extends Map {
|
|
3
3
|
static require(map, key) {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
if (map.has(key))
|
|
5
|
+
return map.get(key);
|
|
6
|
+
else
|
|
6
7
|
throw new Error(`required key not found: "${key}"`);
|
|
7
|
-
return value;
|
|
8
8
|
}
|
|
9
9
|
static guarantee(map, key, make) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
if (map.has(key))
|
|
11
|
+
return map.get(key);
|
|
12
|
+
else {
|
|
13
|
+
const value = make();
|
|
13
14
|
map.set(key, value);
|
|
15
|
+
return value;
|
|
14
16
|
}
|
|
15
|
-
return value;
|
|
16
17
|
}
|
|
17
18
|
array() {
|
|
18
19
|
return [...this];
|
package/x/map-g.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-g.js","sourceRoot":"","sources":["../s/map-g.ts"],"names":[],"mappings":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