@cgtk/std 0.0.189 → 0.0.190
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/checks.d.ts +2 -1
- package/checks.js +1 -0
- package/package.json +1 -1
- package/struct.d.ts +1 -1
- package/struct.js +2 -2
package/checks.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { TypedArray, Pred, TPred, Optional, Numbers } from "./types";
|
|
1
|
+
import type { TypedArray, BigIntArray, Pred, TPred, Optional, Numbers } from "./types";
|
|
2
2
|
export declare const isTypedArray: (x: any) => x is TypedArray;
|
|
3
|
+
export declare const isBigIntArray: (x: any) => x is BigIntArray;
|
|
3
4
|
export declare const isUndefined: (x: any) => x is undefined;
|
|
4
5
|
export declare const isNull: (x: any) => x is null;
|
|
5
6
|
export declare const isDefined: <T>(x: Optional<T>) => x is T;
|
package/checks.js
CHANGED
|
@@ -4,6 +4,7 @@ export const isTypedArray = (x) => x && (x instanceof Uint8Array || x instanceof
|
|
|
4
4
|
x instanceof Uint16Array || x instanceof Uint32Array ||
|
|
5
5
|
x instanceof Int8Array || x instanceof Int16Array || x instanceof Int32Array ||
|
|
6
6
|
x instanceof Float32Array || x instanceof Float64Array);
|
|
7
|
+
export const isBigIntArray = (x) => x && (x instanceof BigUint64Array || x instanceof BigInt64Array);
|
|
7
8
|
export const isUndefined = (x) => x === undefined;
|
|
8
9
|
export const isNull = (x) => x === null;
|
|
9
10
|
export const isDefined = (x) => !isUndefined(x);
|
package/package.json
CHANGED
package/struct.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export type Struct<T extends ReadonlyArray<Field<any>>> = Type & {
|
|
|
36
36
|
export declare const isStruct: (t: any) => t is Struct<any>;
|
|
37
37
|
export declare const struct: <T extends ReadonlyArray<Field<any>>>(fs: T, align?: number, offset?: number) => Struct<T>;
|
|
38
38
|
export type View<T extends Type> = T extends Vec<infer C, any> ? C : T extends Array<infer S> ? View<S>[] : T extends Struct<infer F> ? {
|
|
39
|
-
[K in F[number] as K[0]]: K[1] extends Vec<infer C, infer N> ? (N extends 1 ? number : C) : View<K[1]>;
|
|
39
|
+
[K in F[number] as K[0]]: K[1] extends Vec<infer C, infer N> ? (N extends 1 ? (C extends TypedArray ? number : bigint) : C) : View<K[1]>;
|
|
40
40
|
} : never;
|
|
41
41
|
export declare const view: <T extends Vec<any, any> | Array<any> | Struct<any>>(t: T, buf?: ArrayBufferLike, offset?: number) => View<T>;
|
|
42
42
|
export {};
|
package/struct.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { align as _align } from "./math";
|
|
2
|
-
import { isTypedArray } from "./checks";
|
|
2
|
+
import { isTypedArray, isBigIntArray } from "./checks";
|
|
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
|
});
|
|
@@ -42,7 +42,7 @@ export const struct = (fs, align = 0, offset = 0) => {
|
|
|
42
42
|
};
|
|
43
43
|
const property = (value) => ({
|
|
44
44
|
enumerable: true,
|
|
45
|
-
...(isTypedArray(value) && value.length == 1 ? {
|
|
45
|
+
...((isTypedArray(value) || isBigIntArray(value)) && value.length == 1 ? {
|
|
46
46
|
get: () => value[0],
|
|
47
47
|
set: (x) => value[0] = x,
|
|
48
48
|
} : { value })
|