@cgtk/std 0.0.193 → 0.0.194
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/array.d.ts +1 -1
- package/array.js +1 -1
- package/assign.d.ts +1 -1
- package/assign.js +1 -1
- package/async.d.ts +1 -1
- package/async.js +2 -2
- package/basen.js +1 -1
- package/buffer.d.ts +1 -1
- package/buffer.js +1 -1
- package/checks.d.ts +1 -1
- package/checks.js +2 -2
- package/dom.d.ts +1 -1
- package/dom.js +3 -3
- package/fn.d.ts +1 -1
- package/fn.js +1 -1
- package/http.js +2 -2
- package/iterable.d.ts +1 -1
- package/iterable.js +3 -3
- package/map.d.ts +1 -1
- package/map.js +2 -2
- package/math.js +1 -1
- package/npy.d.ts +1 -1
- package/number.js +1 -1
- package/package.json +2 -2
- package/port.d.ts +1 -1
- package/port.js +4 -4
- package/progress.d.ts +1 -1
- package/rect.d.ts +1 -1
- package/rect.js +1 -1
- package/resource.d.ts +1 -1
- package/resource.js +2 -2
- package/schedule.d.ts +1 -1
- package/schedule.js +2 -2
- package/signal.d.ts +1 -1
- package/signal.js +4 -4
- package/src/array.d.ts +14 -0
- package/src/array.js +21 -0
- package/src/assign.d.ts +8 -0
- package/src/assign.js +26 -0
- package/src/async.d.ts +8 -0
- package/src/async.js +31 -0
- package/src/base64.d.ts +1 -0
- package/src/base64.js +7 -0
- package/src/basen.d.ts +12 -0
- package/src/basen.js +31 -0
- package/src/buffer.d.ts +14 -0
- package/src/buffer.js +54 -0
- package/src/checks.d.ts +29 -0
- package/src/checks.js +44 -0
- package/src/constants.d.ts +5 -0
- package/src/constants.js +1 -0
- package/src/dom.d.ts +50 -0
- package/src/dom.js +36 -0
- package/src/fn.d.ts +33 -0
- package/src/fn.js +61 -0
- package/src/http.d.ts +9 -0
- package/src/http.js +33 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/iterable.d.ts +43 -0
- package/src/iterable.js +158 -0
- package/src/json.d.ts +1 -0
- package/src/json.js +1 -0
- package/src/map.d.ts +12 -0
- package/src/map.js +35 -0
- package/src/math.d.ts +34 -0
- package/src/math.js +43 -0
- package/src/npy.d.ts +10 -0
- package/src/npy.js +29 -0
- package/src/number.d.ts +4 -0
- package/src/number.js +13 -0
- package/src/object.d.ts +15 -0
- package/src/object.js +13 -0
- package/src/port.d.ts +30 -0
- package/src/port.js +56 -0
- package/src/progress.d.ts +6 -0
- package/src/progress.js +1 -0
- package/src/rect.d.ts +5 -0
- package/src/rect.js +16 -0
- package/src/resource.d.ts +12 -0
- package/src/resource.js +28 -0
- package/src/schedule.d.ts +10 -0
- package/src/schedule.js +33 -0
- package/src/set.d.ts +2 -0
- package/src/set.js +2 -0
- package/src/signal.d.ts +37 -0
- package/src/signal.js +89 -0
- package/src/stream.d.ts +6 -0
- package/src/stream.js +26 -0
- package/src/string.d.ts +8 -0
- package/src/string.js +29 -0
- package/src/struct.d.ts +42 -0
- package/src/struct.js +58 -0
- package/src/tree.d.ts +11 -0
- package/src/tree.js +25 -0
- package/src/treemap.d.ts +13 -0
- package/src/treemap.js +71 -0
- package/src/typedarray.d.ts +31 -0
- package/src/typedarray.js +39 -0
- package/src/types.d.ts +63 -0
- package/src/types.js +1 -0
- package/src/utils.d.ts +4 -0
- package/src/utils.js +30 -0
- package/src/weak.d.ts +2 -0
- package/src/weak.js +5 -0
- package/stream.d.ts +1 -1
- package/stream.js +2 -2
- package/string.d.ts +1 -1
- package/string.js +2 -2
- package/struct.d.ts +2 -2
- package/struct.js +2 -2
- package/tree.d.ts +1 -1
- package/tree.js +3 -3
- package/treemap.d.ts +1 -1
- package/treemap.js +3 -3
- package/typedarray.d.ts +1 -1
- package/typedarray.js +3 -3
- package/utils.d.ts +1 -1
- package/utils.js +1 -1
- package/weak.d.ts +1 -1
- package/weak.js +1 -1
package/src/treemap.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { before } from "./fn.js";
|
|
2
|
+
import { isDefined } from "./checks.js";
|
|
3
|
+
import { EMPTY } from "./constants.js";
|
|
4
|
+
export const treemap = () => {
|
|
5
|
+
const nodes = new Set();
|
|
6
|
+
const parents = new Map();
|
|
7
|
+
const children = new Map();
|
|
8
|
+
let changed = false;
|
|
9
|
+
const update = () => {
|
|
10
|
+
const hasChanged = changed;
|
|
11
|
+
if (hasChanged) {
|
|
12
|
+
children.clear();
|
|
13
|
+
for (const k of nodes) {
|
|
14
|
+
const p = parents.get(k);
|
|
15
|
+
if (isDefined(p)) {
|
|
16
|
+
if (!children.has(p))
|
|
17
|
+
children.set(p, []);
|
|
18
|
+
children.get(p).push(k);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
changed = false;
|
|
22
|
+
}
|
|
23
|
+
return hasChanged;
|
|
24
|
+
};
|
|
25
|
+
const updated = before(update);
|
|
26
|
+
const getChildren = updated((key) => children.get(key) ?? EMPTY.LIST);
|
|
27
|
+
const parent = updated((key) => parents.get(key));
|
|
28
|
+
const roots = () => nodes.values().filter(k => !parents.has(k));
|
|
29
|
+
return {
|
|
30
|
+
set(node, parent) {
|
|
31
|
+
nodes.add(node);
|
|
32
|
+
if (isDefined(parent)) {
|
|
33
|
+
nodes.add(parent);
|
|
34
|
+
parents.set(node, parent);
|
|
35
|
+
}
|
|
36
|
+
changed = true;
|
|
37
|
+
return this;
|
|
38
|
+
},
|
|
39
|
+
delete(key) {
|
|
40
|
+
nodes.delete(key);
|
|
41
|
+
parents.delete(key);
|
|
42
|
+
changed = true;
|
|
43
|
+
},
|
|
44
|
+
get size() {
|
|
45
|
+
update();
|
|
46
|
+
return nodes.size;
|
|
47
|
+
},
|
|
48
|
+
parent,
|
|
49
|
+
children: getChildren,
|
|
50
|
+
roots,
|
|
51
|
+
ancestors: updated(function* (node) {
|
|
52
|
+
for (let cur = node; isDefined(cur); cur = parent(cur))
|
|
53
|
+
yield cur;
|
|
54
|
+
}),
|
|
55
|
+
dfs: updated(function* (root) {
|
|
56
|
+
const stack = [root];
|
|
57
|
+
for (let node; stack.length > 0;) {
|
|
58
|
+
yield node = stack.pop();
|
|
59
|
+
const items = getChildren(node);
|
|
60
|
+
for (let i = items.length - 1; i >= 0; i--)
|
|
61
|
+
stack.push(items[i]);
|
|
62
|
+
}
|
|
63
|
+
}),
|
|
64
|
+
bfs: updated(function* (queue = [...roots()]) {
|
|
65
|
+
for (let node; queue.length > 0;) {
|
|
66
|
+
yield node = queue.shift();
|
|
67
|
+
queue.push(...getChildren(node));
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
};
|
|
71
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { FnV, TypedArray, NumberArray, BufferType, Number } from "./types.js";
|
|
2
|
+
export interface Constructor<T extends TypedArray> {
|
|
3
|
+
new (length: number): T;
|
|
4
|
+
new (buffer: BufferType<T> | ArrayBufferLike, byteOffset?: number, length?: number): T;
|
|
5
|
+
readonly BYTES_PER_ELEMENT: number;
|
|
6
|
+
of(...items: Number<T>[]): T;
|
|
7
|
+
from(arrayLike: ArrayLike<Number<T>>): T;
|
|
8
|
+
}
|
|
9
|
+
export type View<T extends TypedArray> = FnV<[BufferType<T>?, number?], T>;
|
|
10
|
+
export declare const view: <T extends TypedArray>(type: Constructor<T>, length: number) => View<T>;
|
|
11
|
+
export declare const u8: (length: number) => View<Uint8Array<ArrayBufferLike>>;
|
|
12
|
+
export declare const u16: (length: number) => View<Uint16Array<ArrayBufferLike>>;
|
|
13
|
+
export declare const u32: (length: number) => View<Uint32Array<ArrayBufferLike>>;
|
|
14
|
+
export declare const u64: (length: number) => View<BigUint64Array<ArrayBufferLike>>;
|
|
15
|
+
export declare const i8: (length: number) => View<Int8Array<ArrayBufferLike>>;
|
|
16
|
+
export declare const i16: (length: number) => View<Int16Array<ArrayBufferLike>>;
|
|
17
|
+
export declare const i32: (length: number) => View<Int32Array<ArrayBufferLike>>;
|
|
18
|
+
export declare const i64: (length: number) => View<BigInt64Array<ArrayBufferLike>>;
|
|
19
|
+
export declare const f16: (length: number) => View<Float16Array<ArrayBufferLike>>;
|
|
20
|
+
export declare const f32: (length: number) => View<Float32Array<ArrayBufferLike>>;
|
|
21
|
+
export declare const f64: (length: number) => View<Float64Array<ArrayBufferLike>>;
|
|
22
|
+
export declare const UintArray: (n: number) => Uint8ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor;
|
|
23
|
+
export declare const ctor: <T extends TypedArray>(x: T) => Constructor<T>;
|
|
24
|
+
export declare const emptyLike: <T extends TypedArray>(x: T) => T;
|
|
25
|
+
export declare const set: <T extends TypedArray>(xs: T, x: ArrayLike<Number<T>> | T, i: number) => T;
|
|
26
|
+
export declare const concat: <T extends TypedArray>(chunks: T[]) => T;
|
|
27
|
+
export declare const iter: (size: number, stride?: number) => <T extends TypedArray>(data: T) => Generator<T>;
|
|
28
|
+
export declare const tile: (n: number) => (out: TypedArray, x: TypedArray) => TypedArray;
|
|
29
|
+
export declare const tileEvery: (m: number, n: number) => <T extends TypedArray>(xs: T, out?: T) => T;
|
|
30
|
+
export declare const strided: <T extends TypedArray>(data: T, size: number, stride?: number, out?: T) => T;
|
|
31
|
+
export declare const toFixed: (n: number, sep?: string) => (xs: NumberArray) => string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { bind } from "./fn.js";
|
|
2
|
+
import { zmap, map as mapI, reduce } from "./iterable.js";
|
|
3
|
+
import { push } from "./array.js";
|
|
4
|
+
export const view = (type, length) => (buf = new ArrayBuffer(type.BYTES_PER_ELEMENT * length), offset = 0) => new type(buf, offset, length);
|
|
5
|
+
export const u8 = bind((view), Uint8Array);
|
|
6
|
+
export const u16 = bind((view), Uint16Array);
|
|
7
|
+
export const u32 = bind((view), Uint32Array);
|
|
8
|
+
export const u64 = bind((view), BigUint64Array);
|
|
9
|
+
export const i8 = bind((view), Int8Array);
|
|
10
|
+
export const i16 = bind((view), Int16Array);
|
|
11
|
+
export const i32 = bind((view), Int32Array);
|
|
12
|
+
export const i64 = bind((view), BigInt64Array);
|
|
13
|
+
export const f16 = bind((view), Float16Array);
|
|
14
|
+
export const f32 = bind((view), Float32Array);
|
|
15
|
+
export const f64 = bind((view), Float64Array);
|
|
16
|
+
export const UintArray = (n) => n < 256 ? Uint8Array : n < 65536 ? Uint16Array : Uint32Array;
|
|
17
|
+
export const ctor = (x) => x.constructor;
|
|
18
|
+
export const emptyLike = (x) => new (ctor(x))(x.length);
|
|
19
|
+
export const set = (xs, x, i) => (xs.set(x, i), xs);
|
|
20
|
+
export const concat = (chunks) => {
|
|
21
|
+
const out = new (ctor(chunks[0]))(chunks.reduce((a, x) => a + x.length, 0));
|
|
22
|
+
chunks.reduce((offset, chunk) => (out.set(chunk, offset), offset + chunk.length), 0);
|
|
23
|
+
return out;
|
|
24
|
+
};
|
|
25
|
+
export const iter = (size, stride = size) => function* (data) {
|
|
26
|
+
const C = ctor(data);
|
|
27
|
+
for (let i = 0, n = data.length; i < n - size + 1; i += stride) {
|
|
28
|
+
const offset = data.byteOffset + i * C.BYTES_PER_ELEMENT;
|
|
29
|
+
yield new C(data.buffer, offset, size);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export const tile = (n) => (out, x) => {
|
|
33
|
+
for (let i = 0; i < n; i++)
|
|
34
|
+
set(out, x, i * x.length);
|
|
35
|
+
return out;
|
|
36
|
+
};
|
|
37
|
+
export const tileEvery = (m, n) => (xs, out = new (ctor(xs))(xs.length * n)) => (zmap(tile(n))(iter(m * n)(out), iter(m)(xs)), out);
|
|
38
|
+
export const strided = (data, size, stride = size, out = new (ctor(data))(data.length / size * stride)) => (iter(size)(data).forEach((p, i) => set(out, p, i * stride)), out);
|
|
39
|
+
export const toFixed = (n, sep = ',') => (xs) => reduce((push), [])(mapI(x => x.toFixed(n))(Iterator.from(xs))).join(sep);
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export interface RecordOf<T> {
|
|
2
|
+
[id: PropertyKey]: T;
|
|
3
|
+
}
|
|
4
|
+
export type ValueOf<T> = T[keyof T];
|
|
5
|
+
export type Structure<T> = T | readonly Structure<T>[] | RecordOf<Structure<T>>;
|
|
6
|
+
export type Optional<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> & Partial<Pick<T, K>>;
|
|
7
|
+
export type Tuple<T, N extends number, R extends T[] = []> = R['length'] extends N ? R : Tuple<T, N, [T, ...R]>;
|
|
8
|
+
export type Elements<A extends readonly unknown[]> = A extends readonly (infer T)[] ? T : never;
|
|
9
|
+
export type MaybeFirst<T extends unknown[], S = void> = T extends {
|
|
10
|
+
length: 0;
|
|
11
|
+
} ? S : T[0];
|
|
12
|
+
export type FnV<T extends any[] = any[], R = any> = (...x: T) => R;
|
|
13
|
+
export type Fn<T = any, R = any> = FnV<[T], R>;
|
|
14
|
+
export type FnP<T = any, R = any> = (x: T) => Promise<R>;
|
|
15
|
+
export type Fns<T> = {
|
|
16
|
+
[k in keyof T]: Fn<T[k]>;
|
|
17
|
+
};
|
|
18
|
+
export type FnF = <F extends FnV>(f: F) => (...xs: Parameters<F>) => ReturnType<F>;
|
|
19
|
+
export type Dispose = Fn<void>;
|
|
20
|
+
export type Reactive<T = unknown, R = any> = Fn<Fn<T, R>, Dispose>;
|
|
21
|
+
export type Constantly<T> = () => T;
|
|
22
|
+
export type FirstParam<F extends FnV> = MaybeFirst<Parameters<F>>;
|
|
23
|
+
export type MaybePromise<T = unknown> = T | PromiseLike<T>;
|
|
24
|
+
export type Last<T extends any[]> = T extends [...any, infer Rest] ? Rest : never;
|
|
25
|
+
export type Tail<T extends any[]> = T extends [any, ...(infer Rest)] ? Rest : never;
|
|
26
|
+
export type Push<T extends any[], V> = [...T, V];
|
|
27
|
+
export type Pop<T extends any[]> = T extends [...infer head, any] ? head : never;
|
|
28
|
+
export type MinusOne<T extends number, A extends any[] = []> = A['length'] extends T ? Pop<A>['length'] : MinusOne<T, [...A, 0]>;
|
|
29
|
+
export type Take<N extends number, T extends any[], R extends any[] = []> = R['length'] extends N ? R : Take<N, Tail<T>, [...R, T[0]]>;
|
|
30
|
+
export type Skip<N extends number, T extends any[]> = N extends 0 ? T : Skip<MinusOne<N>, Tail<T>>;
|
|
31
|
+
export type Range<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : Range<N, [...Acc, Acc['length']]>;
|
|
32
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
33
|
+
export type LastOf<T> = UnionToIntersection<T extends any ? (x: T) => void : never> extends (x: infer L) => void ? L : never;
|
|
34
|
+
export type UnionToTuple<T> = [T] extends [never] ? [] : Push<UnionToTuple<Exclude<T, LastOf<T>>>, LastOf<T>>;
|
|
35
|
+
export type Entry<K extends PropertyKey, V> = [K, V];
|
|
36
|
+
export type Entries<T> = {
|
|
37
|
+
[K in keyof T]: Entry<K, T[K]>;
|
|
38
|
+
}[keyof T];
|
|
39
|
+
export type EntriesTuple<T, K extends UnionToTuple<keyof T> = UnionToTuple<keyof T>> = {
|
|
40
|
+
[I in keyof K]: K[I] extends keyof T ? [K[I], T[K[I]]] : never;
|
|
41
|
+
};
|
|
42
|
+
export type UintArray<T extends ArrayBufferLike = ArrayBufferLike> = Uint8Array<T> | Uint16Array<T> | Uint32Array<T>;
|
|
43
|
+
export type IntArray<T extends ArrayBufferLike = ArrayBufferLike> = Int8Array<T> | Int16Array<T> | Int32Array<T>;
|
|
44
|
+
export type FloatArray<T extends ArrayBufferLike = ArrayBufferLike> = Float16Array<T> | Float32Array<T> | Float64Array<T>;
|
|
45
|
+
export type BigIntArray<T extends ArrayBufferLike = ArrayBufferLike> = BigUint64Array<T> | BigInt64Array<T>;
|
|
46
|
+
export type NumberArray<T extends ArrayBufferLike = ArrayBufferLike> = UintArray<T> | IntArray<T> | FloatArray<T>;
|
|
47
|
+
export type TypedArray<T extends ArrayBufferLike = ArrayBufferLike> = NumberArray | BigIntArray<T>;
|
|
48
|
+
export type Number<T extends TypedArray> = T extends NumberArray ? number : bigint;
|
|
49
|
+
export type BufferType<T extends TypedArray> = T extends TypedArray<infer S> ? S : never;
|
|
50
|
+
export type Eq<A, B = A> = FnV<[A, B], boolean>;
|
|
51
|
+
export type Pred<T> = Fn<T, boolean>;
|
|
52
|
+
export type PredV<T extends any[]> = FnV<T, boolean>;
|
|
53
|
+
export type TPred<T extends S, S = any> = (x: S) => x is T;
|
|
54
|
+
export type Maybe<T> = T | undefined;
|
|
55
|
+
export type Indexed<T> = [number, T];
|
|
56
|
+
export type Required<T, K extends keyof T> = T & {
|
|
57
|
+
[P in K]-?: T[P];
|
|
58
|
+
};
|
|
59
|
+
export type Partials<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
60
|
+
export type KeyMap<T extends string> = {
|
|
61
|
+
[K in T]: Extract<K, T>;
|
|
62
|
+
};
|
|
63
|
+
export {};
|
package/src/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/src/utils.d.ts
ADDED
package/src/utils.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { assert } from "./checks.js";
|
|
2
|
+
export function* toposort(nodes) {
|
|
3
|
+
const n = nodes.length;
|
|
4
|
+
const queue = [], children = new Map();
|
|
5
|
+
nodes.forEach((p, i) => {
|
|
6
|
+
if (p < 0)
|
|
7
|
+
queue.push(i);
|
|
8
|
+
else {
|
|
9
|
+
assert(p < n, `[toposort] Invalid parent: ${p}`);
|
|
10
|
+
if (!children.has(p))
|
|
11
|
+
children.set(p, []);
|
|
12
|
+
children.get(p).push(i);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
while (queue.length > 0) {
|
|
16
|
+
const p = queue.shift();
|
|
17
|
+
yield p;
|
|
18
|
+
if (children.has(p)) {
|
|
19
|
+
queue.push(...children.get(p));
|
|
20
|
+
children.delete(p);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export const hex2rgb = (hex) => {
|
|
25
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
26
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
27
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
28
|
+
return [r, g, b];
|
|
29
|
+
};
|
|
30
|
+
export const rgb2hex = (rgb) => "#" + rgb.map(x => Math.round(x).toString(16).padStart(2, '0')).join("");
|
package/src/weak.d.ts
ADDED
package/src/weak.js
ADDED
package/stream.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fn } from "./types";
|
|
1
|
+
import type { Fn } from "./types.js";
|
|
2
2
|
export declare const readable: <T>(x: T) => ReadableStream<any>;
|
|
3
3
|
export declare function iterate<T>(rs: ReadableStream<T>): AsyncGenerator<Awaited<T>, void, unknown>;
|
|
4
4
|
export declare const map: <T, S>(f: Fn<T, S>) => TransformStream<T, S>;
|
package/stream.js
CHANGED
package/string.d.ts
CHANGED
package/string.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EMPTY } from "./constants";
|
|
2
|
-
import { seek } from "./array";
|
|
1
|
+
import { EMPTY } from "./constants.js";
|
|
2
|
+
import { seek } from "./array.js";
|
|
3
3
|
export const basename = (path) => path.split("/").at(-1) ?? "";
|
|
4
4
|
export const dirname = (path) => {
|
|
5
5
|
const parts = path.split("/");
|
package/struct.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TypedArray, Fn, NumberArray } from "./types";
|
|
2
|
-
import type { Constructor } from "./typedarray";
|
|
1
|
+
import type { TypedArray, Fn, NumberArray } from "./types.js";
|
|
2
|
+
import type { Constructor } from "./typedarray.js";
|
|
3
3
|
export interface Type {
|
|
4
4
|
size: number;
|
|
5
5
|
align: number;
|
package/struct.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { align as _align } from "./math";
|
|
2
|
-
import { isBigIntArray, isNumberArray } from "./checks";
|
|
1
|
+
import { align as _align } from "./math.js";
|
|
2
|
+
import { isBigIntArray, isNumberArray } from "./checks.js";
|
|
3
3
|
const vec = (type) => (length = 1, align = type.BYTES_PER_ELEMENT) => ({
|
|
4
4
|
type, align, length, size: type.BYTES_PER_ELEMENT * length,
|
|
5
5
|
});
|
package/tree.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fn, FnV, TPred, PredV } from './types';
|
|
1
|
+
import type { Fn, FnV, TPred, PredV } from './types.js';
|
|
2
2
|
export type Node<S, T = S> = T | Tree<S, T>;
|
|
3
3
|
export type Tree<S, T = S> = [S, Node<S, T>[]];
|
|
4
4
|
export declare const tree: <S, T = S>(value: S, children?: Node<S, T>[]) => Tree<S, T>;
|
package/tree.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { identity } from './fn';
|
|
2
|
-
import { EMPTY } from './constants';
|
|
3
|
-
import { zip as zipI } from './iterable';
|
|
1
|
+
import { identity } from './fn.js';
|
|
2
|
+
import { EMPTY } from './constants.js';
|
|
3
|
+
import { zip as zipI } from './iterable.js';
|
|
4
4
|
export const tree = (value, children = []) => [value, children];
|
|
5
5
|
export const isTree = (x) => Array.isArray(x) && x.length == 2 && Array.isArray(x[1]);
|
|
6
6
|
export const children = (x, p = isTree) => p(x) ? x[1] : EMPTY.LIST;
|
package/treemap.d.ts
CHANGED
package/treemap.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { before } from "./fn";
|
|
2
|
-
import { isDefined } from "./checks";
|
|
3
|
-
import { EMPTY } from "./constants";
|
|
1
|
+
import { before } from "./fn.js";
|
|
2
|
+
import { isDefined } from "./checks.js";
|
|
3
|
+
import { EMPTY } from "./constants.js";
|
|
4
4
|
export const treemap = () => {
|
|
5
5
|
const nodes = new Set();
|
|
6
6
|
const parents = new Map();
|
package/typedarray.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FnV, TypedArray, NumberArray, BufferType, Number } from "./types";
|
|
1
|
+
import type { FnV, TypedArray, NumberArray, BufferType, Number } from "./types.js";
|
|
2
2
|
export interface Constructor<T extends TypedArray> {
|
|
3
3
|
new (length: number): T;
|
|
4
4
|
new (buffer: BufferType<T> | ArrayBufferLike, byteOffset?: number, length?: number): T;
|
package/typedarray.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { bind } from "./fn";
|
|
2
|
-
import { zmap, map as mapI, reduce } from "./iterable";
|
|
3
|
-
import { push } from "./array";
|
|
1
|
+
import { bind } from "./fn.js";
|
|
2
|
+
import { zmap, map as mapI, reduce } from "./iterable.js";
|
|
3
|
+
import { push } from "./array.js";
|
|
4
4
|
export const view = (type, length) => (buf = new ArrayBuffer(type.BYTES_PER_ELEMENT * length), offset = 0) => new type(buf, offset, length);
|
|
5
5
|
export const u8 = bind((view), Uint8Array);
|
|
6
6
|
export const u16 = bind((view), Uint16Array);
|
package/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Tuple } from "./types";
|
|
1
|
+
import type { Tuple } from "./types.js";
|
|
2
2
|
export declare function toposort(nodes: number[]): Generator<number | undefined, void, unknown>;
|
|
3
3
|
export declare const hex2rgb: (hex: string) => number[];
|
|
4
4
|
export declare const rgb2hex: (rgb: Tuple<number, 3>) => string;
|
package/utils.js
CHANGED
package/weak.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Fn, Maybe } from "./types";
|
|
1
|
+
import type { Fn, Maybe } from "./types.js";
|
|
2
2
|
export declare const deref: <T extends WeakKey, F extends Fn<T>>(r: WeakRef<T>, f: F) => Maybe<ReturnType<F>>;
|
package/weak.js
CHANGED