@cgtk/std 0.0.198 → 0.0.199
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/package.json +1 -1
- package/scope.d.ts +0 -1
- package/scope.js +1 -3
- package/string.d.ts +1 -0
- package/string.js +2 -0
- package/treemap.js +5 -9
package/package.json
CHANGED
package/scope.d.ts
CHANGED
|
@@ -14,6 +14,5 @@ export declare const compose: <R extends Structure<Scope<any>>>(rs: R) => Scope<
|
|
|
14
14
|
export declare const of: <T>(x: T, f: Fn<T, Dispose>) => Scope<T>;
|
|
15
15
|
type Use = <T>(r: Scope<T>) => T;
|
|
16
16
|
export declare const gen: <R>(f: FnV<[Use, Fn<Dispose, Dispose>], R>) => Scope<R>;
|
|
17
|
-
export declare const consume: (f: Fn<Use, Dispose | void>) => Dispose;
|
|
18
17
|
export declare const worker: (w: Worker) => Scope<Worker>;
|
|
19
18
|
export {};
|
package/scope.js
CHANGED
|
@@ -29,13 +29,11 @@ export const compose = (rs) => {
|
|
|
29
29
|
}
|
|
30
30
|
return Object.fromEntries(Object.entries(rs).map(([k, v]) => [k, rec(v)]));
|
|
31
31
|
};
|
|
32
|
-
|
|
33
|
-
return scope(value, F.forEach(...disposes));
|
|
32
|
+
return scope(rec(rs), F.forEach(...disposes));
|
|
34
33
|
};
|
|
35
34
|
export const of = (x, f) => scope(x, f(x));
|
|
36
35
|
export const gen = (f) => {
|
|
37
36
|
const res = new Set();
|
|
38
37
|
return scope(f(r => (res.add(r.dispose), r.value), F.bind(add, res)), () => res.forEach(f => f()));
|
|
39
38
|
};
|
|
40
|
-
export const consume = (f) => F.disposable(use => use(f(r => (use(r.dispose), r.value)) ?? F.noop));
|
|
41
39
|
export const worker = (w) => of(w, x => x.terminate.bind(x));
|
package/string.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export declare const decode: (label?: string, opts?: TextDecoderOptions) => (x:
|
|
|
7
7
|
export declare const readLine: (delims?: Set<number>) => (data: Uint8Array, offset?: number) => string;
|
|
8
8
|
export declare const DATA_URL: RegExp;
|
|
9
9
|
export declare const came2kebab: (s: string) => string;
|
|
10
|
+
export declare const join: (sep: string, ...xs: Array<string | undefined>) => string;
|
package/string.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EMPTY } from "./constants.js";
|
|
2
2
|
import { seek } from "./array.js";
|
|
3
|
+
import { isDefined } from "./checks.js";
|
|
3
4
|
export const basename = (path) => path.split("/").at(-1) ?? "";
|
|
4
5
|
export const dirname = (path) => {
|
|
5
6
|
const parts = path.split("/");
|
|
@@ -28,3 +29,4 @@ export const readLine = (delims = new Set([0x0A])) => {
|
|
|
28
29
|
};
|
|
29
30
|
export const DATA_URL = /^data:(?<mime>[\w/\-\+]+)?(;(?<params>[\w\-]+\=[^;,\s]+)*)?(;(?<encoding>base64))?,(?<data>.*)$/;
|
|
30
31
|
export const came2kebab = (s) => s.replace(/[A-Z]/g, m => '-' + m.toLowerCase());
|
|
32
|
+
export const join = (sep, ...xs) => xs.filter(isDefined).join(sep);
|
package/treemap.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { before } from "./fn.js";
|
|
2
2
|
import { isDefined } from "./checks.js";
|
|
3
|
-
import { EMPTY } from "./constants.js";
|
|
4
3
|
export const treemap = () => {
|
|
5
4
|
const nodes = new Set();
|
|
6
5
|
const parents = new Map();
|
|
@@ -10,20 +9,17 @@ export const treemap = () => {
|
|
|
10
9
|
const hasChanged = changed;
|
|
11
10
|
if (hasChanged) {
|
|
12
11
|
children.clear();
|
|
13
|
-
|
|
12
|
+
nodes.forEach(k => {
|
|
14
13
|
const p = parents.get(k);
|
|
15
|
-
if (isDefined(p))
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
children.get(p).push(k);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
14
|
+
if (isDefined(p))
|
|
15
|
+
children.getOrInsert(p, []).push(k);
|
|
16
|
+
});
|
|
21
17
|
changed = false;
|
|
22
18
|
}
|
|
23
19
|
return hasChanged;
|
|
24
20
|
};
|
|
25
21
|
const updated = before(update);
|
|
26
|
-
const getChildren = updated((key) => children.
|
|
22
|
+
const getChildren = updated((key) => children.getOrInsert(key, []));
|
|
27
23
|
const parent = updated((key) => parents.get(key));
|
|
28
24
|
const roots = () => nodes.values().filter(k => !parents.has(k));
|
|
29
25
|
return {
|