@vielzeug/arsenal 26.11.4 → 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.
- package/README.md +6 -1
- package/dist/_common/_lruMap.js +1 -2
- package/dist/_common/_selectorSet.js +1 -2
- package/dist/_common/unsafePaths.js +1 -2
- package/dist/_dev.js +1 -2
- package/dist/array/chunk.js +1 -2
- package/dist/array/compact.js +1 -2
- package/dist/array/compare.js +1 -2
- package/dist/array/compareBy.js +1 -2
- package/dist/array/contains.js +1 -2
- package/dist/array/countBy.js +1 -2
- package/dist/array/difference.js +1 -2
- package/dist/array/drop.js +1 -2
- package/dist/array/dropLast.js +1 -2
- package/dist/array/filterMap.js +1 -2
- package/dist/array/first.js +1 -2
- package/dist/array/groupBy.js +1 -2
- package/dist/array/indexBy.js +1 -2
- package/dist/array/intersection.js +1 -2
- package/dist/array/last.js +1 -2
- package/dist/array/paginate.js +1 -2
- package/dist/array/partition.js +1 -2
- package/dist/array/replace.js +1 -2
- package/dist/array/rotate.js +1 -2
- package/dist/array/search.js +1 -2
- package/dist/array/sort.cjs +1 -1
- package/dist/array/sort.cjs.map +1 -1
- package/dist/array/sort.js +11 -12
- package/dist/array/take.js +1 -2
- package/dist/array/takeLast.js +1 -2
- package/dist/array/toggle.js +1 -2
- package/dist/array/union.js +1 -2
- package/dist/array/uniq.js +1 -2
- package/dist/array/unzip.js +1 -2
- package/dist/array/zip.js +1 -2
- package/dist/arsenal.js +47 -94
- package/dist/arsenal.js.map +1 -1
- package/dist/async/abortError.js +1 -2
- package/dist/async/abortable.js +1 -2
- package/dist/async/attempt.js +1 -2
- package/dist/async/backoff.js +1 -2
- package/dist/async/index.cjs +1 -1
- package/dist/async/index.js +5 -5
- package/dist/async/parallel.js +1 -2
- package/dist/async/retry.js +1 -2
- package/dist/async/sleep.js +1 -2
- package/dist/async/taskPool.js +1 -2
- package/dist/async/waitFor.js +1 -2
- package/dist/cache/cache.js +1 -2
- package/dist/cache/memo.js +1 -2
- package/dist/encoding/base64url.js +1 -2
- package/dist/encoding/compression.js +1 -2
- package/dist/encoding/share-code.js +1 -2
- package/dist/errors.js +1 -2
- package/dist/function/assert.js +1 -2
- package/dist/function/debounce.js +1 -2
- package/dist/function/once.js +1 -2
- package/dist/function/pipe.js +1 -2
- package/dist/function/runAll.js +1 -2
- package/dist/function/tap.js +1 -2
- package/dist/function/tapper.js +1 -2
- package/dist/function/throttle.js +1 -2
- package/dist/guards/combinators.js +1 -2
- package/dist/guards/index.cjs +1 -1
- package/dist/guards/index.js +13 -13
- package/dist/guards/isAbortError.js +1 -2
- package/dist/guards/isDate.js +1 -2
- package/dist/guards/isDefined.js +1 -2
- package/dist/guards/isEmpty.js +1 -2
- package/dist/guards/isEqual.js +1 -2
- package/dist/guards/isError.js +1 -2
- package/dist/guards/isFunction.js +1 -2
- package/dist/guards/isMatch.js +1 -2
- package/dist/guards/isNil.js +1 -2
- package/dist/guards/isNumber.js +1 -2
- package/dist/guards/isPlainObject.js +1 -2
- package/dist/guards/isPrimitive.js +1 -2
- package/dist/guards/isPromise.js +1 -2
- package/dist/guards/isRegex.js +1 -2
- package/dist/guards/shallowEqual.js +1 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +39 -39
- package/dist/math/allocate.js +1 -2
- package/dist/math/average.js +1 -2
- package/dist/math/clamp.js +1 -2
- package/dist/math/gcd.js +1 -2
- package/dist/math/index.cjs +1 -1
- package/dist/math/index.js +15 -15
- package/dist/math/lcm.js +1 -2
- package/dist/math/lerp.js +1 -2
- package/dist/math/linspace.js +1 -2
- package/dist/math/median.js +1 -2
- package/dist/math/mod.js +1 -2
- package/dist/math/normalize.js +1 -2
- package/dist/math/range.js +1 -2
- package/dist/math/round.js +1 -2
- package/dist/math/standardDeviation.js +1 -2
- package/dist/math/sum.js +1 -2
- package/dist/math/variance.js +1 -2
- package/dist/object/defaults.js +1 -2
- package/dist/object/diff.cjs +1 -1
- package/dist/object/diff.cjs.map +1 -1
- package/dist/object/diff.js +12 -13
- package/dist/object/filterValues.js +1 -2
- package/dist/object/flattenPaths.js +1 -2
- package/dist/object/getPath.js +1 -2
- package/dist/object/hash.js +1 -2
- package/dist/object/index.cjs +1 -1
- package/dist/object/index.js +13 -13
- package/dist/object/invert.js +1 -2
- package/dist/object/mapKeys.js +1 -2
- package/dist/object/mapValues.js +1 -2
- package/dist/object/merge.js +1 -2
- package/dist/object/omit.js +1 -2
- package/dist/object/pick.js +1 -2
- package/dist/object/prune.cjs +1 -1
- package/dist/object/prune.cjs.map +1 -1
- package/dist/object/prune.js +8 -9
- package/dist/object/tryParseJson.js +1 -2
- package/dist/random/_index.js +1 -2
- package/dist/random/draw.js +1 -2
- package/dist/random/index.cjs +1 -1
- package/dist/random/index.js +5 -5
- package/dist/random/random.js +1 -2
- package/dist/random/shuffle.js +1 -2
- package/dist/random/source.js +1 -2
- package/dist/string/_caseUtils.js +1 -2
- package/dist/string/camelCase.js +1 -2
- package/dist/string/escape.js +1 -2
- package/dist/string/index.cjs +1 -1
- package/dist/string/index.js +11 -11
- package/dist/string/kebabCase.js +1 -2
- package/dist/string/padCenter.js +1 -2
- package/dist/string/pascalCase.js +1 -2
- package/dist/string/similarity.js +1 -2
- package/dist/string/snakeCase.js +1 -2
- package/dist/string/titleCase.js +1 -2
- package/dist/string/truncate.js +1 -2
- package/dist/string/unescape.js +1 -2
- package/dist/string/words.js +1 -2
- 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(
|
|
33
|
+
console.log(
|
|
34
|
+
groupBy(matches, (user) => user.name),
|
|
35
|
+
data,
|
|
36
|
+
profile,
|
|
37
|
+
cachedResponses,
|
|
38
|
+
);
|
|
34
39
|
pool.dispose();
|
|
35
40
|
```
|
|
36
41
|
|
package/dist/_common/_lruMap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
package/dist/array/chunk.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
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
|
package/dist/array/compact.js
CHANGED
package/dist/array/compare.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
package/dist/array/compareBy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compare as e } from "./compare.js";
|
|
2
|
-
|
|
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
|
package/dist/array/contains.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { isEqual as e } from "../guards/isEqual.js";
|
|
2
|
-
|
|
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
|
package/dist/array/countBy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isUnsafeKey as e } from "../_common/unsafePaths.js";
|
|
2
|
-
|
|
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
|
package/dist/array/difference.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toSelectorSet as e } from "../_common/_selectorSet.js";
|
|
2
|
-
|
|
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
|
package/dist/array/drop.js
CHANGED
package/dist/array/dropLast.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
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
|
package/dist/array/filterMap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
package/dist/array/first.js
CHANGED
package/dist/array/groupBy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isUnsafeKey as e } from "../_common/unsafePaths.js";
|
|
2
|
-
|
|
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
|
package/dist/array/indexBy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isUnsafeKey as e } from "../_common/unsafePaths.js";
|
|
2
|
-
|
|
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
|
-
|
|
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
|
package/dist/array/last.js
CHANGED
package/dist/array/paginate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
package/dist/array/partition.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
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
|
package/dist/array/replace.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
package/dist/array/rotate.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
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
|
package/dist/array/search.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { similarity as e } from "../string/similarity.js";
|
|
2
|
-
|
|
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
|
package/dist/array/sort.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("
|
|
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
|
package/dist/array/sort.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort.cjs","names":["compare","getPath","compareBy","
|
|
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"}
|
package/dist/array/sort.js
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
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
|
|
12
|
-
return [...r].sort((n, r) =>
|
|
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
|
|
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
|
|
21
|
-
let
|
|
22
|
-
if (
|
|
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(
|
|
27
|
+
return [...r].sort(n(i));
|
|
28
28
|
}
|
|
29
|
-
//#endregion
|
|
30
29
|
export { sort };
|
|
31
30
|
|
|
32
31
|
//# sourceMappingURL=sort.js.map
|
package/dist/array/take.js
CHANGED
package/dist/array/takeLast.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
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
|
package/dist/array/toggle.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
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
|
package/dist/array/union.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { dedupeBySelector as e } from "../_common/_selectorSet.js";
|
|
2
|
-
|
|
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
|
package/dist/array/uniq.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { dedupeBySelector as e } from "../_common/_selectorSet.js";
|
|
2
|
-
|
|
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
|
package/dist/array/unzip.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|