@cgtk/std 0.0.188 → 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 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/http.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export declare const assertStatus: (status: number) => (resp: Response) => void;
2
2
  export declare const contentLength: (response: Response) => number;
3
3
  export declare const toByteArray: (stream: ReadableStream<Uint8Array>) => Promise<Uint8Array<ArrayBufferLike>>;
4
- export declare const fetchBuffer: (url: string, init?: RequestInit) => Promise<Uint8Array<ArrayBufferLike>>;
4
+ export declare const fetchBuffer: (url: string | URL | Request, init?: RequestInit) => Promise<Uint8Array<ArrayBufferLike>>;
5
5
  export declare const fetchText: (url: string, init?: RequestInit) => Promise<string>;
6
6
  export declare const fetchDOM: (url: string, init?: RequestInit) => Promise<HTMLElement>;
7
7
  export declare const fetchImage: (src: string) => Promise<HTMLImageElement>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cgtk/std",
3
- "version": "0.0.188",
3
+ "version": "0.0.190",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "exports": {
package/struct.d.ts CHANGED
@@ -1,19 +1,21 @@
1
- import type { TypedArray, Fn } from "./types";
1
+ import type { TypedArray, BigIntArray, Fn } from "./types";
2
2
  import type { Constructor } from "./typedarray";
3
3
  export interface Type {
4
4
  size: number;
5
5
  align: number;
6
6
  }
7
- export type Vec<T extends TypedArray, N extends number> = Type & {
7
+ export type Vec<T extends TypedArray | BigIntArray, N extends number> = Type & {
8
8
  length: N;
9
9
  type: Constructor<T>;
10
10
  };
11
11
  export declare const u8: <N extends number = 1>(length?: N, align?: number) => Vec<Uint8Array<ArrayBufferLike>, N>;
12
12
  export declare const u16: <N extends number = 1>(length?: N, align?: number) => Vec<Uint16Array<ArrayBufferLike>, N>;
13
13
  export declare const u32: <N extends number = 1>(length?: N, align?: number) => Vec<Uint32Array<ArrayBufferLike>, N>;
14
+ export declare const u64: <N extends number = 1>(length?: N, align?: number) => Vec<BigUint64Array<ArrayBufferLike>, N>;
14
15
  export declare const i8: <N extends number = 1>(length?: N, align?: number) => Vec<Int8Array<ArrayBufferLike>, N>;
15
16
  export declare const i16: <N extends number = 1>(length?: N, align?: number) => Vec<Int16Array<ArrayBufferLike>, N>;
16
17
  export declare const i32: <N extends number = 1>(length?: N, align?: number) => Vec<Int32Array<ArrayBufferLike>, N>;
18
+ export declare const i64: <N extends number = 1>(length?: N, align?: number) => Vec<BigInt64Array<ArrayBufferLike>, N>;
17
19
  export declare const f16: <N extends number = 1>(length?: N, align?: number) => Vec<Float16Array<ArrayBufferLike>, N>;
18
20
  export declare const f32: <N extends number = 1>(length?: N, align?: number) => Vec<Float32Array<ArrayBufferLike>, N>;
19
21
  export declare const f64: <N extends number = 1>(length?: N, align?: number) => Vec<Float64Array<ArrayBufferLike>, N>;
@@ -24,7 +26,7 @@ export type Array<T extends Type> = Type & {
24
26
  };
25
27
  export declare const isArray: (t: any) => t is Array<any>;
26
28
  export declare const array: <T extends Type>(type: T, length: number, align?: number) => Array<T>;
27
- type Field<T extends Type> = readonly [name: string, type: T, aligb?: number];
29
+ type Field<T extends Type> = readonly [name: string, type: T, align?: number];
28
30
  export type Struct<T extends ReadonlyArray<Field<any>>> = Type & {
29
31
  fields: {
30
32
  [K in T[number] as K[0]]: K[1];
@@ -34,7 +36,7 @@ export type Struct<T extends ReadonlyArray<Field<any>>> = Type & {
34
36
  export declare const isStruct: (t: any) => t is Struct<any>;
35
37
  export declare const struct: <T extends ReadonlyArray<Field<any>>>(fs: T, align?: number, offset?: number) => Struct<T>;
36
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> ? {
37
- [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]>;
38
40
  } : never;
39
41
  export declare const view: <T extends Vec<any, any> | Array<any> | Struct<any>>(t: T, buf?: ArrayBufferLike, offset?: number) => View<T>;
40
42
  export {};
package/struct.js CHANGED
@@ -1,14 +1,16 @@
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
  });
6
6
  export const u8 = vec(Uint8Array);
7
7
  export const u16 = vec(Uint16Array);
8
8
  export const u32 = vec(Uint32Array);
9
+ export const u64 = vec(BigUint64Array);
9
10
  export const i8 = vec(Int8Array);
10
11
  export const i16 = vec(Int16Array);
11
12
  export const i32 = vec(Int32Array);
13
+ export const i64 = vec(BigInt64Array);
12
14
  export const f16 = vec(Float16Array);
13
15
  export const f32 = vec(Float32Array);
14
16
  export const f64 = vec(Float64Array);
@@ -40,7 +42,7 @@ export const struct = (fs, align = 0, offset = 0) => {
40
42
  };
41
43
  const property = (value) => ({
42
44
  enumerable: true,
43
- ...(isTypedArray(value) && value.length == 1 ? {
45
+ ...((isTypedArray(value) || isBigIntArray(value)) && value.length == 1 ? {
44
46
  get: () => value[0],
45
47
  set: (x) => value[0] = x,
46
48
  } : { value })
package/typedarray.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import type { Fn, FnV, TypedArray, BufferType, Numbers } from "./types";
2
- export interface Constructor<T extends TypedArray> {
1
+ import type { Fn, FnV, TypedArray, BigIntArray, BufferType, Numbers } from "./types";
2
+ export interface Constructor<T extends TypedArray | BigIntArray> {
3
3
  new (length: number): T;
4
4
  new (buffer: BufferType<T> | ArrayBufferLike, byteOffset?: number, length?: number): T;
5
5
  readonly BYTES_PER_ELEMENT: number;
6
- of(...items: number[]): T;
7
- from(arrayLike: ArrayLike<number>): T;
6
+ of(...items: number[] | bigint[]): T;
7
+ from(arrayLike: ArrayLike<number | bigint>): T;
8
8
  }
9
9
  export type View<T extends TypedArray> = FnV<[BufferType<T>?, number?], T>;
10
10
  export declare const view: <T extends TypedArray>(type: Constructor<T>, length: number) => View<T>;
package/types.d.ts CHANGED
@@ -39,7 +39,8 @@ export type EntriesTuple<T, K extends UnionToTuple<keyof T> = UnionToTuple<keyof
39
39
  [I in keyof K]: K[I] extends keyof T ? [K[I], T[K[I]]] : never;
40
40
  };
41
41
  export type TypedArray<T extends ArrayBufferLike = ArrayBufferLike> = Uint8Array<T> | Uint16Array<T> | Uint32Array<T> | Int8Array<T> | Int16Array<T> | Int32Array<T> | Float16Array<T> | Float32Array<T> | Float64Array<T>;
42
- export type BufferType<T extends TypedArray> = T extends TypedArray<infer S> ? S : never;
42
+ export type BigIntArray<T extends ArrayBufferLike = ArrayBufferLike> = BigUint64Array<T> | BigInt64Array<T>;
43
+ export type BufferType<T extends TypedArray | BigIntArray> = T extends TypedArray<infer S> ? S : T extends BigIntArray<infer S> ? S : never;
43
44
  export type Numbers = Array<number> | TypedArray;
44
45
  export type Eq<A, B = A> = FnV<[A, B], boolean>;
45
46
  export type Pred<T> = Fn<T, boolean>;