@vielzeug/arsenal 26.11.5 → 26.11.6

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.
Files changed (141) hide show
  1. package/README.md +6 -1
  2. package/dist/_common/_lruMap.js +1 -2
  3. package/dist/_common/_selectorSet.js +1 -2
  4. package/dist/_common/unsafePaths.js +1 -2
  5. package/dist/_dev.js +1 -2
  6. package/dist/array/chunk.js +1 -2
  7. package/dist/array/compact.js +1 -2
  8. package/dist/array/compare.js +1 -2
  9. package/dist/array/compareBy.js +1 -2
  10. package/dist/array/contains.js +1 -2
  11. package/dist/array/countBy.js +1 -2
  12. package/dist/array/difference.js +1 -2
  13. package/dist/array/drop.js +1 -2
  14. package/dist/array/dropLast.js +1 -2
  15. package/dist/array/filterMap.js +1 -2
  16. package/dist/array/first.js +1 -2
  17. package/dist/array/groupBy.js +1 -2
  18. package/dist/array/indexBy.js +1 -2
  19. package/dist/array/intersection.js +1 -2
  20. package/dist/array/last.js +1 -2
  21. package/dist/array/paginate.js +1 -2
  22. package/dist/array/partition.js +1 -2
  23. package/dist/array/replace.js +1 -2
  24. package/dist/array/rotate.js +1 -2
  25. package/dist/array/search.js +1 -2
  26. package/dist/array/sort.cjs +1 -1
  27. package/dist/array/sort.cjs.map +1 -1
  28. package/dist/array/sort.js +11 -12
  29. package/dist/array/take.js +1 -2
  30. package/dist/array/takeLast.js +1 -2
  31. package/dist/array/toggle.js +1 -2
  32. package/dist/array/union.js +1 -2
  33. package/dist/array/uniq.js +1 -2
  34. package/dist/array/unzip.js +1 -2
  35. package/dist/array/zip.js +1 -2
  36. package/dist/arsenal.js +47 -94
  37. package/dist/arsenal.js.map +1 -1
  38. package/dist/async/abortError.js +1 -2
  39. package/dist/async/abortable.js +1 -2
  40. package/dist/async/attempt.js +1 -2
  41. package/dist/async/backoff.js +1 -2
  42. package/dist/async/index.cjs +1 -1
  43. package/dist/async/index.js +5 -5
  44. package/dist/async/parallel.js +1 -2
  45. package/dist/async/retry.js +1 -2
  46. package/dist/async/sleep.js +1 -2
  47. package/dist/async/taskPool.js +1 -2
  48. package/dist/async/waitFor.js +1 -2
  49. package/dist/cache/cache.js +1 -2
  50. package/dist/cache/memo.js +1 -2
  51. package/dist/encoding/base64url.js +1 -2
  52. package/dist/encoding/compression.js +1 -2
  53. package/dist/encoding/share-code.js +1 -2
  54. package/dist/errors.js +1 -2
  55. package/dist/function/assert.js +1 -2
  56. package/dist/function/debounce.js +1 -2
  57. package/dist/function/once.js +1 -2
  58. package/dist/function/pipe.js +1 -2
  59. package/dist/function/runAll.js +1 -2
  60. package/dist/function/tap.js +1 -2
  61. package/dist/function/tapper.js +1 -2
  62. package/dist/function/throttle.js +1 -2
  63. package/dist/guards/combinators.js +1 -2
  64. package/dist/guards/index.cjs +1 -1
  65. package/dist/guards/index.js +13 -13
  66. package/dist/guards/isAbortError.js +1 -2
  67. package/dist/guards/isDate.js +1 -2
  68. package/dist/guards/isDefined.js +1 -2
  69. package/dist/guards/isEmpty.js +1 -2
  70. package/dist/guards/isEqual.js +1 -2
  71. package/dist/guards/isError.js +1 -2
  72. package/dist/guards/isFunction.js +1 -2
  73. package/dist/guards/isMatch.js +1 -2
  74. package/dist/guards/isNil.js +1 -2
  75. package/dist/guards/isNumber.js +1 -2
  76. package/dist/guards/isPlainObject.js +1 -2
  77. package/dist/guards/isPrimitive.js +1 -2
  78. package/dist/guards/isPromise.js +1 -2
  79. package/dist/guards/isRegex.js +1 -2
  80. package/dist/guards/shallowEqual.js +1 -2
  81. package/dist/index.cjs +1 -1
  82. package/dist/index.js +39 -39
  83. package/dist/math/allocate.js +1 -2
  84. package/dist/math/average.js +1 -2
  85. package/dist/math/clamp.js +1 -2
  86. package/dist/math/gcd.js +1 -2
  87. package/dist/math/index.cjs +1 -1
  88. package/dist/math/index.js +15 -15
  89. package/dist/math/lcm.js +1 -2
  90. package/dist/math/lerp.js +1 -2
  91. package/dist/math/linspace.js +1 -2
  92. package/dist/math/median.js +1 -2
  93. package/dist/math/mod.js +1 -2
  94. package/dist/math/normalize.js +1 -2
  95. package/dist/math/range.js +1 -2
  96. package/dist/math/round.js +1 -2
  97. package/dist/math/standardDeviation.js +1 -2
  98. package/dist/math/sum.js +1 -2
  99. package/dist/math/variance.js +1 -2
  100. package/dist/object/defaults.js +1 -2
  101. package/dist/object/diff.cjs +1 -1
  102. package/dist/object/diff.cjs.map +1 -1
  103. package/dist/object/diff.js +12 -13
  104. package/dist/object/filterValues.js +1 -2
  105. package/dist/object/flattenPaths.js +1 -2
  106. package/dist/object/getPath.js +1 -2
  107. package/dist/object/hash.js +1 -2
  108. package/dist/object/index.cjs +1 -1
  109. package/dist/object/index.js +13 -13
  110. package/dist/object/invert.js +1 -2
  111. package/dist/object/mapKeys.js +1 -2
  112. package/dist/object/mapValues.js +1 -2
  113. package/dist/object/merge.js +1 -2
  114. package/dist/object/omit.js +1 -2
  115. package/dist/object/pick.js +1 -2
  116. package/dist/object/prune.cjs +1 -1
  117. package/dist/object/prune.cjs.map +1 -1
  118. package/dist/object/prune.js +8 -9
  119. package/dist/object/tryParseJson.js +1 -2
  120. package/dist/random/_index.js +1 -2
  121. package/dist/random/draw.js +1 -2
  122. package/dist/random/index.cjs +1 -1
  123. package/dist/random/index.js +5 -5
  124. package/dist/random/random.js +1 -2
  125. package/dist/random/shuffle.js +1 -2
  126. package/dist/random/source.js +1 -2
  127. package/dist/string/_caseUtils.js +1 -2
  128. package/dist/string/camelCase.js +1 -2
  129. package/dist/string/escape.js +1 -2
  130. package/dist/string/index.cjs +1 -1
  131. package/dist/string/index.js +11 -11
  132. package/dist/string/kebabCase.js +1 -2
  133. package/dist/string/padCenter.js +1 -2
  134. package/dist/string/pascalCase.js +1 -2
  135. package/dist/string/similarity.js +1 -2
  136. package/dist/string/snakeCase.js +1 -2
  137. package/dist/string/titleCase.js +1 -2
  138. package/dist/string/truncate.js +1 -2
  139. package/dist/string/unescape.js +1 -2
  140. package/dist/string/words.js +1 -2
  141. package/package.json +9 -9
package/README.md CHANGED
@@ -30,7 +30,12 @@ const responses = cache<string, unknown>({ ttlMs: 60_000 });
30
30
  const profile = await responses.getOrLoad('/profile', () => fetch('/profile').then((response) => response.json()));
31
31
  const cachedResponses = responses.entries();
32
32
 
33
- console.log(groupBy(matches, (user) => user.name), data, profile, cachedResponses);
33
+ console.log(
34
+ groupBy(matches, (user) => user.name),
35
+ data,
36
+ profile,
37
+ cachedResponses,
38
+ );
34
39
  pool.dispose();
35
40
  ```
36
41
 
@@ -1,4 +1,4 @@
1
- //#region src/_common/_lruMap.ts
1
+ // src/_common/_lruMap.ts
2
2
  var LruMap = class extends Map {
3
3
  maxSize;
4
4
  constructor(e) {
@@ -12,7 +12,6 @@ var LruMap = class extends Map {
12
12
  return !1;
13
13
  }
14
14
  };
15
- //#endregion
16
15
  export { LruMap };
17
16
 
18
17
  //# sourceMappingURL=_lruMap.js.map
@@ -1,4 +1,4 @@
1
- //#region src/_common/_selectorSet.ts
1
+ // src/_common/_selectorSet.ts
2
2
  function toSelectorSet(e, t) {
3
3
  return new Set(e.map((e) => t(e)));
4
4
  }
@@ -10,7 +10,6 @@ function dedupeBySelector(e, t) {
10
10
  }
11
11
  return r;
12
12
  }
13
- //#endregion
14
13
  export { dedupeBySelector, toSelectorSet };
15
14
 
16
15
  //# sourceMappingURL=_selectorSet.js.map
@@ -1,4 +1,4 @@
1
- //#region src/_common/unsafePaths.ts
1
+ // src/_common/unsafePaths.ts
2
2
  var e = /* @__PURE__ */ new Set([
3
3
  "__proto__",
4
4
  "constructor",
@@ -7,7 +7,6 @@ var e = /* @__PURE__ */ new Set([
7
7
  function isUnsafeKey(t) {
8
8
  return typeof t == "string" && e.has(t);
9
9
  }
10
- //#endregion
11
10
  export { e as UNSAFE_PATH_SEGMENTS, isUnsafeKey };
12
11
 
13
12
  //# sourceMappingURL=unsafePaths.js.map
package/dist/_dev.js CHANGED
@@ -1,6 +1,5 @@
1
- //#region src/_dev.ts
1
+ // src/_dev.ts
2
2
  function warn(e) {}
3
- //#endregion
4
3
  export { warn };
5
4
 
6
5
  //# sourceMappingURL=_dev.js.map
@@ -1,10 +1,9 @@
1
- //#region src/array/chunk.ts
1
+ // src/array/chunk.ts
2
2
  function chunk(e, t = 2) {
3
3
  if (!Array.isArray(e) && typeof e != "string") throw TypeError("chunk: argument must be an array or string");
4
4
  if (!Number.isInteger(t) || t < 1) throw RangeError("chunk: size must be a positive integer");
5
5
  return Array.from({ length: Math.ceil(e.length / t) }, (n, r) => e.slice(r * t, r * t + t));
6
6
  }
7
- //#endregion
8
7
  export { chunk };
9
8
 
10
9
  //# sourceMappingURL=chunk.js.map
@@ -1,8 +1,7 @@
1
- //#region src/array/compact.ts
1
+ // src/array/compact.ts
2
2
  function compact(e) {
3
3
  return e.filter(Boolean);
4
4
  }
5
- //#endregion
6
5
  export { compact };
7
6
 
8
7
  //# sourceMappingURL=compact.js.map
@@ -1,4 +1,4 @@
1
- //#region src/array/compare.ts
1
+ // src/array/compare.ts
2
2
  var compare = (e, t) => {
3
3
  if (e === t) return 0;
4
4
  if (e === void 0) return 1;
@@ -13,7 +13,6 @@ var compare = (e, t) => {
13
13
  }
14
14
  throw TypeError(`compare: unsupported types "${typeof e}" and "${typeof t}". Supported: number, string, Date, null, undefined.`);
15
15
  };
16
- //#endregion
17
16
  export { compare };
18
17
 
19
18
  //# sourceMappingURL=compare.js.map
@@ -1,5 +1,5 @@
1
1
  import { compare as e } from "./compare.js";
2
- //#region src/array/compareBy.ts
2
+ // src/array/compareBy.ts
3
3
  var compareBy = (t) => {
4
4
  let n = Object.entries(t);
5
5
  return (t, r) => {
@@ -10,7 +10,6 @@ var compareBy = (t) => {
10
10
  return 0;
11
11
  };
12
12
  };
13
- //#endregion
14
13
  export { compareBy };
15
14
 
16
15
  //# sourceMappingURL=compareBy.js.map
@@ -1,9 +1,8 @@
1
1
  import { isEqual as e } from "../guards/isEqual.js";
2
- //#region src/array/contains.ts
2
+ // src/array/contains.ts
3
3
  function contains(t, n) {
4
4
  return typeof n != "object" || !n ? t.includes(n) : t.some((t) => e(t, n));
5
5
  }
6
- //#endregion
7
6
  export { contains };
8
7
 
9
8
  //# sourceMappingURL=contains.js.map
@@ -1,5 +1,5 @@
1
1
  import { isUnsafeKey as e } from "../_common/unsafePaths.js";
2
- //#region src/array/countBy.ts
2
+ // src/array/countBy.ts
3
3
  function countBy(t, n) {
4
4
  let r = {};
5
5
  for (let i = 0; i < t.length; i++) {
@@ -8,7 +8,6 @@ function countBy(t, n) {
8
8
  }
9
9
  return r;
10
10
  }
11
- //#endregion
12
11
  export { countBy };
13
12
 
14
13
  //# sourceMappingURL=countBy.js.map
@@ -1,5 +1,5 @@
1
1
  import { toSelectorSet as e } from "../_common/_selectorSet.js";
2
- //#region src/array/difference.ts
2
+ // src/array/difference.ts
3
3
  function difference(t, n, r) {
4
4
  if (!r) {
5
5
  let e = new Set(n);
@@ -8,7 +8,6 @@ function difference(t, n, r) {
8
8
  let i = e(n, r);
9
9
  return t.filter((e) => !i.has(r(e)));
10
10
  }
11
- //#endregion
12
11
  export { difference };
13
12
 
14
13
  //# sourceMappingURL=difference.js.map
@@ -1,9 +1,8 @@
1
- //#region src/array/drop.ts
1
+ // src/array/drop.ts
2
2
  function drop(e, t = 1) {
3
3
  let n = Math.max(0, Math.floor(t));
4
4
  return e.slice(n);
5
5
  }
6
- //#endregion
7
6
  export { drop };
8
7
 
9
8
  //# sourceMappingURL=drop.js.map
@@ -1,9 +1,8 @@
1
- //#region src/array/dropLast.ts
1
+ // src/array/dropLast.ts
2
2
  function dropLast(e, t = 1) {
3
3
  let n = Math.max(0, Math.floor(t));
4
4
  return n === 0 ? [...e] : e.slice(0, Math.max(0, e.length - n));
5
5
  }
6
- //#endregion
7
6
  export { dropLast };
8
7
 
9
8
  //# sourceMappingURL=dropLast.js.map
@@ -1,4 +1,4 @@
1
- //#region src/array/filterMap.ts
1
+ // src/array/filterMap.ts
2
2
  function filterMap(e, t) {
3
3
  let n = [];
4
4
  for (let r = 0; r < e.length; r++) {
@@ -7,7 +7,6 @@ function filterMap(e, t) {
7
7
  }
8
8
  return n;
9
9
  }
10
- //#endregion
11
10
  export { filterMap };
12
11
 
13
12
  //# sourceMappingURL=filterMap.js.map
@@ -1,8 +1,7 @@
1
- //#region src/array/first.ts
1
+ // src/array/first.ts
2
2
  function first(e, t) {
3
3
  return e.length > 0 ? e[0] : t;
4
4
  }
5
- //#endregion
6
5
  export { first };
7
6
 
8
7
  //# sourceMappingURL=first.js.map
@@ -1,5 +1,5 @@
1
1
  import { isUnsafeKey as e } from "../_common/unsafePaths.js";
2
- //#region src/array/groupBy.ts
2
+ // src/array/groupBy.ts
3
3
  function groupBy(t, n) {
4
4
  let r = {};
5
5
  for (let i of t) {
@@ -8,7 +8,6 @@ function groupBy(t, n) {
8
8
  }
9
9
  return r;
10
10
  }
11
- //#endregion
12
11
  export { groupBy };
13
12
 
14
13
  //# sourceMappingURL=groupBy.js.map
@@ -1,5 +1,5 @@
1
1
  import { isUnsafeKey as e } from "../_common/unsafePaths.js";
2
- //#region src/array/indexBy.ts
2
+ // src/array/indexBy.ts
3
3
  function indexBy(t, n) {
4
4
  let r = {};
5
5
  for (let i of t) {
@@ -8,7 +8,6 @@ function indexBy(t, n) {
8
8
  }
9
9
  return r;
10
10
  }
11
- //#endregion
12
11
  export { indexBy };
13
12
 
14
13
  //# sourceMappingURL=indexBy.js.map
@@ -1,5 +1,5 @@
1
1
  import { toSelectorSet as e } from "../_common/_selectorSet.js";
2
- //#region src/array/intersection.ts
2
+ // src/array/intersection.ts
3
3
  function intersection(t, n, r) {
4
4
  if (!r) {
5
5
  let e = new Set(n);
@@ -8,7 +8,6 @@ function intersection(t, n, r) {
8
8
  let i = e(n, r);
9
9
  return t.filter((e) => i.has(r(e)));
10
10
  }
11
- //#endregion
12
11
  export { intersection };
13
12
 
14
13
  //# sourceMappingURL=intersection.js.map
@@ -1,8 +1,7 @@
1
- //#region src/array/last.ts
1
+ // src/array/last.ts
2
2
  function last(e, t) {
3
3
  return e.length > 0 ? e[e.length - 1] : t;
4
4
  }
5
- //#endregion
6
5
  export { last };
7
6
 
8
7
  //# sourceMappingURL=last.js.map
@@ -1,4 +1,4 @@
1
- //#region src/array/paginate.ts
1
+ // src/array/paginate.ts
2
2
  function paginate(e, t = {}) {
3
3
  if (!Array.isArray(e)) throw TypeError("paginate: first argument must be an array");
4
4
  let { pageOffset: n = 1, pageSize: r = 20 } = t, i = t.page ?? n;
@@ -13,7 +13,6 @@ function paginate(e, t = {}) {
13
13
  totalPages: a
14
14
  };
15
15
  }
16
- //#endregion
17
16
  export { paginate };
18
17
 
19
18
  //# sourceMappingURL=paginate.js.map
@@ -1,10 +1,9 @@
1
- //#region src/array/partition.ts
1
+ // src/array/partition.ts
2
2
  function partition(e, t) {
3
3
  let n = [], r = [];
4
4
  for (let i = 0; i < e.length; i++) t(e[i], i, e) ? n.push(e[i]) : r.push(e[i]);
5
5
  return [n, r];
6
6
  }
7
- //#endregion
8
7
  export { partition };
9
8
 
10
9
  //# sourceMappingURL=partition.js.map
@@ -1,4 +1,4 @@
1
- //#region src/array/replace.ts
1
+ // src/array/replace.ts
2
2
  function replace(e, t, n) {
3
3
  let r = e.findIndex(t);
4
4
  return r === -1 ? e : [
@@ -7,7 +7,6 @@ function replace(e, t, n) {
7
7
  ...e.slice(r + 1)
8
8
  ];
9
9
  }
10
- //#endregion
11
10
  export { replace };
12
11
 
13
12
  //# sourceMappingURL=replace.js.map
@@ -1,10 +1,9 @@
1
- //#region src/array/rotate.ts
1
+ // src/array/rotate.ts
2
2
  function rotate(e, t, { wrap: n = !1 } = {}) {
3
3
  if (e.length === 0) return e;
4
4
  let r = (t % e.length + e.length) % e.length, i = e.slice(r);
5
5
  return n ? [...i, ...e.slice(0, r)] : i;
6
6
  }
7
- //#endregion
8
7
  export { rotate };
9
8
 
10
9
  //# sourceMappingURL=rotate.js.map
@@ -1,5 +1,5 @@
1
1
  import { similarity as e } from "../string/similarity.js";
2
- //#region src/array/search.ts
2
+ // src/array/search.ts
3
3
  var normalizeText = (e) => e.normalize("NFKD").replace(/\p{M}/gu, ""), termsFor = (e, t) => {
4
4
  let n = t(e);
5
5
  return typeof n == "string" ? [n] : n;
@@ -24,7 +24,6 @@ function fuzzyScore(e, t, n = {}) {
24
24
  score: 1
25
25
  }));
26
26
  }
27
- //#endregion
28
27
  export { fuzzyFilter, fuzzyScore };
29
28
 
30
29
  //# sourceMappingURL=search.js.map
@@ -1,2 +1,2 @@
1
- const e=require("./compare.cjs"),t=require("./compareBy.cjs"),n=require("../object/getPath.cjs");function isCriteriaForm(e){return Array.isArray(e)}function sort(r,i,a=`asc`){if(!Array.isArray(r))throw TypeError(`sort: first argument must be an array`);if(typeof i==`function`){let t=a===`desc`?-1:1;return[...r].sort((n,r)=>e.compare(i(n),i(r))*t)}if(isCriteriaForm(i)){let t=i.map(({direction:e=`asc`,key:t})=>({multiplier:e===`desc`?-1:1,path:String(t)}));return[...r].sort((r,i)=>{for(let{multiplier:a,path:o}of t){let t=e.compare(n.getPath(r,o),n.getPath(i,o))*a;if(t!==0)return t}return 0})}return[...r].sort(t.compareBy(i))}exports.sort=sort;
1
+ const e=require("../object/getPath.cjs"),t=require("./compare.cjs"),n=require("./compareBy.cjs");function isCriteriaForm(e){return Array.isArray(e)}function sort(r,i,a=`asc`){if(!Array.isArray(r))throw TypeError(`sort: first argument must be an array`);if(typeof i==`function`){let e=a===`desc`?-1:1;return[...r].sort((n,r)=>t.compare(i(n),i(r))*e)}if(isCriteriaForm(i)){let n=i.map(({direction:e=`asc`,key:t})=>({multiplier:e===`desc`?-1:1,path:String(t)}));return[...r].sort((r,i)=>{for(let{multiplier:a,path:o}of n){let n=t.compare(e.getPath(r,o),e.getPath(i,o))*a;if(n!==0)return n}return 0})}return[...r].sort(n.compareBy(i))}exports.sort=sort;
2
2
  //# sourceMappingURL=sort.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"sort.cjs","names":["compare","getPath","compareBy","require_compare","require_compareBy","require_getPath","value","array","selectorOrSelectors","multiplier","direction","a","b","criteria","dir","key","result","path"],"sources":["../../src/array/sort.ts"],"sourcesContent":["import { getPath } from '../object/getPath';\nimport { compare } from './compare';\nimport { compareBy } from './compareBy';\n\nexport type SortDirection = 'asc' | 'desc';\nexport type SortSelectors<T> = Partial<Record<keyof T, SortDirection>>;\n\n/**\n * One ordering term: a dot-notation path into the item plus its direction.\n *\n * `key` accepts a `keyof T` or any dotted/bracketed path (`'address.city'`,\n * `'tags[0]'`), because a data grid's sortable columns are strings known only at\n * runtime. Values are resolved with `getPath`, which refuses prototype-access segments.\n */\nexport type SortCriterion<T> = Readonly<{\n key: keyof T | (string & {});\n direction?: SortDirection;\n}>;\n\n/**\n * Criteria arrive as a plain or frozen array from callers; `Array.isArray` alone cannot\n * narrow a `ReadonlyArray` member out of a union, so the discriminant gets a name.\n */\nfunction isCriteriaForm<T>(\n value: ((item: T) => unknown) | ReadonlyArray<SortCriterion<T>> | SortSelectors<T>,\n): value is ReadonlyArray<SortCriterion<T>> {\n return Array.isArray(value);\n}\n\n/**\n * Sorts an array by a selector function (single-field), by a multi-field object of\n * `{ key: 'asc' | 'desc' }` entries, or by an ordered list of path criteria.\n *\n * The criteria form is the one a grid or table hands over: column ids arrive as\n * runtime strings, so they cannot be typed `keyof T` keys. Ordering is delegated to\n * `compare`, which means a column mixing incompatible value types (a number beside a\n * string) throws a `TypeError` instead of guessing an order — keep columns typed.\n *\n * Ties keep their input order: `Array.prototype.sort` is stable in every supported\n * engine and no tiebreaker is layered on top.\n *\n * @example\n * ```ts\n * // Single field\n * sort([{ a: 2 }, { a: 1 }], item => item.a); // [{ a:1 }, { a:2 }]\n * sort([{ a: 2 }, { a: 1 }], item => item.a, 'desc'); // [{ a:2 }, { a:1 }]\n *\n * // Multi-field by key\n * sort(users, { name: 'asc', age: 'desc' });\n *\n * // Ordered path criteria, nested paths included\n * sort(rows, [{ key: 'address.city' }, { key: 'age', direction: 'desc' }]);\n * ```\n *\n * @param array - The array to sort.\n * @param selector - A function extracting the sort key, a multi-field object, or path criteria.\n * @param direction - `'asc'` (default) or `'desc'`: only applies to single-field mode.\n * @returns A new sorted array.\n *\n * @throws {TypeError} If the first argument is not an array, or a column mixes value types.\n */\nexport function sort<T>(array: readonly T[], selector: (item: T) => unknown, direction?: SortDirection): T[];\nexport function sort<T>(array: readonly T[], selectors: SortSelectors<T>): T[];\nexport function sort<T>(array: readonly T[], criteria: ReadonlyArray<SortCriterion<T>>): T[];\nexport function sort<T>(\n array: readonly T[],\n selectorOrSelectors: ((item: T) => unknown) | ReadonlyArray<SortCriterion<T>> | SortSelectors<T>,\n direction: SortDirection = 'asc',\n): T[] {\n if (!Array.isArray(array)) throw new TypeError('sort: first argument must be an array');\n\n if (typeof selectorOrSelectors === 'function') {\n const multiplier = direction === 'desc' ? -1 : 1;\n\n return [...array].sort((a, b) => compare(selectorOrSelectors(a), selectorOrSelectors(b)) * multiplier);\n }\n\n if (isCriteriaForm(selectorOrSelectors)) {\n const criteria = selectorOrSelectors.map(({ direction: dir = 'asc', key }) => ({\n multiplier: dir === 'desc' ? -1 : 1,\n path: String(key),\n }));\n\n return [...array].sort((a, b) => {\n for (const { multiplier, path } of criteria) {\n const result = compare(getPath(a, path), getPath(b, path)) * multiplier;\n\n if (result !== 0) return result;\n }\n\n return 0;\n });\n }\n\n return [...array].sort(compareBy(selectorOrSelectors));\n}\n"],"mappings":"A,iGAuBA,SAAS,eACP,EAC0C,CAC1C,OAAO,MAAM,QAAQM,CAAK,CAC5B,CAqCA,SAAgB,KACd,EACA,EACA,EAA2B,MACtB,CACL,GAAI,CAAC,MAAM,QAAQC,CAAK,EAAG,MAAU,UAAU,uCAAuC,EAEtF,GAAI,OAAOC,GAAwB,WAAY,CAC7C,IAAMC,EAAaC,IAAc,OAAS,GAAK,EAE/C,MAAO,CAAC,GAAGH,CAAK,CAAC,CAAC,MAAM,EAAG,IAAMP,EAAAA,QAAQQ,EAAoBG,CAAC,EAAGH,EAAoBI,CAAC,CAAC,EAAIH,CAAU,CACvG,CAEA,GAAI,eAAeD,CAAmB,EAAG,CACvC,IAAMK,EAAWL,EAAoB,KAAK,CAAE,UAAWM,EAAM,MAAO,UAAW,CAC7E,WAAYA,IAAQ,OAAS,GAAK,EAClC,KAAM,OAAOC,CAAG,CAClB,EAAE,EAEF,MAAO,CAAC,GAAGR,CAAK,CAAC,CAAC,MAAM,EAAG,IAAM,CAC/B,IAAK,GAAM,CAAE,aAAY,UAAUM,EAAU,CAC3C,IAAMG,EAAShB,EAAAA,QAAQC,EAAAA,QAAQU,EAAGM,CAAI,EAAGhB,EAAAA,QAAQW,EAAGK,CAAI,CAAC,EAAIR,EAE7D,GAAIO,IAAW,EAAG,OAAOA,CAC3B,CAEA,MAAO,EACT,CAAC,CACH,CAEA,MAAO,CAAC,GAAGT,CAAK,CAAC,CAAC,KAAKL,EAAAA,UAAUM,CAAmB,CAAC,CACvD,C"}
1
+ {"version":3,"file":"sort.cjs","names":["compare","getPath","compareBy","require_getPath","require_compare","require_compareBy","value","array","selectorOrSelectors","multiplier","direction","a","b","criteria","dir","key","result","path"],"sources":["../../src/array/sort.ts"],"sourcesContent":["import { getPath } from '../object/getPath';\nimport { compare } from './compare';\nimport { compareBy } from './compareBy';\n\nexport type SortDirection = 'asc' | 'desc';\nexport type SortSelectors<T> = Partial<Record<keyof T, SortDirection>>;\n\n/**\n * One ordering term: a dot-notation path into the item plus its direction.\n *\n * `key` accepts a `keyof T` or any dotted/bracketed path (`'address.city'`,\n * `'tags[0]'`), because a data grid's sortable columns are strings known only at\n * runtime. Values are resolved with `getPath`, which refuses prototype-access segments.\n */\nexport type SortCriterion<T> = Readonly<{\n key: keyof T | (string & {});\n direction?: SortDirection;\n}>;\n\n/**\n * Criteria arrive as a plain or frozen array from callers; `Array.isArray` alone cannot\n * narrow a `ReadonlyArray` member out of a union, so the discriminant gets a name.\n */\nfunction isCriteriaForm<T>(\n value: ((item: T) => unknown) | ReadonlyArray<SortCriterion<T>> | SortSelectors<T>,\n): value is ReadonlyArray<SortCriterion<T>> {\n return Array.isArray(value);\n}\n\n/**\n * Sorts an array by a selector function (single-field), by a multi-field object of\n * `{ key: 'asc' | 'desc' }` entries, or by an ordered list of path criteria.\n *\n * The criteria form is the one a grid or table hands over: column ids arrive as\n * runtime strings, so they cannot be typed `keyof T` keys. Ordering is delegated to\n * `compare`, which means a column mixing incompatible value types (a number beside a\n * string) throws a `TypeError` instead of guessing an order — keep columns typed.\n *\n * Ties keep their input order: `Array.prototype.sort` is stable in every supported\n * engine and no tiebreaker is layered on top.\n *\n * @example\n * ```ts\n * // Single field\n * sort([{ a: 2 }, { a: 1 }], item => item.a); // [{ a:1 }, { a:2 }]\n * sort([{ a: 2 }, { a: 1 }], item => item.a, 'desc'); // [{ a:2 }, { a:1 }]\n *\n * // Multi-field by key\n * sort(users, { name: 'asc', age: 'desc' });\n *\n * // Ordered path criteria, nested paths included\n * sort(rows, [{ key: 'address.city' }, { key: 'age', direction: 'desc' }]);\n * ```\n *\n * @param array - The array to sort.\n * @param selector - A function extracting the sort key, a multi-field object, or path criteria.\n * @param direction - `'asc'` (default) or `'desc'`: only applies to single-field mode.\n * @returns A new sorted array.\n *\n * @throws {TypeError} If the first argument is not an array, or a column mixes value types.\n */\nexport function sort<T>(array: readonly T[], selector: (item: T) => unknown, direction?: SortDirection): T[];\nexport function sort<T>(array: readonly T[], selectors: SortSelectors<T>): T[];\nexport function sort<T>(array: readonly T[], criteria: ReadonlyArray<SortCriterion<T>>): T[];\nexport function sort<T>(\n array: readonly T[],\n selectorOrSelectors: ((item: T) => unknown) | ReadonlyArray<SortCriterion<T>> | SortSelectors<T>,\n direction: SortDirection = 'asc',\n): T[] {\n if (!Array.isArray(array)) throw new TypeError('sort: first argument must be an array');\n\n if (typeof selectorOrSelectors === 'function') {\n const multiplier = direction === 'desc' ? -1 : 1;\n\n return [...array].sort((a, b) => compare(selectorOrSelectors(a), selectorOrSelectors(b)) * multiplier);\n }\n\n if (isCriteriaForm(selectorOrSelectors)) {\n const criteria = selectorOrSelectors.map(({ direction: dir = 'asc', key }) => ({\n multiplier: dir === 'desc' ? -1 : 1,\n path: String(key),\n }));\n\n return [...array].sort((a, b) => {\n for (const { multiplier, path } of criteria) {\n const result = compare(getPath(a, path), getPath(b, path)) * multiplier;\n\n if (result !== 0) return result;\n }\n\n return 0;\n });\n }\n\n return [...array].sort(compareBy(selectorOrSelectors));\n}\n"],"mappings":"A,iGAuBA,SAAS,eACP,EAC0C,CAC1C,OAAO,MAAM,QAAQM,CAAK,CAC5B,CAqCA,SAAgB,KACd,EACA,EACA,EAA2B,MACtB,CACL,GAAI,CAAC,MAAM,QAAQC,CAAK,EAAG,MAAU,UAAU,uCAAuC,EAEtF,GAAI,OAAOC,GAAwB,WAAY,CAC7C,IAAMC,EAAaC,IAAc,OAAS,GAAK,EAE/C,MAAO,CAAC,GAAGH,CAAK,CAAC,CAAC,MAAM,EAAG,IAAMP,EAAAA,QAAQQ,EAAoBG,CAAC,EAAGH,EAAoBI,CAAC,CAAC,EAAIH,CAAU,CACvG,CAEA,GAAI,eAAeD,CAAmB,EAAG,CACvC,IAAMK,EAAWL,EAAoB,KAAK,CAAE,UAAWM,EAAM,MAAO,UAAW,CAC7E,WAAYA,IAAQ,OAAS,GAAK,EAClC,KAAM,OAAOC,CAAG,CAClB,EAAE,EAEF,MAAO,CAAC,GAAGR,CAAK,CAAC,CAAC,MAAM,EAAG,IAAM,CAC/B,IAAK,GAAM,CAAE,aAAY,UAAUM,EAAU,CAC3C,IAAMG,EAAShB,EAAAA,QAAQC,EAAAA,QAAQU,EAAGM,CAAI,EAAGhB,EAAAA,QAAQW,EAAGK,CAAI,CAAC,EAAIR,EAE7D,GAAIO,IAAW,EAAG,OAAOA,CAC3B,CAEA,MAAO,EACT,CAAC,CACH,CAEA,MAAO,CAAC,GAAGT,CAAK,CAAC,CAAC,KAAKL,EAAAA,UAAUM,CAAmB,CAAC,CACvD,C"}
@@ -1,32 +1,31 @@
1
- import { compare as e } from "./compare.js";
2
- import { compareBy as t } from "./compareBy.js";
3
- import { getPath as n } from "../object/getPath.js";
4
- //#region src/array/sort.ts
1
+ import { getPath as e } from "../object/getPath.js";
2
+ import { compare as t } from "./compare.js";
3
+ import { compareBy as n } from "./compareBy.js";
4
+ // src/array/sort.ts
5
5
  function isCriteriaForm(e) {
6
6
  return Array.isArray(e);
7
7
  }
8
8
  function sort(r, i, a = "asc") {
9
9
  if (!Array.isArray(r)) throw TypeError("sort: first argument must be an array");
10
10
  if (typeof i == "function") {
11
- let t = a === "desc" ? -1 : 1;
12
- return [...r].sort((n, r) => e(i(n), i(r)) * t);
11
+ let e = a === "desc" ? -1 : 1;
12
+ return [...r].sort((n, r) => t(i(n), i(r)) * e);
13
13
  }
14
14
  if (isCriteriaForm(i)) {
15
- let t = i.map(({ direction: e = "asc", key: t }) => ({
15
+ let n = i.map(({ direction: e = "asc", key: t }) => ({
16
16
  multiplier: e === "desc" ? -1 : 1,
17
17
  path: String(t)
18
18
  }));
19
19
  return [...r].sort((r, i) => {
20
- for (let { multiplier: a, path: o } of t) {
21
- let t = e(n(r, o), n(i, o)) * a;
22
- if (t !== 0) return t;
20
+ for (let { multiplier: a, path: o } of n) {
21
+ let n = t(e(r, o), e(i, o)) * a;
22
+ if (n !== 0) return n;
23
23
  }
24
24
  return 0;
25
25
  });
26
26
  }
27
- return [...r].sort(t(i));
27
+ return [...r].sort(n(i));
28
28
  }
29
- //#endregion
30
29
  export { sort };
31
30
 
32
31
  //# sourceMappingURL=sort.js.map
@@ -1,9 +1,8 @@
1
- //#region src/array/take.ts
1
+ // src/array/take.ts
2
2
  function take(e, t = 1) {
3
3
  let n = Math.max(0, Math.floor(t));
4
4
  return e.slice(0, n);
5
5
  }
6
- //#endregion
7
6
  export { take };
8
7
 
9
8
  //# sourceMappingURL=take.js.map
@@ -1,9 +1,8 @@
1
- //#region src/array/takeLast.ts
1
+ // src/array/takeLast.ts
2
2
  function takeLast(e, t = 1) {
3
3
  let n = Math.max(0, Math.floor(t));
4
4
  return n === 0 ? [] : e.slice(Math.max(0, e.length - n));
5
5
  }
6
- //#endregion
7
6
  export { takeLast };
8
7
 
9
8
  //# sourceMappingURL=takeLast.js.map
@@ -1,9 +1,8 @@
1
- //#region src/array/toggle.ts
1
+ // src/array/toggle.ts
2
2
  function toggle(e, t, n, r = {}) {
3
3
  let { strategy: i = "append" } = r, a = n ? (e) => n(e) === n(t) : (e) => e === t, o = e.findIndex(a);
4
4
  return o === -1 ? i === "prepend" ? [t, ...e] : [...e, t] : [...e.slice(0, o), ...e.slice(o + 1)];
5
5
  }
6
- //#endregion
7
6
  export { toggle };
8
7
 
9
8
  //# sourceMappingURL=toggle.js.map
@@ -1,9 +1,8 @@
1
1
  import { dedupeBySelector as e } from "../_common/_selectorSet.js";
2
- //#region src/array/union.ts
2
+ // src/array/union.ts
3
3
  function union(t, n, r) {
4
4
  return r ? e([...t, ...n], r) : [.../* @__PURE__ */ new Set([...t, ...n])];
5
5
  }
6
- //#endregion
7
6
  export { union };
8
7
 
9
8
  //# sourceMappingURL=union.js.map
@@ -1,9 +1,8 @@
1
1
  import { dedupeBySelector as e } from "../_common/_selectorSet.js";
2
- //#region src/array/uniq.ts
2
+ // src/array/uniq.ts
3
3
  function uniq(t, n) {
4
4
  return t.length <= 1 ? [...t] : n ? e(t, n) : [...new Set(t)];
5
5
  }
6
- //#endregion
7
6
  export { uniq };
8
7
 
9
8
  //# sourceMappingURL=uniq.js.map
@@ -1,11 +1,10 @@
1
- //#region src/array/unzip.ts
1
+ // src/array/unzip.ts
2
2
  function unzip(e) {
3
3
  if (e.length === 0) return [];
4
4
  let t = e[0].length, n = Array.from({ length: t }, () => []);
5
5
  for (let r of e) for (let e = 0; e < t; e++) n[e].push(r[e]);
6
6
  return n;
7
7
  }
8
- //#endregion
9
8
  export { unzip };
10
9
 
11
10
  //# sourceMappingURL=unzip.js.map
package/dist/array/zip.js CHANGED
@@ -1,11 +1,10 @@
1
- //#region src/array/zip.ts
1
+ // src/array/zip.ts
2
2
  function zip(...e) {
3
3
  if (e.length === 0) return [];
4
4
  let t = Math.max(...e.map((e) => e.length)), n = Array(t);
5
5
  for (let r = 0; r < t; r++) n[r] = e.map((e) => e[r]);
6
6
  return n;
7
7
  }
8
- //#endregion
9
8
  export { zip };
10
9
 
11
10
  //# sourceMappingURL=zip.js.map