@thi.ng/api 8.3.8 → 8.4.1

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2022-07-19T15:36:12Z
3
+ - **Last updated**: 2022-08-23T10:37:04Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,16 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [8.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/api@8.4.0) (2022-08-15)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add i64/u64 support for typed arrays ([0bb5277](https://github.com/thi-ng/umbrella/commit/0bb5277))
17
+ - add various 64bit bigint related types & lookups
18
+ - add BIT_SHIFTS LUT
19
+ - update sizeOf()
20
+ - update typedArray()
21
+
12
22
  ## [8.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/api@8.3.0) (2021-11-17)
13
23
 
14
24
  #### 🚀 Features
package/README.md CHANGED
@@ -60,7 +60,7 @@ node --experimental-repl-await
60
60
  > const api = await import("@thi.ng/api");
61
61
  ```
62
62
 
63
- Package sizes (gzipped, pre-treeshake): ESM: 2.25 KB
63
+ Package sizes (gzipped, pre-treeshake): ESM: 2.33 KB
64
64
 
65
65
  ## Dependencies
66
66
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/api",
3
- "version": "8.3.8",
3
+ "version": "8.4.1",
4
4
  "description": "Common, generic types, interfaces & mixins",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@microsoft/api-extractor": "^7.25.0",
38
- "@thi.ng/testament": "^0.2.9",
38
+ "@thi.ng/testament": "^0.2.12",
39
39
  "rimraf": "^3.0.2",
40
40
  "tools": "^0.0.1",
41
41
  "typedoc": "^0.22.17",
@@ -222,5 +222,5 @@
222
222
  "default": "./watch.js"
223
223
  }
224
224
  },
225
- "gitHead": "108a6357b77d457912d30681d7cc5603ae995209\n"
225
+ "gitHead": "be8423e2019e95c14a096260a93b9762dde0c768\n"
226
226
  }
package/typedarray.d.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  export declare type ArrayLikeIterable<T> = ArrayLike<T> & Iterable<T>;
2
2
  export declare type NumericArray = number[] | TypedArray;
3
3
  export declare type TypedArray = Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;
4
+ export declare type BigTypedArray = BigInt64Array | BigUint64Array;
4
5
  export declare type FloatArray = Float32Array | Float64Array;
5
6
  export declare type IntArray = Int8Array | Int16Array | Int32Array;
6
7
  export declare type UIntArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;
7
8
  export declare type FloatArrayConstructor = Float32ArrayConstructor | Float64ArrayConstructor;
8
9
  export declare type IntArrayConstructor = Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor;
9
10
  export declare type UIntArrayConstructor = Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor;
11
+ export declare type BigIntArrayConstructor = BigInt64ArrayConstructor | BigUint64ArrayConstructor;
10
12
  export declare type TypedArrayConstructor = FloatArrayConstructor | IntArrayConstructor | UIntArrayConstructor;
11
13
  /**
12
14
  * Type IDs for typed array backed buffers and generally describing binary data
@@ -15,6 +17,7 @@ export declare type TypedArrayConstructor = FloatArrayConstructor | IntArrayCons
15
17
  * {@link GLType} {@link GL2TYPE} {@link TYPE2GL}
16
18
  */
17
19
  export declare type Type = "u8" | "u8c" | "i8" | "u16" | "i16" | "u32" | "i32" | "f32" | "f64";
20
+ export declare type BigType = "i64" | "u64";
18
21
  export declare type UintType = "u8" | "u8c" | "u16" | "u32";
19
22
  export declare type IntType = "i8" | "i16" | "i32";
20
23
  export declare type FloatType = "f32" | "f64";
@@ -48,7 +51,8 @@ export declare const GL2TYPE: Record<GLType, Type>;
48
51
  */
49
52
  export declare const TYPE2GL: Record<Type, GLType | undefined>;
50
53
  /**
51
- * Size information (in bytes) for {@link Type}. Also see {@link sizeOf}.
54
+ * Size information (in bytes) for {@link Type} and {@link BigType}. Also see
55
+ * {@link sizeOf}.
52
56
  */
53
57
  export declare const SIZEOF: {
54
58
  u8: number;
@@ -58,12 +62,32 @@ export declare const SIZEOF: {
58
62
  i16: number;
59
63
  u32: number;
60
64
  i32: number;
65
+ i64: number;
66
+ u64: number;
67
+ f32: number;
68
+ f64: number;
69
+ };
70
+ /**
71
+ * Bit shift values to convert byte addresses into array indices for all
72
+ * {@link Type}s and {@link BigType}s.
73
+ */
74
+ export declare const BIT_SHIFTS: {
75
+ i8: number;
76
+ u8: number;
77
+ u8c: number;
78
+ i16: number;
79
+ u16: number;
80
+ i32: number;
81
+ u32: number;
82
+ i64: number;
83
+ u64: number;
61
84
  f32: number;
62
85
  f64: number;
63
86
  };
64
87
  export declare const FLOAT_ARRAY_CTORS: Record<FloatType, FloatArrayConstructor>;
65
88
  export declare const INT_ARRAY_CTORS: Record<IntType, IntArrayConstructor>;
66
89
  export declare const UINT_ARRAY_CTORS: Record<UintType, UIntArrayConstructor>;
90
+ export declare const BIGINT_ARRAY_CTORS: Record<BigType, BigIntArrayConstructor>;
67
91
  export declare const TYPEDARRAY_CTORS: Record<Type, TypedArrayConstructor>;
68
92
  export interface TypedArrayTypeMap extends Record<Type | GLType, TypedArray> {
69
93
  u8: Uint8Array;
@@ -83,6 +107,10 @@ export interface TypedArrayTypeMap extends Record<Type | GLType, TypedArray> {
83
107
  [GLType.I32]: Int32Array;
84
108
  [GLType.F32]: Float32Array;
85
109
  }
110
+ export interface BigTypedArrayTypeMap extends Record<BigType, BigTypedArray> {
111
+ i64: BigInt64Array;
112
+ u64: BigUint64Array;
113
+ }
86
114
  /**
87
115
  * Returns canonical {@link Type} value of `type` by first
88
116
  * attempting to resolve it as {@link GLType} enum.
@@ -117,16 +145,19 @@ export declare const asInt: (...args: number[]) => number[];
117
145
  *
118
146
  * @param type -
119
147
  */
120
- export declare const sizeOf: (type: GLType | Type) => number;
148
+ export declare const sizeOf: (type: Type | BigType | GLType) => number;
121
149
  /**
122
- * Constructs new typed array of given {@link Type}/{@link GLType}. Supports all
123
- * arities of standard typed array ctors.
150
+ * Constructs new typed array of given {@link Type}, {@link GLType} or
151
+ * {@link BigType}. Supports all arities of standard typed array ctors.
124
152
  *
125
153
  * @param type - array type enum
126
154
  */
127
155
  export declare function typedArray<T extends Type | GLType>(type: T, length: number): TypedArrayTypeMap[T];
128
156
  export declare function typedArray<T extends Type | GLType>(type: T, src: ArrayLike<number> | ArrayBufferLike): TypedArrayTypeMap[T];
129
157
  export declare function typedArray<T extends Type | GLType>(type: T, buf: ArrayBufferLike, byteOffset: number, length?: number): TypedArrayTypeMap[T];
158
+ export declare function typedArray<T extends BigType>(type: T, length: number): BigTypedArrayTypeMap[T];
159
+ export declare function typedArray<T extends BigType>(type: T, src: ArrayLike<bigint> | ArrayBufferLike): BigTypedArrayTypeMap[T];
160
+ export declare function typedArray<T extends BigType>(type: T, buf: ArrayBufferLike, byteOffset: number, length?: number): BigTypedArrayTypeMap[T];
130
161
  /**
131
162
  * Takes an {@link NumericArray} and returns its corresponding {@link Type} ID.
132
163
  * Standard JS arrays will default to {@link "f64"}.
package/typedarray.js CHANGED
@@ -47,7 +47,8 @@ export const TYPE2GL = {
47
47
  f64: undefined,
48
48
  };
49
49
  /**
50
- * Size information (in bytes) for {@link Type}. Also see {@link sizeOf}.
50
+ * Size information (in bytes) for {@link Type} and {@link BigType}. Also see
51
+ * {@link sizeOf}.
51
52
  */
52
53
  export const SIZEOF = {
53
54
  u8: 1,
@@ -57,9 +58,28 @@ export const SIZEOF = {
57
58
  i16: 2,
58
59
  u32: 4,
59
60
  i32: 4,
61
+ i64: 8,
62
+ u64: 8,
60
63
  f32: 4,
61
64
  f64: 8,
62
65
  };
66
+ /**
67
+ * Bit shift values to convert byte addresses into array indices for all
68
+ * {@link Type}s and {@link BigType}s.
69
+ */
70
+ export const BIT_SHIFTS = {
71
+ i8: 0,
72
+ u8: 0,
73
+ u8c: 0,
74
+ i16: 1,
75
+ u16: 1,
76
+ i32: 2,
77
+ u32: 2,
78
+ i64: 3,
79
+ u64: 3,
80
+ f32: 2,
81
+ f64: 2,
82
+ };
63
83
  export const FLOAT_ARRAY_CTORS = {
64
84
  f32: Float32Array,
65
85
  f64: Float64Array,
@@ -75,6 +95,10 @@ export const UINT_ARRAY_CTORS = {
75
95
  u16: Uint16Array,
76
96
  u32: Uint32Array,
77
97
  };
98
+ export const BIGINT_ARRAY_CTORS = {
99
+ i64: BigInt64Array,
100
+ u64: BigUint64Array,
101
+ };
78
102
  export const TYPEDARRAY_CTORS = {
79
103
  ...FLOAT_ARRAY_CTORS,
80
104
  ...INT_ARRAY_CTORS,
@@ -120,9 +144,10 @@ export const asInt = (...args) => args.map((x) => x | 0);
120
144
  *
121
145
  * @param type -
122
146
  */
123
- export const sizeOf = (type) => SIZEOF[asNativeType(type)];
147
+ export const sizeOf = (type) => SIZEOF[type] || SIZEOF[asNativeType(type)];
124
148
  export function typedArray(type, ...xs) {
125
- return new TYPEDARRAY_CTORS[asNativeType(type)](...xs);
149
+ const ctor = BIGINT_ARRAY_CTORS[type];
150
+ return new (ctor || TYPEDARRAY_CTORS[asNativeType(type)])(...xs);
126
151
  }
127
152
  /**
128
153
  * Takes an {@link NumericArray} and returns its corresponding {@link Type} ID.