@thi.ng/arrays 2.9.5 → 2.9.7

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-04-23T07:02:17Z
3
+ - **Last updated**: 2024-06-21T19:34:38Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,13 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [2.9.7](https://github.com/thi-ng/umbrella/tree/@thi.ng/arrays@2.9.7) (2024-06-21)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - rename various rest args to be more semantically meaningful ([8088a56](https://github.com/thi-ng/umbrella/commit/8088a56))
17
+ - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
18
+
12
19
  ### [2.9.4](https://github.com/thi-ng/umbrella/tree/@thi.ng/arrays@2.9.4) (2024-04-20)
13
20
 
14
21
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 193 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -60,7 +60,7 @@ For Node.js REPL:
60
60
  const arr = await import("@thi.ng/arrays");
61
61
  ```
62
62
 
63
- Package sizes (brotli'd, pre-treeshake): ESM: 2.99 KB
63
+ Package sizes (brotli'd, pre-treeshake): ESM: 3.00 KB
64
64
 
65
65
  ## Dependencies
66
66
 
package/blit.js CHANGED
@@ -1,7 +1,6 @@
1
1
  function blit1d(dest, x, src, mask) {
2
2
  const [sx, sw, dx, dw] = __clip(0, src.length, x, dest.length);
3
- if (sw < 1 || dx >= dw)
4
- return dest;
3
+ if (sw < 1 || dx >= dw) return dest;
5
4
  for (let i = 0; i < sw; i++) {
6
5
  const val = src[sx + i];
7
6
  val !== mask && (dest[dx + i] = val);
@@ -10,8 +9,7 @@ function blit1d(dest, x, src, mask) {
10
9
  }
11
10
  function blitPred1d(dest, x, src, pred) {
12
11
  const [sx, sw, dx, dw] = __clip(0, src.length, x, dest.length);
13
- if (sw < 1 || dx >= dw)
14
- return dest;
12
+ if (sw < 1 || dx >= dw) return dest;
15
13
  for (let i = 0; i < sw; i++) {
16
14
  const val = pred(src[sx + i], dest[dx + i], sx + i);
17
15
  val !== void 0 && (dest[dx + i] = val);
@@ -21,8 +19,7 @@ function blitPred1d(dest, x, src, pred) {
21
19
  function blit2d(dest, dpos, dsize, src, ssize, mask) {
22
20
  const [sx, sw, dx, dw] = __clip(0, ssize[0], dpos[0], dsize[0]);
23
21
  const [sy, sh, dy, dh] = __clip(0, ssize[1], dpos[1], dsize[1]);
24
- if (sw < 1 || sh < 1 || dx >= dw || dy >= dh)
25
- return dest;
22
+ if (sw < 1 || sh < 1 || dx >= dw || dy >= dh) return dest;
26
23
  const sstride = ssize[0];
27
24
  const dstride = dsize[0];
28
25
  for (let y = 0; y < sh; y++) {
package/ends-with.js CHANGED
@@ -2,8 +2,7 @@ import { equiv as _eq } from "@thi.ng/equiv";
2
2
  const endsWith = (buf, needle, equiv = _eq) => {
3
3
  let i = buf.length;
4
4
  let j = needle.length;
5
- if (i < j)
6
- return false;
5
+ if (i < j) return false;
7
6
  while (--i, j-- > 0 && equiv(buf[i], needle[j])) {
8
7
  }
9
8
  return j < 0;
package/fill-range.js CHANGED
@@ -1,10 +1,8 @@
1
1
  const fillRange = (buf, index = 0, start = 0, end = buf.length, step = end > start ? 1 : -1) => {
2
2
  if (step > 0) {
3
- for (; start < end; start += step)
4
- buf[index++] = start;
3
+ for (; start < end; start += step) buf[index++] = start;
5
4
  } else {
6
- for (; start > end; start += step)
7
- buf[index++] = start;
5
+ for (; start > end; start += step) buf[index++] = start;
8
6
  }
9
7
  return buf;
10
8
  };
package/find-sequence.js CHANGED
@@ -2,12 +2,10 @@ function findSequence(buf, needle, start = 0) {
2
2
  const m = buf.length;
3
3
  const n = needle.length;
4
4
  const max = m - n;
5
- if (max < 0)
6
- return -1;
5
+ if (max < 0) return -1;
7
6
  while (start < m) {
8
7
  const idx = buf.indexOf(needle[0], start);
9
- if (idx < 0 || idx > max)
10
- return -1;
8
+ if (idx < 0 || idx > max) return -1;
11
9
  let j = n;
12
10
  while (j-- > 1) {
13
11
  if (buf[idx + j] !== needle[j]) {
@@ -15,8 +13,7 @@ function findSequence(buf, needle, start = 0) {
15
13
  break;
16
14
  }
17
15
  }
18
- if (j === 0)
19
- return idx;
16
+ if (j === 0) return idx;
20
17
  }
21
18
  return -1;
22
19
  }
package/find.js CHANGED
@@ -5,8 +5,7 @@ const find = (buf, x, equiv = _equiv) => {
5
5
  };
6
6
  const findIndex = (buf, x, equiv = _equiv) => {
7
7
  for (let i = buf.length; i-- > 0; ) {
8
- if (equiv(x, buf[i]))
9
- return i;
8
+ if (equiv(x, buf[i])) return i;
10
9
  }
11
10
  return -1;
12
11
  };
package/floyd-rivest.js CHANGED
@@ -20,16 +20,13 @@ function floydRivest(buf, k = 1, cmp = compare, left = 0, right = buf.length - 1
20
20
  let i = left;
21
21
  let j = right;
22
22
  swap(buf, left, k);
23
- if (cmp(buf[right], t) > 0)
24
- swap(buf, right, left);
23
+ if (cmp(buf[right], t) > 0) swap(buf, right, left);
25
24
  while (i < j) {
26
25
  swap(buf, i, j);
27
26
  i++;
28
27
  j--;
29
- while (compare(buf[i], t) < 0)
30
- i++;
31
- while (compare(buf[j], t) > 0)
32
- j--;
28
+ while (compare(buf[i], t) < 0) i++;
29
+ while (compare(buf[j], t) > 0) j--;
33
30
  }
34
31
  if (compare(buf[left], t) === 0) {
35
32
  swap(buf, left, j);
@@ -37,10 +34,8 @@ function floydRivest(buf, k = 1, cmp = compare, left = 0, right = buf.length - 1
37
34
  j++;
38
35
  swap(buf, j, right);
39
36
  }
40
- if (j <= k)
41
- left = j + 1;
42
- if (k <= j)
43
- right = j - 1;
37
+ if (j <= k) left = j + 1;
38
+ if (k <= j) right = j - 1;
44
39
  }
45
40
  return buf;
46
41
  }
package/fuzzy-match.js CHANGED
@@ -8,16 +8,15 @@ const fuzzyMatch = (domain, query, equiv = _eq) => {
8
8
  if (nq === nd) {
9
9
  return equiv(query, domain);
10
10
  }
11
- next:
12
- for (let i = 0, j = 0; i < nq; i++) {
13
- const q = query[i];
14
- while (j < nd) {
15
- if (equiv(domain[j++], q)) {
16
- continue next;
17
- }
11
+ next: for (let i = 0, j = 0; i < nq; i++) {
12
+ const q = query[i];
13
+ while (j < nd) {
14
+ if (equiv(domain[j++], q)) {
15
+ continue next;
18
16
  }
19
- return false;
20
17
  }
18
+ return false;
19
+ }
21
20
  return true;
22
21
  };
23
22
  export {
package/insert.js CHANGED
@@ -1,8 +1,7 @@
1
1
  const insert = (buf, x, i, k = Infinity) => i < 0 || i >= k || k < 1 ? buf : insertUnsafe(buf, x, i, k);
2
2
  const insertUnsafe = (buf, x, i, k = Infinity) => {
3
3
  let j = buf.length < k ? buf.length + 1 : k;
4
- for (; --j > i; )
5
- buf[j] = buf[j - 1];
4
+ for (; --j > i; ) buf[j] = buf[j - 1];
6
5
  buf[i] = x;
7
6
  return buf;
8
7
  };
package/into.js CHANGED
@@ -1,7 +1,6 @@
1
1
  const into = (dest, src, max = Infinity) => {
2
2
  for (let x of src) {
3
- if (--max < 0)
4
- break;
3
+ if (--max < 0) break;
5
4
  dest.push(x);
6
5
  }
7
6
  return dest;
package/is-sorted.js CHANGED
@@ -3,8 +3,7 @@ const isSorted = (arr, cmp = compare, start = 0, end = arr.length) => {
3
3
  let prev = arr[start];
4
4
  while (++start < end) {
5
5
  const curr = arr[start];
6
- if (cmp(prev, curr) > 0)
7
- return false;
6
+ if (cmp(prev, curr) > 0) return false;
8
7
  prev = curr;
9
8
  }
10
9
  return true;
package/iterator.js CHANGED
@@ -1,6 +1,5 @@
1
1
  function* arrayIterator(buf, start = 0, end) {
2
- if (!buf)
3
- return;
2
+ if (!buf) return;
4
3
  end === void 0 && (end = buf.length);
5
4
  const step = start <= end ? 1 : -1;
6
5
  for (; start !== end; start += step) {
package/levenshtein.js CHANGED
@@ -1,5 +1,5 @@
1
- const eqStrict = (a, b) => a === b;
2
- const levenshtein = (a, b, maxDist = Infinity, equiv = eqStrict) => {
1
+ const __eqStrict = (a, b) => a === b;
2
+ const levenshtein = (a, b, maxDist = Infinity, equiv = __eqStrict) => {
3
3
  if (a === b) {
4
4
  return 0;
5
5
  }
@@ -67,8 +67,7 @@ const levenshtein = (a, b, maxDist = Infinity, equiv = eqStrict) => {
67
67
  d1 = d0;
68
68
  d0 = dy;
69
69
  }
70
- if (minDist > maxDist)
71
- return Infinity;
70
+ if (minDist > maxDist) return Infinity;
72
71
  }
73
72
  for (; x < lb; ) {
74
73
  bx0 = b[offset + (d0 = x)];
@@ -80,12 +79,11 @@ const levenshtein = (a, b, maxDist = Infinity, equiv = eqStrict) => {
80
79
  dd < minDist && (minDist = dd);
81
80
  d0 = dy;
82
81
  }
83
- if (minDist > maxDist)
84
- return Infinity;
82
+ if (minDist > maxDist) return Infinity;
85
83
  }
86
84
  return dd;
87
85
  };
88
- const normalizedLevenshtein = (a, b, maxDist = Infinity, equiv = eqStrict) => {
86
+ const normalizedLevenshtein = (a, b, maxDist = Infinity, equiv = __eqStrict) => {
89
87
  const n = Math.max(a.length, b.length);
90
88
  return n > 0 ? levenshtein(a, b, maxDist, equiv) / n : 0;
91
89
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/arrays",
3
- "version": "2.9.5",
3
+ "version": "2.9.7",
4
4
  "description": "Array / Arraylike utilities",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/arrays#readme",
13
+ "homepage": "https://thi.ng/arrays",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -36,18 +36,18 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.11.1",
40
- "@thi.ng/checks": "^3.6.3",
41
- "@thi.ng/compare": "^2.3.4",
42
- "@thi.ng/equiv": "^2.1.57",
43
- "@thi.ng/errors": "^2.5.6",
44
- "@thi.ng/random": "^3.7.5"
39
+ "@thi.ng/api": "^8.11.3",
40
+ "@thi.ng/checks": "^3.6.5",
41
+ "@thi.ng/compare": "^2.3.6",
42
+ "@thi.ng/equiv": "^2.1.59",
43
+ "@thi.ng/errors": "^2.5.8",
44
+ "@thi.ng/random": "^3.8.1"
45
45
  },
46
46
  "devDependencies": {
47
- "@microsoft/api-extractor": "^7.43.0",
48
- "esbuild": "^0.20.2",
49
- "typedoc": "^0.25.12",
50
- "typescript": "^5.4.3"
47
+ "@microsoft/api-extractor": "^7.47.0",
48
+ "esbuild": "^0.21.5",
49
+ "typedoc": "^0.25.13",
50
+ "typescript": "^5.5.2"
51
51
  },
52
52
  "keywords": [
53
53
  "aos",
@@ -168,5 +168,5 @@
168
168
  "thi.ng": {
169
169
  "year": 2018
170
170
  },
171
- "gitHead": "5dd66c18a3862a3af69a5b2f49563f7cbdd960c2\n"
171
+ "gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
172
172
  }
package/quicksort.js CHANGED
@@ -12,8 +12,7 @@ function quickSort(arr, _cmp = compare, _swap = swap, start = 0, end = arr.lengt
12
12
  do {
13
13
  e--;
14
14
  } while (_cmp(arr[e], pivot) > 0);
15
- if (s >= e)
16
- break;
15
+ if (s >= e) break;
17
16
  _swap(arr, s, e);
18
17
  }
19
18
  quickSort(arr, _cmp, _swap, start, e);
package/rotate.js CHANGED
@@ -1,6 +1,5 @@
1
1
  const rotate = (buf, num) => {
2
- if (!(num = __distance(buf, num)))
3
- return buf;
2
+ if (!(num = __distance(buf, num))) return buf;
4
3
  if (num < 0) {
5
4
  buf.push(...buf.splice(0, -num));
6
5
  } else {
@@ -9,8 +8,7 @@ const rotate = (buf, num) => {
9
8
  return buf;
10
9
  };
11
10
  const rotateTyped = (buf, num) => {
12
- if (!(num = __distance(buf, num)))
13
- return buf;
11
+ if (!(num = __distance(buf, num))) return buf;
14
12
  if (num < 0) {
15
13
  const tmp = buf.slice(0, -num);
16
14
  buf.copyWithin(0, -num);
package/starts-with.js CHANGED
@@ -2,8 +2,7 @@ import { equiv as _eq } from "@thi.ng/equiv";
2
2
  const startsWith = (buf, needle, equiv = _eq) => {
3
3
  let i = buf.length;
4
4
  let j = needle.length;
5
- if (i < j)
6
- return false;
5
+ if (i < j) return false;
7
6
  while (-j >= 0 && equiv(buf[j], needle[j])) {
8
7
  }
9
8
  return j < 0;
package/swap.d.ts CHANGED
@@ -41,7 +41,7 @@ export declare const swap: (arr: AnyArray, x: number, y: number) => void;
41
41
  * // [30, 40]
42
42
  * ```
43
43
  *
44
- * @param xs - arrays to swap in later
44
+ * @param arrays - arrays to swap in later
45
45
  */
46
- export declare const multiSwap: (...xs: AnyArray[]) => SwapFn;
46
+ export declare const multiSwap: (...arrays: AnyArray[]) => SwapFn;
47
47
  //# sourceMappingURL=swap.d.ts.map
package/swap.js CHANGED
@@ -3,9 +3,9 @@ const swap = (arr, x, y) => {
3
3
  arr[x] = arr[y];
4
4
  arr[y] = t;
5
5
  };
6
- const multiSwap = (...xs) => {
7
- const [b, c, d] = xs;
8
- const n = xs.length;
6
+ const multiSwap = (...arrays) => {
7
+ const [b, c, d] = arrays;
8
+ const n = arrays.length;
9
9
  switch (n) {
10
10
  case 0:
11
11
  return swap;
@@ -30,8 +30,7 @@ const multiSwap = (...xs) => {
30
30
  default:
31
31
  return (a, x, y) => {
32
32
  swap(a, x, y);
33
- for (let i = n; i-- > 0; )
34
- swap(xs[i], x, y);
33
+ for (let i = n; i-- > 0; ) swap(arrays[i], x, y);
35
34
  };
36
35
  }
37
36
  };
package/topo-sort.js CHANGED
@@ -3,20 +3,16 @@ const topoSort = (nodes, deps) => {
3
3
  const cycles = {};
4
4
  const topology = [];
5
5
  const sort = (id, path) => {
6
- if (cycles[id])
7
- illegalState(`dependency cycle: ${path.join(" -> ")}`);
6
+ if (cycles[id]) illegalState(`dependency cycle: ${path.join(" -> ")}`);
8
7
  cycles[id] = true;
9
8
  const nodeDeps = deps(nodes[id]);
10
9
  if (nodeDeps) {
11
- for (let d of nodeDeps)
12
- sort(d, [...path, d]);
10
+ for (let d of nodeDeps) sort(d, [...path, d]);
13
11
  }
14
12
  cycles[id] = false;
15
- if (!topology.includes(id))
16
- topology.push(id);
13
+ if (!topology.includes(id)) topology.push(id);
17
14
  };
18
- for (let id in nodes)
19
- sort(id, [id]);
15
+ for (let id in nodes) sort(id, [id]);
20
16
  return topology;
21
17
  };
22
18
  export {