@e280/stz 0.0.0-34 → 0.0.0-36
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 +2 -2
- package/s/constructor.ts +3 -0
- package/s/index.ts +3 -1
- package/s/map-g.ts +8 -9
- package/s/pipe.ts +7 -8
- package/s/templating.ts +22 -0
- package/x/constructor.d.ts +1 -0
- package/x/constructor.js +2 -0
- package/x/constructor.js.map +1 -0
- package/x/index.d.ts +3 -1
- package/x/index.js +3 -1
- package/x/index.js.map +1 -1
- package/x/map-g.d.ts +2 -2
- package/x/map-g.js +8 -7
- package/x/map-g.js.map +1 -1
- package/x/pipe.d.ts +3 -3
- package/x/pipe.js +5 -5
- package/x/pipe.js.map +1 -1
- package/x/templating.d.ts +6 -0
- package/x/templating.js +11 -0
- package/x/templating.js.map +1 -0
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
# `@e280/stz`
|
|
2
|
+
# 🏂 `@e280/stz`
|
|
3
3
|
|
|
4
4
|
**stz** is e280's standard library of environment-agnostic typescript tools.
|
|
5
5
|
|
|
@@ -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"
|
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-36",
|
|
4
4
|
"description": "everyday ts fns for everything",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Chase Moskal <chasemoskal@gmail.com>",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@e280/science": "^0.0.6",
|
|
30
|
-
"@types/node": "^24.
|
|
30
|
+
"@types/node": "^24.3.0",
|
|
31
31
|
"npm-run-all": "^4.1.5",
|
|
32
32
|
"typescript": "^5.9.2"
|
|
33
33
|
},
|
package/s/constructor.ts
ADDED
package/s/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from "./queue/queue.js"
|
|
|
17
17
|
|
|
18
18
|
export * from "./coalesce.js"
|
|
19
19
|
export * from "./concurrent.js"
|
|
20
|
+
export * from "./constructor.js"
|
|
20
21
|
export * from "./deadline.js"
|
|
21
22
|
export * from "./dedupe.js"
|
|
22
23
|
export * from "./defer.js"
|
|
@@ -32,8 +33,9 @@ export * from "./nap.js"
|
|
|
32
33
|
export * from "./ob.js"
|
|
33
34
|
export * from "./once.js"
|
|
34
35
|
export * from "./pipe.js"
|
|
35
|
-
export * from "./repeat.js"
|
|
36
36
|
export * from "./pubsub.js"
|
|
37
|
+
export * from "./repeat.js"
|
|
38
|
+
export * from "./templating.js"
|
|
37
39
|
export * from "./time.js"
|
|
38
40
|
export * from "./trash.js"
|
|
39
41
|
|
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/s/pipe.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
|
|
2
|
-
export type
|
|
2
|
+
export type Piper<I, O> = (input: I) => O
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return new this(input)
|
|
8
|
-
}
|
|
4
|
+
export function pipe<I>(input: I) {
|
|
5
|
+
return new Pipe(input)
|
|
6
|
+
}
|
|
9
7
|
|
|
8
|
+
export class Pipe<I> {
|
|
10
9
|
#input: I
|
|
11
10
|
|
|
12
11
|
constructor(input: I) {
|
|
13
12
|
this.#input = input
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
to<O>(
|
|
17
|
-
return new Pipe(
|
|
15
|
+
to<O>(fn: Piper<I, O>) {
|
|
16
|
+
return new Pipe(fn(this.#input))
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
done() {
|
package/s/templating.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
export type TemplateParts = {
|
|
3
|
+
strings: TemplateStringsArray
|
|
4
|
+
values: any[]
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function templateParts(
|
|
8
|
+
strings: TemplateStringsArray,
|
|
9
|
+
...values: any[]
|
|
10
|
+
): TemplateParts {
|
|
11
|
+
|
|
12
|
+
return {strings, values}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function templateString(strings: TemplateStringsArray, ...values: any[]) {
|
|
16
|
+
const lastIndex = strings.length - 1
|
|
17
|
+
return strings
|
|
18
|
+
.slice(0, lastIndex)
|
|
19
|
+
.reduce((a, b, c) => a + b + values[c], "")
|
|
20
|
+
+ strings[lastIndex]
|
|
21
|
+
}
|
|
22
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Constructor<T extends {} = {}> = new (...args: any[]) => T;
|
package/x/constructor.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constructor.js","sourceRoot":"","sources":["../s/constructor.ts"],"names":[],"mappings":""}
|
package/x/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export * from "./deep/deep.js";
|
|
|
12
12
|
export * from "./queue/queue.js";
|
|
13
13
|
export * from "./coalesce.js";
|
|
14
14
|
export * from "./concurrent.js";
|
|
15
|
+
export * from "./constructor.js";
|
|
15
16
|
export * from "./deadline.js";
|
|
16
17
|
export * from "./dedupe.js";
|
|
17
18
|
export * from "./defer.js";
|
|
@@ -27,7 +28,8 @@ export * from "./nap.js";
|
|
|
27
28
|
export * from "./ob.js";
|
|
28
29
|
export * from "./once.js";
|
|
29
30
|
export * from "./pipe.js";
|
|
30
|
-
export * from "./repeat.js";
|
|
31
31
|
export * from "./pubsub.js";
|
|
32
|
+
export * from "./repeat.js";
|
|
33
|
+
export * from "./templating.js";
|
|
32
34
|
export * from "./time.js";
|
|
33
35
|
export * from "./trash.js";
|
package/x/index.js
CHANGED
|
@@ -12,6 +12,7 @@ export * from "./deep/deep.js";
|
|
|
12
12
|
export * from "./queue/queue.js";
|
|
13
13
|
export * from "./coalesce.js";
|
|
14
14
|
export * from "./concurrent.js";
|
|
15
|
+
export * from "./constructor.js";
|
|
15
16
|
export * from "./deadline.js";
|
|
16
17
|
export * from "./dedupe.js";
|
|
17
18
|
export * from "./defer.js";
|
|
@@ -27,8 +28,9 @@ export * from "./nap.js";
|
|
|
27
28
|
export * from "./ob.js";
|
|
28
29
|
export * from "./once.js";
|
|
29
30
|
export * from "./pipe.js";
|
|
30
|
-
export * from "./repeat.js";
|
|
31
31
|
export * from "./pubsub.js";
|
|
32
|
+
export * from "./repeat.js";
|
|
33
|
+
export * from "./templating.js";
|
|
32
34
|
export * from "./time.js";
|
|
33
35
|
export * from "./trash.js";
|
|
34
36
|
//# sourceMappingURL=index.js.map
|
package/x/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../s/index.ts"],"names":[],"mappings":"AACA,cAAc,0BAA0B,CAAA;AACxC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAE7B,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AAEnC,cAAc,gBAAgB,CAAA;AAE9B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../s/index.ts"],"names":[],"mappings":"AACA,cAAc,0BAA0B,CAAA;AACxC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAE7B,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AAEnC,cAAc,gBAAgB,CAAA;AAE9B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA"}
|
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":"AACA,wEAAwE;AACxE,MAAM,OAAO,IAAW,SAAQ,GAAS;IACxC,MAAM,CAAC,OAAO,CAAO,GAAc,EAAE,GAAM;QAC1C,
|
|
1
|
+
{"version":3,"file":"map-g.js","sourceRoot":"","sources":["../s/map-g.ts"],"names":[],"mappings":"AACA,wEAAwE;AACxE,MAAM,OAAO,IAAW,SAAQ,GAAS;IACxC,MAAM,CAAC,OAAO,CAAO,GAAc,EAAE,GAAM;QAC1C,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;YACf,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAE,CAAA;;YAEpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,GAAG,CAAC,CAAA;IACrD,CAAC;IAED,MAAM,CAAC,SAAS,CAAO,GAAc,EAAE,GAAM,EAAE,IAAa;QAC3D,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,KAAK;QACJ,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA;IACjB,CAAC;IAED,OAAO,CAAC,GAAM;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAC/B,CAAC;IAED,SAAS,CAAC,GAAM,EAAE,IAAa;QAC9B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;IACvC,CAAC;CACD;AAID,oDAAoD;AACpD,MAAM,OAAO,KAA8B,SAAQ,IAAgB;IAClE,GAAG,CAAC,KAAQ;QACX,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAC1B,CAAC;IAED,GAAG,CAAC,KAAQ;QACX,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;QACzB,OAAO,KAAK,CAAA;IACb,CAAC;IAED,MAAM,CAAC,KAAQ;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAC7B,CAAC;CACD"}
|
package/x/pipe.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type Piper<I, O> = (input: I) => O;
|
|
2
|
+
export declare function pipe<I>(input: I): Pipe<I>;
|
|
2
3
|
export declare class Pipe<I> {
|
|
3
4
|
#private;
|
|
4
|
-
static with<I>(input: I): Pipe<I>;
|
|
5
5
|
constructor(input: I);
|
|
6
|
-
to<O>(
|
|
6
|
+
to<O>(fn: Piper<I, O>): Pipe<O>;
|
|
7
7
|
done(): I;
|
|
8
8
|
}
|
package/x/pipe.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
export function pipe(input) {
|
|
2
|
+
return new Pipe(input);
|
|
3
|
+
}
|
|
1
4
|
export class Pipe {
|
|
2
|
-
static with(input) {
|
|
3
|
-
return new this(input);
|
|
4
|
-
}
|
|
5
5
|
#input;
|
|
6
6
|
constructor(input) {
|
|
7
7
|
this.#input = input;
|
|
8
8
|
}
|
|
9
|
-
to(
|
|
10
|
-
return new Pipe(
|
|
9
|
+
to(fn) {
|
|
10
|
+
return new Pipe(fn(this.#input));
|
|
11
11
|
}
|
|
12
12
|
done() {
|
|
13
13
|
return this.#input;
|
package/x/pipe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipe.js","sourceRoot":"","sources":["../s/pipe.ts"],"names":[],"mappings":"AAGA,MAAM,
|
|
1
|
+
{"version":3,"file":"pipe.js","sourceRoot":"","sources":["../s/pipe.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,IAAI,CAAI,KAAQ;IAC/B,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAA;AACvB,CAAC;AAED,MAAM,OAAO,IAAI;IAChB,MAAM,CAAG;IAET,YAAY,KAAQ;QACnB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,EAAE,CAAI,EAAe;QACpB,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;IACjC,CAAC;IAED,IAAI;QACH,OAAO,IAAI,CAAC,MAAM,CAAA;IACnB,CAAC;CACD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type TemplateParts = {
|
|
2
|
+
strings: TemplateStringsArray;
|
|
3
|
+
values: any[];
|
|
4
|
+
};
|
|
5
|
+
export declare function templateParts(strings: TemplateStringsArray, ...values: any[]): TemplateParts;
|
|
6
|
+
export declare function templateString(strings: TemplateStringsArray, ...values: any[]): string;
|
package/x/templating.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function templateParts(strings, ...values) {
|
|
2
|
+
return { strings, values };
|
|
3
|
+
}
|
|
4
|
+
export function templateString(strings, ...values) {
|
|
5
|
+
const lastIndex = strings.length - 1;
|
|
6
|
+
return strings
|
|
7
|
+
.slice(0, lastIndex)
|
|
8
|
+
.reduce((a, b, c) => a + b + values[c], "")
|
|
9
|
+
+ strings[lastIndex];
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=templating.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templating.js","sourceRoot":"","sources":["../s/templating.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,aAAa,CAC3B,OAA6B,EAC7B,GAAG,MAAa;IAGjB,OAAO,EAAC,OAAO,EAAE,MAAM,EAAC,CAAA;AACzB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAA6B,EAAE,GAAG,MAAa;IAC7E,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,CAAA;IACpC,OAAO,OAAO;SACZ,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC;SACnB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;UACxC,OAAO,CAAC,SAAS,CAAC,CAAA;AACvB,CAAC"}
|