@cgtk/std 0.0.182 → 0.0.184

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/iterable.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { Fn, FnV, Indexed, Pred } from "./types.js";
1
+ import type { Fn, FnV, Indexed, Pred } from "./types";
2
+ export declare const next: <T>(xs: Iterator<T>) => T;
2
3
  export declare const repeat: (n: number) => <A>(x: A) => Iterator<A>;
3
4
  export declare const just: <T>(x: T) => IteratorObject<T>;
4
5
  export declare const enumerate: (n?: number) => <T>(x: T) => Indexed<T>;
@@ -17,7 +18,7 @@ export declare const flat: <T>(xs: IteratorObject<IteratorObject<T>>) => Iterato
17
18
  export declare const prepend: <A>(ys: IteratorObject<A>) => (xs: IteratorObject<A>) => Generator<A, void, unknown>;
18
19
  export declare const append: <A>(ys: IteratorObject<A>) => (xs: IteratorObject<A>) => Generator<A, void, unknown>;
19
20
  export declare const first: <T>(xs: IteratorObject<T>) => T | undefined;
20
- export declare const reduce: <T, S>(f: FnV<[S, T], S>, a: S) => (xs: IteratorObject<T>) => S;
21
+ export declare const reduce: <T, S>(f: FnV<[S, T, number], S>, a: S) => (xs: IteratorObject<T>) => S;
21
22
  export declare const traverse: <T>(children: Fn<T, Iterable<T>>, f: Fn<T>) => Fn<T>;
22
23
  export declare const take: (n: number) => <T>(xs: IteratorObject<T>) => Generator<T>;
23
24
  export declare function arange(a: number, b?: number, s?: number): Generator<number, void, unknown>;
package/iterable.js CHANGED
@@ -1,5 +1,11 @@
1
- import { pipe, comp, scan, apply, noop, identity, constantly } from "./fn.js";
2
- import { set } from "./map.js";
1
+ import { assert, isDefined } from "./checks";
2
+ import { pipe, comp, scan, apply, noop, identity, constantly } from "./fn";
3
+ import { set } from "./map";
4
+ export const next = (xs) => {
5
+ const { done, value } = xs.next();
6
+ assert(isDefined(done) && !done, "iterator done");
7
+ return value;
8
+ };
3
9
  export const repeat = n => function* (x) { for (let i = 0; i < n; i++)
4
10
  yield x; };
5
11
  export const just = function* (x) { yield x; };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cgtk/std",
3
- "version": "0.0.182",
3
+ "version": "0.0.184",
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;
package/typedarray.d.ts CHANGED
@@ -13,7 +13,7 @@ export declare const f64: (length: number) => View<Float64Array<ArrayBufferLike>
13
13
  export declare const UintArray: (n: number) => Uint8ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor;
14
14
  export declare const ctor: <T extends TypedArray>(x: T) => Constructor<T>;
15
15
  export declare const emptyLike: <T extends TypedArray>(x: T) => T;
16
- export declare const set: <T extends TypedArray>(xs: T, v: Numbers, i: number) => T;
16
+ export declare const set: <T extends TypedArray>(xs: T, x: Numbers, i: number) => T;
17
17
  export declare const concat: <T extends TypedArray>(chunks: T[]) => T;
18
18
  export declare const iter: (size: number, stride?: number) => <T extends TypedArray>(data: T) => Generator<T>;
19
19
  export declare const tile: (n: number) => (out: TypedArray, x: TypedArray) => TypedArray;
package/typedarray.js CHANGED
@@ -13,7 +13,7 @@ export const f64 = bind((view), Float64Array);
13
13
  export const UintArray = (n) => n < 256 ? Uint8Array : n < 65536 ? Uint16Array : Uint32Array;
14
14
  export const ctor = (x) => x.constructor;
15
15
  export const emptyLike = (x) => new (ctor(x))(x.length);
16
- export const set = (xs, v, i) => (xs.set(v, i), xs);
16
+ export const set = (xs, x, i) => (xs.set(x, i), xs);
17
17
  export const concat = (chunks) => {
18
18
  const out = new (ctor(chunks[0]))(chunks.reduce((a, x) => a + x.length, 0));
19
19
  chunks.reduce((offset, chunk) => (out.set(chunk, offset), offset + chunk.length), 0);