@the-w1zard/dx 1.0.13 → 1.0.14

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.
@@ -0,0 +1,39 @@
1
+ export declare class S2I extends String implements S2 {
2
+ constructor(value?: A);
3
+ empty(): boolean;
4
+ notEmpty(): boolean;
5
+ blank(): boolean;
6
+ notBlank(): boolean;
7
+ equals(value: string): boolean;
8
+ equalsIgnoreCase(value: string): boolean;
9
+ contains(value: string): boolean;
10
+ starts(value: string): boolean;
11
+ ends(value: string): boolean;
12
+ first(): string;
13
+ last(): string;
14
+ reverse(): string;
15
+ capitalize(): string;
16
+ uncapitalize(): string;
17
+ titleCase(): string;
18
+ camelCase(): string;
19
+ kebabCase(): string;
20
+ snakeCase(): string;
21
+ pascalCase(): string;
22
+ words(): string[];
23
+ lines(): string[];
24
+ chars(): string[];
25
+ unique(): string;
26
+ escapeRegExp(): string;
27
+ stripHtml(): string;
28
+ stripWhitespace(): string;
29
+ truncate(length: N, suffix?: string): string;
30
+ limit(length: N, suffix?: string): string;
31
+ toNumber(): number;
32
+ toInt(radix?: N): number;
33
+ toFloat(): number;
34
+ toBoolean(): boolean;
35
+ toArray(): string[];
36
+ toJSON(): string;
37
+ isWellFormed(): boolean;
38
+ toWellFormed(): string;
39
+ }
@@ -0,0 +1,64 @@
1
+ export declare class U82I<T = A> extends Array<T> implements U82<T> {
2
+ constructor(...items: T[]);
3
+ static get [Symbol.species](): ArrayConstructor;
4
+ static from<T>(arrayLike: ArrayLike<T>): U82I<T>;
5
+ static from<T, U>(arrayLike: ArrayLike<T>, mapFn: (value: T, index: number) => U, thisArg?: A): U82I<U>;
6
+ static from<T>(iterable: Iterable<T> | ArrayLike<T>): U82I<T>;
7
+ static of<T>(...items: T[]): U82I<T>;
8
+ first(): T | undefined;
9
+ last(): T | undefined;
10
+ second(): T | undefined;
11
+ third(): T | undefined;
12
+ random(): T | undefined;
13
+ isEmpty(): boolean;
14
+ isNotEmpty(): boolean;
15
+ isNotEmptyAndDefined(): boolean;
16
+ clear(): this;
17
+ clone(): U82I<T>;
18
+ unique(): U82I<T>;
19
+ compact(): U82I<NonNullable<T>>;
20
+ chunk(size: N): U82I<U82I<T>>;
21
+ flatten<D extends N = 1>(depth?: D): U82I<A>;
22
+ shuffle(): this;
23
+ sample(count?: N): U82I<T>;
24
+ count(predicate?: (value: T, index: N, array: T[]) => unknown): N;
25
+ sum(this: U82I<number>): number;
26
+ average(this: U82I<number>): number;
27
+ min(this: U82I<number>): number | undefined;
28
+ max(this: U82I<number>): number | undefined;
29
+ groupBy<K extends PropertyKey>(keyFn: (value: T, index: N) => K): Map<K, U82I<T>>;
30
+ keyBy<K extends PropertyKey>(keyFn: (value: T, index: N) => K): Map<K, T>;
31
+ partition(predicate: (value: T, index: N, array: T[]) => unknown): [U82I<T>, U82I<T>];
32
+ difference(other: Iterable<T>): U82I<T>;
33
+ intersection(other: Iterable<T>): U82I<T>;
34
+ union(other: Iterable<T>): U82I<T>;
35
+ symmetricDifference(other: Iterable<T>): U82I<T>;
36
+ take(count: N): U82I<T>;
37
+ takeLast(count: N): U82I<T>;
38
+ drop(count: N): U82I<T>;
39
+ dropLast(count: N): U82I<T>;
40
+ pluck<K extends keyof T>(key: K): U82I<T[K]>;
41
+ flattenDeep(): U82I<A>;
42
+ insert(index: N, ...items: T[]): this;
43
+ removeAt(index: N): T | undefined;
44
+ remove(value: T): boolean;
45
+ removeWhere(predicate: (value: T, index: N, array: T[]) => unknown): this;
46
+ replace(oldValue: T, newValue: T): boolean;
47
+ move(from: N, to: N): this;
48
+ swap(i: N, j: N): this;
49
+ shuffleInPlace(): this;
50
+ pick(count?: N): U82I<T>;
51
+ toSet(): Set<T>;
52
+ toMap<K extends PropertyKey>(keyFn: (value: T, index: N) => K): Map<K, T>;
53
+ equals(other: readonly T[]): boolean;
54
+ startsWith(other: readonly T[]): boolean;
55
+ endsWith(other: readonly T[]): boolean;
56
+ isSorted(compareFn?: (a: T, b: T) => N): boolean;
57
+ frequencies(): Map<T, N>;
58
+ findLast<S extends T>(predicate: (value: T, index: N, obj: T[]) => value is S, thisArg?: A): S | undefined;
59
+ findLastIndex(predicate: (value: T, index: N, obj: T[]) => unknown, thisArg?: A): N;
60
+ toReversed(): T[];
61
+ toSorted(compareFn?: (a: T, b: T) => N): T[];
62
+ toSpliced(start: N, deleteCount: N, ...items: T[]): T[];
63
+ with(index: N, value: T): T[];
64
+ }
@@ -0,0 +1,30 @@
1
+ export declare class USP2I extends URLSearchParams implements USP2 {
2
+ constructor(init?: S | URLSearchParams | R<S, S> | S[][]);
3
+ get size(): N;
4
+ getOr(name: S, fallback: S): S;
5
+ getOrNull(name: S): S | NU;
6
+ getOrThrow(name: S, error?: A): string;
7
+ getNumber(name: S, fallback?: N): N | UD;
8
+ getInt(name: S, radix?: N): N | UD;
9
+ getFloat(name: S): N | UD;
10
+ getBoolean(name: S, fallback?: boolean): B;
11
+ getJSON<T = A>(name: S): T | UD;
12
+ getArray(name: S, separator?: string): S[];
13
+ getObject<T extends R<S, A> = R<S, A>>(): T;
14
+ setNumber(name: S, value: N): this;
15
+ setBoolean(name: S, value: B): this;
16
+ setJSON(name: S, value: A): this;
17
+ setArray(name: S, values: Iterable<A>, separator?: string): this;
18
+ setIfAbsent(name: S, value: S): this;
19
+ setIfPresent(name: S, value: S): this;
20
+ appendAll(params: URLSearchParams | R<S, A>): this;
21
+ merge(params: URLSearchParams | R<S, A>, overwrite?: boolean): this;
22
+ clone(): USP2I;
23
+ clear(): V;
24
+ isEmpty(): B;
25
+ isNotEmpty(): B;
26
+ toObject(): R<S, S | S[]>;
27
+ toJSON(): R<S, S | S[]>;
28
+ toURLSearchParams(): URLSearchParams;
29
+ toURL(url: S | URL): URL;
30
+ }
@@ -0,0 +1,32 @@
1
+ export declare class WM2I<H extends WeakKey = A, T = A> extends WeakMap<H, T> implements WM2<H, T> {
2
+ g: (key: H) => T | undefined;
3
+ h: (key: H) => boolean;
4
+ d: (key: H) => boolean;
5
+ private _tracked?;
6
+ s(k: H, v: T | (() => T)): this;
7
+ swap(key: H, value: T): T | UD;
8
+ take(key: H): T | UD;
9
+ getAndDelete(key: H): T | UD;
10
+ peek(key: H): T | false;
11
+ getOrI(key: H, value: T): T;
12
+ getOrM(key: H, make: () => T): T;
13
+ getOr<G>(key: H, fallback: G): T | G;
14
+ getOrThrow(key: H, error?: Error): T;
15
+ getOrCreate(key: H, make: () => T): T;
16
+ ensure(key: H, make: () => T): T;
17
+ update(key: H, fn: (old: T, has: B) => T, initial: T): T;
18
+ setIfAbsent(key: H, value: T): B;
19
+ setIfPresent(key: H, value: T): B;
20
+ hasOrSet(key: H, value: T): B;
21
+ replace(key: H, value: T): B;
22
+ touch(key: H): B;
23
+ get tracked(): B;
24
+ get trackedSize(): N;
25
+ track(key: H): this;
26
+ untrack(key: H): B;
27
+ trackedKeys(): AR<H>;
28
+ trackedValues(): AR<T>;
29
+ trackedEntries(): AR<[H, T]>;
30
+ forEachTracked(fn: (value: T, key: H, map: this) => void): void;
31
+ clearTracked(): void;
32
+ }
@@ -0,0 +1,20 @@
1
+ export declare class WS2I<T extends WeakKey = A> extends WeakSet<T> implements WS2<T> {
2
+ private readonly _tracked;
3
+ constructor(values?: readonly T[] | Iterable<T> | null);
4
+ add(value: T): this;
5
+ delete(value: T): boolean;
6
+ has(value: T): boolean;
7
+ addIfAbsent(value: T): boolean;
8
+ toggle(value: T): boolean;
9
+ deleteIfPresent(value: T): boolean;
10
+ hasAll(values: Iterable<T>): boolean;
11
+ hasAny(values: Iterable<T>): boolean;
12
+ addAll(values: Iterable<T>): this;
13
+ deleteAll(values: Iterable<T>): N;
14
+ replace(oldValue: T, newValue: T): boolean;
15
+ track(value: T): this;
16
+ untrack(value: T): boolean;
17
+ trackedKeys(): T[];
18
+ forEachTracked(callback: (value: T, set: this) => void, thisArg?: A): void;
19
+ clearTracked(): void;
20
+ }
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@the-w1zard/dx",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "sideEffects": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
7
8
  "exports": {
8
9
  ".": {
10
+ "types": "./dist/index.d.ts",
9
11
  "default": "./dist/index.js",
10
- "types": "./src/dx.d.ts"
12
+ "import": "./dist/index.js"
11
13
  }
12
14
  },
13
15
  "files": [
@@ -21,7 +23,7 @@
21
23
  "4": "npm version patch",
22
24
  "5": "git push --tags",
23
25
  "6": "npm publish --access public",
24
- "build": "rspack build",
26
+ "build": "tsc --emitDeclarationOnly && rspack build",
25
27
  "dev": "rspack serve",
26
28
  "check": "tsc --noEmit",
27
29
  "*": "npm run 1 && npm run 2 && npm run 3 && npm run 4 && npm run 5 && npm run 6 && npm run *"
@@ -30,15 +32,15 @@
30
32
  "@rspack/cli": "^2.3.1",
31
33
  "@rspack/core": "^2.3.1",
32
34
  "@rspack/dev-server": "^2.2.2",
35
+ "@the-w1zard/alias_types": "^1.0.3",
33
36
  "@tsconfig/node-lts": "^24.0.0",
34
37
  "@types/node": "^24.0.0",
35
- "typescript": "^6.0.0",
36
- "jsrepo": "^3.8.3"
38
+ "jsrepo": "^3.8.3",
39
+ "typescript": "^6.0.0"
37
40
  },
38
41
  "dependencies": {
39
42
  "@babel/parser": "^8.1.0",
40
43
  "@babel/traverse": "^8.1.0",
41
- "@babel/types": "^8.1.0",
42
- "@the-w1zard/alias_types": "^1.0.2"
44
+ "@babel/types": "^8.1.0"
43
45
  }
44
46
  }
package/src/dx.d.ts CHANGED
@@ -4,21 +4,25 @@ import { M2BINI } from "./map_bin";
4
4
  import { B2BI } from "./boolean_byte";
5
5
  import { M2I } from "./map";
6
6
  import { M2BI } from "./map_byte";
7
- import { SET2I } from "./set";
8
- import { SET2BI } from "./set_byte";
9
- import { D2I, R2I, R2II } from "./date";
7
+
10
8
  import { A2I } from "./array";
11
- import { O2I } from "./object";
12
- import { WM2I } from "./weak_map";
9
+ import { D2I, R2I, R2II } from "./date";
10
+ import { ER2I } from './error'
13
11
  import { I2I } from "./iterator";
14
12
  import { N2I } from "./number";
13
+ import { O2I } from "./object";
15
14
  import { P2I } from "./promise";
15
+ import { REC2, RECC2 } from './reg_ex'
16
+ import { SET2I } from "./set";
17
+ import { SET2BI } from "./set_byte";
18
+ import { SOA_CODEC, soa_codeci } from './soa_codec'
16
19
  import { S2I } from "./string";
17
20
  import { U82I } from "./unit8array";
18
- import { WS2I } from "./weak_set";
19
21
  import { USP2I } from "./url_search_params";
20
- import { ER2I } from "./error";
21
- import {MaybePromise} from '../bag_of_tricks/maybe_promise'
22
+
23
+ import { WM2I } from "./weak_map";
24
+ import { WS2I } from "./weak_set";
25
+ import { MaybePromisei, type MaybePromise } from './index'
22
26
  export {};
23
27
 
24
28
 
@@ -31,7 +35,7 @@ declare global {
31
35
  it.
32
36
  ================================================================================== ⇦✦──⇦✦──✦──✦──← 'pew pew' 🧙 [UX/DX] */
33
37
  type MaybePromise<R = any> = R;
34
- var MaybePromise: MaybePromise;
38
+ var MaybePromise: MaybePromisei;
35
39
  var B2B: typeof B2BI; // BOOLEAN BINARY
36
40
 
37
41
  var M2: typeof M2I; // map
@@ -43,6 +47,9 @@ declare global {
43
47
  var SET2: typeof SET2I; // set
44
48
  var SET2B: typeof SET2BI; // set
45
49
 
50
+ var RES2: typeof RECC2; // reg ex static
51
+ var RE2: typeof REC2; // reg ex
52
+ var ER2: typeof ER2I; // error
46
53
  var D2: typeof D2I; // Date
47
54
  var A2: typeof A2I; // Array
48
55
  var O2: typeof O2I; // Object
@@ -52,17 +59,30 @@ declare global {
52
59
  var S2: typeof S2I; // String
53
60
  var N2: typeof N2I; // Number
54
61
  var USP2: typeof USP2I; // URLSearchParams
55
- var ER2: typeof ER2I; // Error
56
62
  var U82: typeof U82I; // Uint8Array
57
63
  var I2: typeof I2I; // Iterator
58
64
  var R2: typeof R2I;
59
65
  var R2FN: typeof R2II;
66
+ var soa_codec: typeof soa_codeci;
67
+ interface soa_codec {
68
+ readonly maxPids: number;
69
+ readonly channelMap: Int32Array;
70
+ readonly subChannelMap: Int32Array;
71
+ readonly tripChannelMap: Int32Array;
72
+ readonly keyMap: Int32Array;
73
+ readonly listeners: Array<((pid: number, val?: number) => void) | undefined>;
74
+ nextPid: number;
75
+
76
+ allocatePid(rId: number, mId: number, sId: number, kId: number): number;
77
+ }
78
+ interface soa_codeci extends soa_codec {}
79
+
60
80
  // [MAP]
61
81
  // #region ══════════════════════════════════════════════════════════════════════════════════════════════════════
62
82
  type M2Op = "set" | "del" | "upd" | "dirty";
63
83
  interface M2Event<H = A, T = A> {
64
84
  op: M2Op;
65
- pid: H;
85
+ pid?: H;
66
86
  k: H;
67
87
  v?: T;
68
88
  prev?: T;
package/src/index.ts CHANGED
@@ -1,25 +1,36 @@
1
+ import { M2RI } from "./map_rows";
2
+ import { M2DI } from "./map_dense";
3
+ import { M2BINI } from "./map_bin";
4
+ import { B2BI } from "./boolean_byte";
5
+ import { M2I } from "./map";
6
+ import { M2BI } from "./map_byte";
1
7
  import { A2I } from './array'
2
- import { B2BI } from './boolean_byte'
3
8
  import { D2I, R2I, R2II } from './date'
4
9
  import { ER2I } from './error'
5
10
  import { I2I } from './iterator'
6
- import { M2BI } from './map_byte'
7
- import { M2I } from './map'
8
11
  import { N2I } from './number'
9
12
  import { O2I } from './object'
10
13
  import { P2I } from './promise'
11
14
  import { REC2, RECC2 } from './reg_ex'
12
15
  import { SET2I } from './set'
13
16
  import { SET2BI } from './set_byte'
14
- import { SOA_CODEC } from './soa_codec'
17
+ import { SOA_CODEC, soa_codeci } from './soa_codec'
15
18
  import { S2I } from './string'
16
19
  import { U82I } from './unit8array'
17
20
  import { USP2I } from './url_search_params'
18
21
  import { WM2I } from './weak_map'
19
22
  import { WS2I } from './weak_set'
23
+ export type MaybePromise<R = any> = R;
24
+ export function MaybePromisei<R = any>(v: R): MaybePromise {
25
+ return v !== undefined ? v as R : Promise.resolve(v) as Promise<R>
26
+ }
20
27
 
28
+ globalThis.MaybePromise = MaybePromisei;
21
29
 
22
30
  export {
31
+ M2RI as M2R,
32
+ M2DI as M2D,
33
+ M2BINI as M2BIN,
23
34
  A2I as A2,
24
35
  B2BI as B2B,
25
36
  D2I as D2,
@@ -30,16 +41,17 @@ export {
30
41
  N2I as N2,
31
42
  O2I as O2,
32
43
  P2I as P2,
33
- REC2 as REC,
44
+ REC2 as RE2,
45
+ RECC2 as RES2,
34
46
  SET2I as SET2,
35
47
  SET2BI as SET2B,
36
48
  SOA_CODEC ,
49
+ soa_codeci as soa_codec,
37
50
  S2I as S2,
38
51
  U82I as U82,
39
52
  USP2I as USP2,
40
53
  WM2I as WM2,
41
54
  WS2I as WS2,
42
- RECC2 as RECC,
43
55
  R2I as R2,
44
56
  R2II as R2I
45
57
  }
package/src/map_bin.ts CHANGED
@@ -95,7 +95,7 @@ export class M2BINI<K = N, V = N> {
95
95
  return this.entries();
96
96
  }
97
97
 
98
- forEach(fn: (v: V, k: K, m: Map<K, V>) => void, thisArg?: unknown): void {
98
+ forEach(fn: (v: V, k: K, m: M2BINI<K, V>) => V, thisArg?: unknown): void {
99
99
  for (let i = 0; i < this.#size; i++) fn.call(thisArg, this.#vals[i] as V, this.#slotToPid[i] as K, this);
100
100
  this.#odd?.forEach((v, k) => fn.call(thisArg, v, k as K, this));
101
101
  }
package/src/map_dense.ts CHANGED
@@ -48,7 +48,7 @@ export class M2DI<Key=A, V = number> {
48
48
  this.#vals[k] = v;
49
49
  return this;
50
50
  }
51
- (this.#odd ??= new Map()).set(k as Key, v);
51
+ (this.#odd ??= new M2<Key, V>()).set(k as Key, v);
52
52
  return this;
53
53
  }
54
54
  delete(k: number): B {
@@ -61,7 +61,7 @@ export class M2DI<Key=A, V = number> {
61
61
  }
62
62
  return this.#odd !== null && this.#odd.delete(k as Key);
63
63
  }
64
- clear(): V {
64
+ clear() {
65
65
  this.#live.fill(0);
66
66
  this.#size = 0;
67
67
  this.#odd?.clear();
@@ -101,7 +101,7 @@ export class M2DI<Key=A, V = number> {
101
101
  [Symbol.iterator](): MapIterator<[N, V]> {
102
102
  return this.entries();
103
103
  }
104
- forEach(fn: (v: V, k: N, m: M<N, V>) => V, thisArg?: U): V {
104
+ forEach(fn: (v: V, k: N, m: M<N, V>) => V, thisArg?: U) {
105
105
  const l = this.#live;
106
106
  for (let k = 0; k < l.length; k++) if (l[k] === 1) fn.call(thisArg, this.#vals[k] as V, k, this as U as Map<N, V>);
107
107
  this.#odd?.forEach((v, k) => fn.call(thisArg, v, k as N, this as U as Map<N, V>));
@@ -138,7 +138,7 @@ export class M2DI<Key=A, V = number> {
138
138
  return this.#live[pid] === 1;
139
139
  }
140
140
  /** walk live pids without allocating an iterator */
141
- forEachRaw(fn: (pid: N, value: N) => V): V {
141
+ forEachRaw(fn: (pid: N, value: N) => V) {
142
142
  const l = this.#live;
143
143
  for (let k = 0; k < l.length; k++) if (l[k] === 1) fn(k, this.#vals[k]);
144
144
  }
@@ -150,7 +150,7 @@ export class M2DI<Key=A, V = number> {
150
150
  }
151
151
  return out;
152
152
  }
153
- #grow(need: N): V {
153
+ #grow(need: N) {
154
154
  let cap = this.#live.length;
155
155
  while (cap <= need) cap *= 2;
156
156
  const v = new Float64Array(cap);
package/src/map_rows.ts CHANGED
@@ -100,7 +100,7 @@ export class M2RI<K = N> {
100
100
  [Symbol.iterator](): MapIterator<[K, F64]> {
101
101
  return this.entries();
102
102
  }
103
- forEach(fn: (v: F64, k: K, m: Map<K, F64>) => V, thisArg?: U): V {
103
+ forEach(fn: (v: F64, k: K, m: M2RI<K>) => V, thisArg?: U): V {
104
104
  for (const [k, v] of this.entries()) fn.call(thisArg, v, k, this);
105
105
  }
106
106
  forEachRaw(fn: (pid: N, slot: N) => V): V {
package/src/reg_ex.ts CHANGED
@@ -415,8 +415,8 @@ export const RECC2: RE2Static = Object.assign(
415
415
  },
416
416
  );
417
417
 
418
- (globalThis as A).REC2 = REC2;
419
- (globalThis as A).RE2 = RECC2;
418
+ (globalThis as A).RE2 = REC2;
419
+ (globalThis as A).RES2 = RECC2;
420
420
 
421
421
  /* ====================================================================================================
422
422
 
package/src/soa_codec.ts CHANGED
@@ -7,7 +7,7 @@ export class SOA_CODEC {// HIGH_PERFORMANCE_SOA_CODEC
7
7
  public readonly keyMap: Int32Array;
8
8
  public readonly listeners: Array<((pid: number, val?: number) => void) | undefined>;
9
9
  public nextPid = 1;
10
- constructor( maxPids = 8192) {
10
+ constructor( maxPids = 8192 * 2) {
11
11
  this.maxPids = maxPids;
12
12
  this.channelMap = new Int32Array(maxPids);
13
13
  this.subChannelMap = new Int32Array(maxPids);
@@ -25,3 +25,6 @@ export class SOA_CODEC {// HIGH_PERFORMANCE_SOA_CODEC
25
25
  return pid;
26
26
  }
27
27
  }
28
+
29
+ export const soa_codeci = new SOA_CODEC()
30
+ globalThis.soa_codec = soa_codeci