@cgtk/std 0.0.182 → 0.0.183

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/base64.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const decodeBytes: (str: string) => Uint8Array<ArrayBuffer>;
package/base64.js ADDED
@@ -0,0 +1,7 @@
1
+ export const decodeBytes = (str) => {
2
+ const raw = atob(str), size = raw.length;
3
+ const res = new Uint8Array(size);
4
+ for (let i = 0; i < size; i++)
5
+ res[i] = raw.charCodeAt(i);
6
+ return res;
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cgtk/std",
3
- "version": "0.0.182",
3
+ "version": "0.0.183",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "exports": {
@@ -33,6 +33,7 @@
33
33
  "./basen": "./basen.js",
34
34
  "./struct": "./struct.js",
35
35
  "./buffer": "./buffer.js",
36
+ "./base64": "./base64.js",
36
37
  "./utils": "./utils.js"
37
38
  },
38
39
  "devDependencies": {
package/struct.d.ts CHANGED
@@ -18,8 +18,9 @@ export declare const f32: Num<Float32Array<ArrayBufferLike>>;
18
18
  export declare const f64: Num<Float64Array<ArrayBufferLike>>;
19
19
  export declare const vec: <T extends TypedArray, N extends number>(t: Num<T>, length: N, align?: number, size?: number) => View<T>;
20
20
  export declare const array: <T>(type: View<T>, length: number, size?: number, align?: number) => View<T[]>;
21
- type Struct<T extends ReadonlyArray<readonly [string, View<any>]>> = View<{
21
+ export type Fields = ReadonlyArray<readonly [string, View<unknown>]>;
22
+ export type Struct<T extends Fields> = View<{
22
23
  [K in T[number] as K[0]]: K[1] extends Num<any> ? number : Inner<K[1]>;
23
24
  }>;
24
- export declare const struct: <T extends ReadonlyArray<readonly [string, View<any>]>>(fs: T) => Struct<T>;
25
+ export declare const struct: <T extends Fields>(fs: T) => Struct<T>;
25
26
  export {};
package/struct.js CHANGED
@@ -47,9 +47,8 @@ export const struct = (fs) => {
47
47
  const size = _align(offset, align);
48
48
  const f = ((buf = new ArrayBuffer(size), offset = 0) => {
49
49
  const res = {};
50
- for (const [name, type] of Object.entries(fields)) {
50
+ for (const [name, type] of Object.entries(fields))
51
51
  Object.defineProperty(res, name, property(type(buf, offset + offsets[name])));
52
- }
53
52
  return res;
54
53
  });
55
54
  f.size = size;