@isopodlabs/utilities 1.7.1 → 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.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;
@@ -744,7 +744,8 @@ function sparseClearMask(bits, i, m, undef = 0) {
744
744
  bits[i] = ~m;
745
745
  }
746
746
  function sparseSetRange(bits, a, b, undef = 0) {
747
- let i = a >> 5, j = b >> 5;
747
+ let i = a >> 5;
748
+ const j = b >> 5;
748
749
  if (i === j) {
749
750
  sparseSetMask(bits, i, (1 << (b & 0x1f)) - (1 << (a & 0x1f)), undef);
750
751
  }
@@ -762,7 +763,8 @@ function sparseSetRange(bits, a, b, undef = 0) {
762
763
  }
763
764
  }
764
765
  function sparseClearRange(bits, a, b, undef = 0) {
765
- let i = a >> 5, j = b >> 5;
766
+ let i = a >> 5;
767
+ const j = b >> 5;
766
768
  if (i === j) {
767
769
  sparseClearMask(bits, i, (1 << (b & 0x1f)) - (1 << (a & 0x1f)), undef);
768
770
  }
@@ -821,36 +823,32 @@ function sparseComplement(bits) {
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;
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.1",
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
  }