@isopodlabs/utilities 1.7.0 → 1.8.0

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/dist/array.d.ts CHANGED
@@ -4,3 +4,4 @@ export declare function equal<T>(arr1: T[], arr2: T[]): boolean;
4
4
  export declare function reverse<T>(array: T[], start: number, end: number): void;
5
5
  export declare function rotate<T>(array: T[], start: number, end: number, shift: number): void;
6
6
  export declare function make<T>(n: number, constructor: new () => T): T[];
7
+ export declare function lazySlice<T>(array: T[], start?: number, end?: number): Generator<T>;
package/dist/array.js CHANGED
@@ -6,6 +6,7 @@ exports.equal = equal;
6
6
  exports.reverse = reverse;
7
7
  exports.rotate = rotate;
8
8
  exports.make = make;
9
+ exports.lazySlice = lazySlice;
9
10
  const object_1 = require("./object");
10
11
  //-----------------------------------------------------------------------------
11
12
  // array
@@ -55,3 +56,20 @@ function rotate(array, start, end, shift) {
55
56
  function make(n, constructor) {
56
57
  return Array.from({ length: n }, () => new constructor);
57
58
  }
59
+ function* lazySlice(array, start, end) {
60
+ const len = array.length;
61
+ if (start === undefined)
62
+ start = 0;
63
+ else if (start < 0)
64
+ start = Math.max(len + start, 0);
65
+ else
66
+ start = Math.min(start, len);
67
+ if (end === undefined)
68
+ end = len;
69
+ else if (end < 0)
70
+ end = Math.max(len + start, 0);
71
+ else
72
+ end = Math.min(end, len);
73
+ for (let i = start; i < end; i++)
74
+ yield array[i];
75
+ }
package/dist/bits.d.ts CHANGED
@@ -126,13 +126,14 @@ export declare class DenseBits32 implements BitSet {
126
126
  selfDifference(other: DenseBits32): this;
127
127
  clean(): this;
128
128
  }
129
- type SparseNumberArray = number[] | Record<number, number>;
129
+ type sparsebits = Record<number, number>;
130
+ type SparseNumberArray = number[] | sparsebits;
130
131
  type ExtraParams<T> = T extends new (bits: SparseNumberArray, ...args: infer P) => any ? P : never;
131
132
  export declare class SparseBits implements BitSet {
132
- protected bits: number[];
133
+ protected bits: sparsebits;
133
134
  constructor(bits?: SparseNumberArray);
134
135
  protected create(bits?: SparseNumberArray): this;
135
- static fromEntries<C extends new (bits: SparseNumberArray, ...args: any[]) => any>(this: C, entries: Record<number, number> | [number, number][], ...extra: ExtraParams<C>): InstanceType<C>;
136
+ static fromEntries<C extends new (bits: SparseNumberArray, ...args: any[]) => any>(this: C, entries: sparsebits | [number, number][], ...extra: ExtraParams<C>): InstanceType<C>;
136
137
  static fromIndices<C extends new (bits: SparseNumberArray, ...args: any[]) => any>(this: C, ...indices: number[]): InstanceType<C>;
137
138
  static fromIndices<C extends new (bits: SparseNumberArray, ...args: any[]) => any>(this: C, indices: number[], ...extra: ExtraParams<C>): InstanceType<C>;
138
139
  copy(): this;
package/dist/bits.js CHANGED
@@ -28,7 +28,7 @@ function highestSet32(x) {
28
28
  return x ? 32 - Math.clz32(x) : 0;
29
29
  }
30
30
  function highestSet1024(x) {
31
- let b = Math.floor(Math.log2(x));
31
+ const b = Math.floor(Math.log2(x));
32
32
  return 1n << BigInt(b) <= x ? b + 1 : b;
33
33
  }
34
34
  // Returns the number of set bits
@@ -42,7 +42,7 @@ function nthSet32(x, i) {
42
42
  let b2 = x - ((x >> 1) & 0x55555555);
43
43
  let b4 = (b2 & 0x33333333) + ((b2 >> 2) & 0x33333333);
44
44
  let b8 = (b4 + (b4 >> 4) & 0xF0F0F0F);
45
- let b16 = (b8 + (b8 >> 8)) & 0xff;
45
+ const b16 = (b8 + (b8 >> 8)) & 0xff;
46
46
  let n = 0;
47
47
  if (i >= b16) {
48
48
  i -= b16;
@@ -702,11 +702,8 @@ class DenseBits32 {
702
702
  }
703
703
  exports.DenseBits32 = DenseBits32;
704
704
  ;
705
- //-----------------------------------------------------------------------------
706
- // SparseBits - a sparse bitset where each entry in the 'bits' array represents 32 bits
707
- //-----------------------------------------------------------------------------
708
705
  function sparseFromIndices(indices) {
709
- const bits = [];
706
+ const bits = {};
710
707
  for (const i of indices)
711
708
  bits[i >> 5] |= 1 << (i & 0x1f);
712
709
  return bits;
@@ -747,7 +744,8 @@ function sparseClearMask(bits, i, m, undef = 0) {
747
744
  bits[i] = ~m;
748
745
  }
749
746
  function sparseSetRange(bits, a, b, undef = 0) {
750
- let i = a >> 5, j = b >> 5;
747
+ let i = a >> 5;
748
+ const j = b >> 5;
751
749
  if (i === j) {
752
750
  sparseSetMask(bits, i, (1 << (b & 0x1f)) - (1 << (a & 0x1f)), undef);
753
751
  }
@@ -765,7 +763,8 @@ function sparseSetRange(bits, a, b, undef = 0) {
765
763
  }
766
764
  }
767
765
  function sparseClearRange(bits, a, b, undef = 0) {
768
- let i = a >> 5, j = b >> 5;
766
+ let i = a >> 5;
767
+ const j = b >> 5;
769
768
  if (i === j) {
770
769
  sparseClearMask(bits, i, (1 << (b & 0x1f)) - (1 << (a & 0x1f)), undef);
771
770
  }
@@ -816,41 +815,40 @@ function sparseNthSet(bits, a, undef = 0) {
816
815
  return -1;
817
816
  }
818
817
  function sparseComplement(bits) {
819
- return bits.map(b => ~b);
818
+ const result = [];
819
+ for (const i in bits)
820
+ result[i] = ~bits[i];
821
+ return result;
820
822
  }
821
823
  function sparseIntersect(bits, other) {
822
824
  const result = [];
823
825
  for (const i in bits) {
824
- if (other[i] !== undefined) {
826
+ if (other[i] !== undefined)
825
827
  result[i] = bits[i] & other[i];
826
- }
827
828
  }
828
829
  return result;
829
830
  }
830
831
  function sparseUnion(bits, other) {
831
832
  const result = [];
832
833
  for (const i in bits) {
833
- if (other[i] !== undefined) {
834
+ if (other[i] !== undefined)
834
835
  result[i] = bits[i] | other[i];
835
- }
836
836
  }
837
837
  return result;
838
838
  }
839
839
  function sparseXor(bits, other) {
840
840
  const result = [];
841
841
  for (const i in bits) {
842
- if (other[i] !== undefined) {
842
+ if (other[i] !== undefined)
843
843
  result[i] = bits[i] ^ other[i];
844
- }
845
844
  }
846
845
  return result;
847
846
  }
848
847
  function sparseDifference(bits, other) {
849
848
  const result = [];
850
849
  for (const i in bits) {
851
- if (other[i] !== undefined) {
850
+ if (other[i] !== undefined)
852
851
  result[i] = bits[i] & ~other[i];
853
- }
854
852
  }
855
853
  return result;
856
854
  }
@@ -975,7 +973,7 @@ function* sparseWhere(bits, set, from = -1, to, undef = 0) {
975
973
  }
976
974
  function* sparseRanges(bits, set, undef = 0) {
977
975
  let start = -1, end = 0;
978
- let other = undef ? set : !set;
976
+ const other = undef ? set : !set;
979
977
  for (const i in bits) {
980
978
  let b = bits[i] ^ undef;
981
979
  const c0 = +i * 32;
@@ -1013,13 +1011,15 @@ function sparseSlice(bits, from, to) {
1013
1011
  for (const k in bits) {
1014
1012
  const i = +k;
1015
1013
  if (i >= from32) {
1016
- if (i > to32)
1017
- break;
1018
1014
  let b = bits[k];
1019
1015
  if (i === from32)
1020
1016
  b &= -fromM;
1021
- if (i === to32)
1017
+ if (i === to32) {
1022
1018
  b &= toM - 1;
1019
+ if (b !== 0)
1020
+ result[k] = b;
1021
+ break;
1022
+ }
1023
1023
  if (b !== 0)
1024
1024
  result[k] = b;
1025
1025
  }
@@ -1029,7 +1029,7 @@ function sparseSlice(bits, from, to) {
1029
1029
  class SparseBits {
1030
1030
  bits;
1031
1031
  constructor(bits = []) {
1032
- this.bits = bits;
1032
+ this.bits = bits; // as Record<number, number>;
1033
1033
  }
1034
1034
  create(bits = []) {
1035
1035
  return new this.constructor(bits);
package/dist/object.d.ts CHANGED
@@ -11,7 +11,7 @@ export declare class Lazy<T> {
11
11
  private _value;
12
12
  constructor(factory: () => T);
13
13
  get value(): T;
14
- then<U>(this: T extends Promise<infer R> ? Lazy<T> : never, onFulfilled: (value: T extends Promise<infer R> ? R : never) => U): Promise<U>;
14
+ then<U>(this: T extends Promise<infer _R> ? Lazy<T> : never, onFulfilled: (value: T extends Promise<infer R> ? R : never) => U): Promise<U>;
15
15
  }
16
16
  export declare class CallCombiner0 {
17
17
  private timeout?;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isopodlabs/utilities",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "Various typescript helpers.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,8 @@
16
16
  "README.md"
17
17
  ],
18
18
  "scripts": {
19
- "build": "tsc"
19
+ "build": "tsc",
20
+ "lint": "eslint \"src/**/*.ts\""
20
21
  },
21
22
  "keywords": [
22
23
  "typescript",
@@ -29,7 +30,6 @@
29
30
  "devDependencies": {
30
31
  "@types/node": "^22.13.8",
31
32
  "eslint": "^9.21.0",
32
- "typescript": "^5.8.2",
33
33
  "typescript-eslint": "^8.26.0"
34
34
  }
35
35
  }