es-toolkit 0.0.1 → 1.0.0-dev.19
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 +5 -0
- package/README.md +31 -0
- package/dist/array/chunk.d.ts +21 -5
- package/dist/array/difference.d.ts +20 -4
- package/dist/array/differenceBy.d.ts +23 -5
- package/dist/array/differenceWith.d.ts +19 -5
- package/dist/array/drop.d.ts +13 -4
- package/dist/array/dropRight.d.ts +13 -4
- package/dist/array/dropRightWhile.d.ts +15 -4
- package/dist/array/dropWhile.d.ts +15 -4
- package/dist/array/groupBy.d.ts +31 -1
- package/dist/array/groupBy.spec.d.ts +1 -0
- package/dist/array/index.js +437 -224
- package/dist/array/intersection.d.ts +13 -6
- package/dist/array/intersectionBy.d.ts +17 -8
- package/dist/array/intersectionWith.d.ts +18 -8
- package/dist/array/partition.d.ts +19 -5
- package/dist/array/sample.d.ts +10 -3
- package/dist/array/shuffle.d.ts +11 -4
- package/dist/array/takeRight.d.ts +0 -2
- package/dist/array/union.d.ts +13 -6
- package/dist/array/unionBy.d.ts +0 -3
- package/dist/array/unionWith.d.ts +15 -9
- package/dist/array/uniq.d.ts +9 -8
- package/dist/array/xor.d.ts +0 -2
- package/dist/array/zip.d.ts +18 -6
- package/dist/array/zipWith.d.ts +26 -3
- package/dist/function/debounce.d.ts +4 -4
- package/dist/function/index.js +4 -5
- package/dist/function/once.d.ts +0 -1
- package/dist/index.js +651 -248
- package/dist/math/clamp.d.ts +16 -8
- package/dist/math/index.js +114 -29
- package/dist/math/round.d.ts +11 -8
- package/dist/math/sum.d.ts +10 -9
- package/dist/object/index.js +122 -12
- package/dist/object/omit.d.ts +13 -4
- package/dist/object/omitBy.d.ts +19 -1
- package/dist/object/omitBy.spec.d.ts +1 -0
- package/dist/object/pick.d.ts +13 -4
- package/dist/object/pickBy.d.ts +19 -1
- package/dist/object/pickBy.spec.d.ts +1 -0
- package/dist/predicate/index.js +58 -10
- package/dist/predicate/isNil.d.ts +17 -3
- package/dist/predicate/isNotNil.d.ts +7 -3
- package/dist/predicate/isNull.d.ts +17 -2
- package/dist/predicate/isUndefined.d.ts +17 -2
- package/dist/promise/delay.d.ts +17 -4
- package/dist/promise/index.js +16 -3
- package/esm/array/_virtual/_rollupPluginBabelHelpers.mjs +1 -37
- package/esm/array/chunk.mjs +28 -25
- package/esm/array/difference.mjs +20 -4
- package/esm/array/differenceBy.mjs +23 -5
- package/esm/array/differenceWith.mjs +19 -5
- package/esm/array/drop.mjs +13 -4
- package/esm/array/dropRight.mjs +13 -4
- package/esm/array/dropRightWhile.mjs +15 -4
- package/esm/array/dropWhile.mjs +15 -4
- package/esm/array/groupBy.mjs +51 -2
- package/esm/array/intersection.mjs +13 -6
- package/esm/array/intersectionBy.mjs +17 -8
- package/esm/array/intersectionWith.mjs +18 -8
- package/esm/array/partition.mjs +19 -5
- package/esm/array/sample.mjs +10 -3
- package/esm/array/shuffle.mjs +12 -5
- package/esm/array/takeRight.mjs +0 -2
- package/esm/array/union.mjs +14 -10
- package/esm/array/unionBy.mjs +0 -3
- package/esm/array/unionWith.mjs +16 -11
- package/esm/array/uniq.mjs +28 -9
- package/esm/array/xor.mjs +0 -2
- package/esm/array/zip.mjs +18 -6
- package/esm/array/zipWith.mjs +26 -3
- package/esm/function/debounce.mjs +4 -4
- package/esm/function/once.mjs +0 -1
- package/esm/math/_virtual/_rollupPluginBabelHelpers.mjs +66 -0
- package/esm/math/clamp.mjs +15 -7
- package/esm/math/round.mjs +11 -8
- package/esm/math/sum.mjs +25 -14
- package/esm/object/_virtual/_rollupPluginBabelHelpers.mjs +37 -1
- package/esm/object/omit.mjs +13 -4
- package/esm/object/omitBy.mjs +32 -2
- package/esm/object/pick.mjs +13 -4
- package/esm/object/pickBy.mjs +32 -2
- package/esm/predicate/isNil.mjs +17 -3
- package/esm/predicate/isNotNil.mjs +7 -3
- package/esm/predicate/isNull.mjs +17 -2
- package/esm/predicate/isUndefined.mjs +17 -2
- package/esm/promise/delay.mjs +16 -3
- package/package.json +17 -3
- package/.vscode/extensions.json +0 -7
- package/.vscode/settings.json +0 -10
- package/.yarn/sdks/eslint/bin/eslint.js +0 -20
- package/.yarn/sdks/eslint/lib/api.js +0 -20
- package/.yarn/sdks/eslint/lib/unsupported-api.js +0 -20
- package/.yarn/sdks/eslint/package.json +0 -14
- package/.yarn/sdks/integrations.yml +0 -5
- package/.yarn/sdks/prettier/bin/prettier.cjs +0 -20
- package/.yarn/sdks/prettier/index.cjs +0 -20
- package/.yarn/sdks/prettier/package.json +0 -7
- package/.yarn/sdks/typescript/bin/tsc +0 -20
- package/.yarn/sdks/typescript/bin/tsserver +0 -20
- package/.yarn/sdks/typescript/lib/tsc.js +0 -20
- package/.yarn/sdks/typescript/lib/tsserver.js +0 -225
- package/.yarn/sdks/typescript/lib/tsserverlibrary.js +0 -225
- package/.yarn/sdks/typescript/lib/typescript.js +0 -20
- package/.yarn/sdks/typescript/package.json +0 -10
- package/babel.config.js +0 -6
- package/coverage/.tmp/coverage-0.json +0 -1
- package/coverage/.tmp/coverage-1.json +0 -1
- package/coverage/.tmp/coverage-10.json +0 -1
- package/coverage/.tmp/coverage-11.json +0 -1
- package/coverage/.tmp/coverage-12.json +0 -1
- package/coverage/.tmp/coverage-13.json +0 -1
- package/coverage/.tmp/coverage-14.json +0 -1
- package/coverage/.tmp/coverage-15.json +0 -1
- package/coverage/.tmp/coverage-16.json +0 -1
- package/coverage/.tmp/coverage-17.json +0 -1
- package/coverage/.tmp/coverage-18.json +0 -1
- package/coverage/.tmp/coverage-19.json +0 -1
- package/coverage/.tmp/coverage-2.json +0 -1
- package/coverage/.tmp/coverage-20.json +0 -1
- package/coverage/.tmp/coverage-21.json +0 -1
- package/coverage/.tmp/coverage-22.json +0 -1
- package/coverage/.tmp/coverage-23.json +0 -1
- package/coverage/.tmp/coverage-24.json +0 -1
- package/coverage/.tmp/coverage-25.json +0 -1
- package/coverage/.tmp/coverage-26.json +0 -1
- package/coverage/.tmp/coverage-27.json +0 -1
- package/coverage/.tmp/coverage-28.json +0 -1
- package/coverage/.tmp/coverage-29.json +0 -1
- package/coverage/.tmp/coverage-3.json +0 -1
- package/coverage/.tmp/coverage-30.json +0 -1
- package/coverage/.tmp/coverage-4.json +0 -1
- package/coverage/.tmp/coverage-5.json +0 -1
- package/coverage/.tmp/coverage-6.json +0 -1
- package/coverage/.tmp/coverage-7.json +0 -1
- package/coverage/.tmp/coverage-8.json +0 -1
- package/coverage/.tmp/coverage-9.json +0 -1
- package/rollup.config.js +0 -5
- package/src/array/chunk.spec.ts +0 -27
- package/src/array/chunk.ts +0 -24
- package/src/array/difference.spec.ts +0 -10
- package/src/array/difference.ts +0 -11
- package/src/array/differenceBy.spec.ts +0 -9
- package/src/array/differenceBy.ts +0 -14
- package/src/array/differenceWith.spec.ts +0 -8
- package/src/array/differenceWith.ts +0 -14
- package/src/array/drop.spec.ts +0 -9
- package/src/array/drop.ts +0 -9
- package/src/array/dropRight.spec.ts +0 -9
- package/src/array/dropRight.ts +0 -9
- package/src/array/dropRightWhile.spec.ts +0 -16
- package/src/array/dropRightWhile.ts +0 -13
- package/src/array/dropWhile.spec.ts +0 -14
- package/src/array/dropWhile.ts +0 -10
- package/src/array/groupBy.ts +0 -3
- package/src/array/index.ts +0 -30
- package/src/array/intersection.spec.ts +0 -11
- package/src/array/intersection.ts +0 -15
- package/src/array/intersectionBy.spec.ts +0 -9
- package/src/array/intersectionBy.ts +0 -18
- package/src/array/intersectionWith.spec.ts +0 -9
- package/src/array/intersectionWith.ts +0 -18
- package/src/array/partition.spec.ts +0 -23
- package/src/array/partition.ts +0 -21
- package/src/array/sample.spec.ts +0 -11
- package/src/array/sample.ts +0 -10
- package/src/array/shuffle.spec.ts +0 -11
- package/src/array/shuffle.ts +0 -18
- package/src/array/take.spec.ts +0 -25
- package/src/array/take.ts +0 -25
- package/src/array/takeRight.spec.ts +0 -25
- package/src/array/takeRight.ts +0 -29
- package/src/array/takeRightWhile.spec.ts +0 -16
- package/src/array/takeRightWhile.ts +0 -26
- package/src/array/takeWhile.spec.ts +0 -34
- package/src/array/takeWhile.ts +0 -31
- package/src/array/union.spec.ts +0 -10
- package/src/array/union.ts +0 -14
- package/src/array/unionBy.spec.ts +0 -12
- package/src/array/unionBy.ts +0 -35
- package/src/array/unionWith.spec.ts +0 -23
- package/src/array/unionWith.ts +0 -18
- package/src/array/uniq.spec.ts +0 -8
- package/src/array/uniq.ts +0 -16
- package/src/array/uniqBy.spec.ts +0 -8
- package/src/array/uniqBy.ts +0 -17
- package/src/array/uniqWith.spec.ts +0 -16
- package/src/array/uniqWith.ts +0 -29
- package/src/array/xor.spec.ts +0 -13
- package/src/array/xor.ts +0 -25
- package/src/array/xorBy.spec.ts +0 -16
- package/src/array/xorBy.ts +0 -29
- package/src/array/xorWith.spec.ts +0 -16
- package/src/array/xorWith.ts +0 -28
- package/src/array/zip.spec.ts +0 -14
- package/src/array/zip.ts +0 -34
- package/src/array/zipWith.spec.ts +0 -13
- package/src/array/zipWith.ts +0 -23
- package/src/function/debounce.spec.ts +0 -76
- package/src/function/debounce.ts +0 -42
- package/src/function/index.ts +0 -3
- package/src/function/once.spec.ts +0 -31
- package/src/function/once.ts +0 -34
- package/src/function/throttle.spec.ts +0 -32
- package/src/function/throttle.ts +0 -39
- package/src/index.ts +0 -6
- package/src/math/clamp.spec.ts +0 -18
- package/src/math/clamp.ts +0 -17
- package/src/math/index.ts +0 -3
- package/src/math/round.spec.ts +0 -53
- package/src/math/round.ts +0 -16
- package/src/math/sum.spec.ts +0 -29
- package/src/math/sum.ts +0 -17
- package/src/object/index.ts +0 -4
- package/src/object/omit.spec.ts +0 -10
- package/src/object/omit.ts +0 -15
- package/src/object/omitBy.ts +0 -3
- package/src/object/pick.spec.ts +0 -10
- package/src/object/pick.ts +0 -15
- package/src/object/pickBy.ts +0 -3
- package/src/predicate/index.ts +0 -4
- package/src/predicate/isNil.spec.ts +0 -23
- package/src/predicate/isNil.ts +0 -8
- package/src/predicate/isNotNil.spec.ts +0 -29
- package/src/predicate/isNotNil.ts +0 -14
- package/src/predicate/isNull.spec.ts +0 -23
- package/src/predicate/isNull.ts +0 -8
- package/src/predicate/isUndefined.spec.ts +0 -23
- package/src/predicate/isUndefined.ts +0 -8
- package/src/promise/delay.spec.ts +0 -13
- package/src/promise/delay.ts +0 -10
- package/src/promise/index.ts +0 -1
- package/tsconfig.json +0 -12
- package/vitest.config.mts +0 -13
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @name isNull
|
|
3
2
|
* Checks if the given value is null.
|
|
4
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* This function tests whether the provided value is strictly equal to `null`.
|
|
5
|
+
* It returns `true` if the value is `null`, and `false` otherwise.
|
|
6
|
+
*
|
|
7
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null`.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} x - The value to test if it is null.
|
|
10
|
+
* @returns {x is null} True if the value is null, false otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* * const value1 = null;
|
|
14
|
+
* const value2 = undefined;
|
|
15
|
+
* const value3 = 42;
|
|
16
|
+
*
|
|
17
|
+
* console.log(isNull(value1)); // true
|
|
18
|
+
* console.log(isNull(value2)); // false
|
|
19
|
+
* console.log(isNull(value3)); // false
|
|
5
20
|
*/
|
|
6
21
|
export declare function isNull(x: unknown): x is null;
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @name isUndefined
|
|
3
2
|
* Checks if the given value is undefined.
|
|
4
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* This function tests whether the provided value is strictly equal to `undefined`.
|
|
5
|
+
* It returns `true` if the value is `undefined`, and `false` otherwise.
|
|
6
|
+
*
|
|
7
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `undefined`.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} x - The value to test if it is undefined.
|
|
10
|
+
* @returns {x is undefined} true if the value is undefined, false otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* * const value1 = undefined;
|
|
14
|
+
* const value2 = null;
|
|
15
|
+
* const value3 = 42;
|
|
16
|
+
*
|
|
17
|
+
* console.log(isUndefined(value1)); // true
|
|
18
|
+
* console.log(isUndefined(value2)); // false
|
|
19
|
+
* console.log(isUndefined(value3)); // false
|
|
5
20
|
*/
|
|
6
21
|
export declare function isUndefined(x: unknown): x is undefined;
|
package/dist/promise/delay.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Delays the execution of code for a specified number of milliseconds.
|
|
3
|
+
*
|
|
4
|
+
* This function returns a Promise that resolves after the specified delay, allowing you to use it
|
|
5
|
+
* with async/await to pause execution.
|
|
6
|
+
*
|
|
7
|
+
* @param {number} ms - The number of milliseconds to delay.
|
|
8
|
+
* @returns {Promise<void>} A Promise that resolves after the specified delay.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* async function foo() {
|
|
12
|
+
* console.log('Start');
|
|
13
|
+
* await delay(1000); // Delays execution for 1 second
|
|
14
|
+
* console.log('End');
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* foo();
|
|
5
18
|
*/
|
|
6
|
-
export declare function delay(ms: number): Promise<
|
|
19
|
+
export declare function delay(ms: number): Promise<void>;
|
package/dist/promise/index.js
CHANGED
|
@@ -3,9 +3,22 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Delays the execution of code for a specified number of milliseconds.
|
|
7
|
+
*
|
|
8
|
+
* This function returns a Promise that resolves after the specified delay, allowing you to use it
|
|
9
|
+
* with async/await to pause execution.
|
|
10
|
+
*
|
|
11
|
+
* @param {number} ms - The number of milliseconds to delay.
|
|
12
|
+
* @returns {Promise<void>} A Promise that resolves after the specified delay.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* async function foo() {
|
|
16
|
+
* console.log('Start');
|
|
17
|
+
* await delay(1000); // Delays execution for 1 second
|
|
18
|
+
* console.log('End');
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* foo();
|
|
9
22
|
*/
|
|
10
23
|
function delay(ms) {
|
|
11
24
|
return new Promise(function (resolve) {
|
|
@@ -1,42 +1,9 @@
|
|
|
1
|
-
function _iterableToArrayLimit(r, l) {
|
|
2
|
-
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
3
|
-
if (null != t) {
|
|
4
|
-
var e,
|
|
5
|
-
n,
|
|
6
|
-
i,
|
|
7
|
-
u,
|
|
8
|
-
a = [],
|
|
9
|
-
f = !0,
|
|
10
|
-
o = !1;
|
|
11
|
-
try {
|
|
12
|
-
if (i = (t = t.call(r)).next, 0 === l) {
|
|
13
|
-
if (Object(t) !== t) return;
|
|
14
|
-
f = !1;
|
|
15
|
-
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
16
|
-
} catch (r) {
|
|
17
|
-
o = !0, n = r;
|
|
18
|
-
} finally {
|
|
19
|
-
try {
|
|
20
|
-
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
21
|
-
} finally {
|
|
22
|
-
if (o) throw n;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return a;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function _slicedToArray(arr, i) {
|
|
29
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
30
|
-
}
|
|
31
1
|
function _toConsumableArray(arr) {
|
|
32
2
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
33
3
|
}
|
|
34
4
|
function _arrayWithoutHoles(arr) {
|
|
35
5
|
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
36
6
|
}
|
|
37
|
-
function _arrayWithHoles(arr) {
|
|
38
|
-
if (Array.isArray(arr)) return arr;
|
|
39
|
-
}
|
|
40
7
|
function _iterableToArray(iter) {
|
|
41
8
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
42
9
|
}
|
|
@@ -56,9 +23,6 @@ function _arrayLikeToArray(arr, len) {
|
|
|
56
23
|
function _nonIterableSpread() {
|
|
57
24
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
58
25
|
}
|
|
59
|
-
function _nonIterableRest() {
|
|
60
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
61
|
-
}
|
|
62
26
|
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
63
27
|
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
64
28
|
if (!it) {
|
|
@@ -111,4 +75,4 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
|
111
75
|
};
|
|
112
76
|
}
|
|
113
77
|
|
|
114
|
-
export { _arrayLikeToArray as arrayLikeToArray,
|
|
78
|
+
export { _arrayLikeToArray as arrayLikeToArray, _arrayWithoutHoles as arrayWithoutHoles, _createForOfIteratorHelper as createForOfIteratorHelper, _iterableToArray as iterableToArray, _nonIterableSpread as nonIterableSpread, _toConsumableArray as toConsumableArray, _unsupportedIterableToArray as unsupportedIterableToArray };
|
package/esm/array/chunk.mjs
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
import { createForOfIteratorHelper as _createForOfIteratorHelper, slicedToArray as _slicedToArray } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
2
|
+
* Splits an array into smaller arrays of a specified length.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an input array and divides it into multiple smaller arrays,
|
|
5
|
+
* each of a specified length. If the input array cannot be evenly divided,
|
|
6
|
+
* the final sub-array will contain the remaining elements.
|
|
7
|
+
*
|
|
8
|
+
* @template T The type of elements in the array.
|
|
9
|
+
* @param {T[]} arr - The array to be chunked into smaller arrays.
|
|
10
|
+
* @param {number} size - The size of each smaller array. Must be a positive integer.
|
|
11
|
+
* @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.
|
|
12
|
+
* @throws {Error} Throws an error if `size` is not a positive integer.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Splits an array of numbers into sub-arrays of length 2
|
|
16
|
+
* chunk([1, 2, 3, 4, 5], 2);
|
|
17
|
+
* // Returns: [[1, 2], [3, 4], [5]]
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Splits an array of strings into sub-arrays of length 3
|
|
21
|
+
* chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);
|
|
22
|
+
* // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
|
|
9
23
|
*/
|
|
10
24
|
function chunk(arr, size) {
|
|
11
25
|
if (!Number.isInteger(size) || size <= 0) {
|
|
12
|
-
throw new Error(
|
|
26
|
+
throw new Error('Size must be an integer greater than zero.');
|
|
13
27
|
}
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
index = _step$value[0],
|
|
21
|
-
item = _step$value[1];
|
|
22
|
-
if (index % size === 0) {
|
|
23
|
-
result.push([]);
|
|
24
|
-
}
|
|
25
|
-
result[result.length - 1].push(item);
|
|
26
|
-
}
|
|
27
|
-
} catch (err) {
|
|
28
|
-
_iterator.e(err);
|
|
29
|
-
} finally {
|
|
30
|
-
_iterator.f();
|
|
28
|
+
var chunkLength = Math.ceil(arr.length / size);
|
|
29
|
+
var result = Array(chunkLength);
|
|
30
|
+
for (var index = 0; index < chunkLength; index++) {
|
|
31
|
+
var start = index * size;
|
|
32
|
+
var end = start + size;
|
|
33
|
+
result[index] = arr.slice(start, end);
|
|
31
34
|
}
|
|
32
35
|
return result;
|
|
33
36
|
}
|
package/esm/array/difference.mjs
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Computes the difference between two arrays.
|
|
3
|
+
*
|
|
4
|
+
* This function takes two arrays and returns a new array containing the elements
|
|
5
|
+
* that are present in the first array but not in the second array. It effectively
|
|
6
|
+
* filters out any elements from the first array that also appear in the second array.
|
|
7
|
+
*
|
|
8
|
+
* @template T
|
|
9
|
+
* @param {T[]} firstArr - The array from which to derive the difference. This is the primary array
|
|
10
|
+
* from which elements will be compared and filtered.
|
|
11
|
+
* @param {T[]} secondArr - The array containing elements to be excluded from the first array.
|
|
12
|
+
* Each element in this array will be checked against the first array, and if a match is found,
|
|
13
|
+
* that element will be excluded from the result.
|
|
14
|
+
* @returns {T[]} A new array containing the elements that are present in the first array but not
|
|
15
|
+
* in the second array.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* * const array1 = [1, 2, 3, 4, 5];
|
|
19
|
+
* const array2 = [2, 4];
|
|
20
|
+
* const result = difference(array1, array2);
|
|
21
|
+
* // result will be [1, 3, 5] since 2 and 4 are in both arrays and are excluded from the result.
|
|
6
22
|
*/
|
|
7
23
|
function difference(firstArr, secondArr) {
|
|
8
24
|
return firstArr.filter(function (item) {
|
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Computes the difference between two arrays after mapping their elements through a provided function.
|
|
3
|
+
*
|
|
4
|
+
* This function takes two arrays and a mapper function. It returns a new array containing the elements
|
|
5
|
+
* that are present in the first array but not in the second array, based on the identity calculated
|
|
6
|
+
* by the mapper function.
|
|
7
|
+
*
|
|
8
|
+
* Essentially, it filters out any elements from the first array that, when
|
|
9
|
+
* mapped, match an element in the mapped version of the second array.
|
|
10
|
+
*
|
|
11
|
+
* @template T, U
|
|
12
|
+
* @param {T[]} firstArr - The primary array from which to derive the difference.
|
|
13
|
+
* @param {T[]} secondArr - The array containing elements to be excluded from the first array.
|
|
14
|
+
* @param {(value: T) => U} mapper - The function to map the elements of both arrays. This function
|
|
15
|
+
* is applied to each element in both arrays, and the comparison is made based on the mapped values.
|
|
16
|
+
* @returns {T[]} A new array containing the elements from the first array that do not have a corresponding
|
|
17
|
+
* mapped identity in the second array.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
21
|
+
* const array2 = [{ id: 2 }, { id: 4 }];
|
|
22
|
+
* const mapper = item => item.id;
|
|
23
|
+
* const result = differenceBy(array1, array2, mapper);
|
|
24
|
+
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are in both arrays and are excluded from the result.
|
|
7
25
|
*/
|
|
8
26
|
function differenceBy(firstArr, secondArr, mapper) {
|
|
9
27
|
var mappedSecondArr = secondArr.map(function (item) {
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Computes the difference between two arrays based on a custom equality function.
|
|
3
|
+
*
|
|
4
|
+
* This function takes two arrays and a custom comparison function. It returns a new array containing
|
|
5
|
+
* the elements that are present in the first array but not in the second array. The comparison to determine
|
|
6
|
+
* if elements are equal is made using the provided custom function.
|
|
7
|
+
*
|
|
8
|
+
* @template T
|
|
9
|
+
* @param {T[]} firstArr - The array from which to get the difference.
|
|
10
|
+
* @param {T[]} secondArr - The array containing elements to exclude from the first array.
|
|
11
|
+
* @param {(x: T, y: T) => boolean} areItemsEqual - A function to determine if two items are equal.
|
|
12
|
+
* @returns {T[]} A new array containing the elements from the first array that do not match any elements in the second array
|
|
13
|
+
* according to the custom equality function.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
17
|
+
* const array2 = [{ id: 2 }, { id: 4 }];
|
|
18
|
+
* const areItemsEqual = (a, b) => a.id === b.id;
|
|
19
|
+
* const result = differenceWith(array1, array2, areItemsEqual);
|
|
20
|
+
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are considered equal and are excluded from the result.
|
|
7
21
|
*/
|
|
8
22
|
function differenceWith(firstArr, secondArr, areItemsEqual) {
|
|
9
23
|
return firstArr.filter(function (firstItem) {
|
package/esm/array/drop.mjs
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Removes a specified number of elements from the beginning of an array and returns the rest.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array and a number, and returns a new array with the specified number
|
|
5
|
+
* of elements removed from the start.
|
|
6
|
+
*
|
|
7
|
+
* @param {T[]} arr - The array from which to drop elements.
|
|
8
|
+
* @param {number} itemsCount - The number of elements to drop from the beginning of the array.
|
|
9
|
+
* @returns {T[]} A new array with the specified number of elements removed from the start.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* * const array = [1, 2, 3, 4, 5];
|
|
13
|
+
* const result = drop(array, 2);
|
|
14
|
+
* // result will be [3, 4, 5] since the first two elements are dropped.
|
|
6
15
|
*/
|
|
7
16
|
function drop(arr, itemsCount) {
|
|
8
17
|
return arr.slice(itemsCount);
|
package/esm/array/dropRight.mjs
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Removes a specified number of elements from the end of an array and returns the rest.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array and a number, and returns a new array with the specified number
|
|
5
|
+
* of elements removed from the end.
|
|
6
|
+
*
|
|
7
|
+
* @param {T[]} arr - The array from which to drop elements.
|
|
8
|
+
* @param {number} itemsCount - The number of elements to drop from the end of the array.
|
|
9
|
+
* @returns {T[]} A new array with the specified number of elements removed from the end.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* * const array = [1, 2, 3, 4, 5];
|
|
13
|
+
* const result = dropRight(array, 2);
|
|
14
|
+
* // result will be [1, 2, 3] since the last two elements are dropped.
|
|
6
15
|
*/
|
|
7
16
|
function dropRight(arr, itemsCount) {
|
|
8
17
|
return arr.slice(0, -itemsCount);
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { dropWhile } from './dropWhile.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Removes elements from the end of an array until the predicate returns false.
|
|
5
|
+
*
|
|
6
|
+
* This function iterates over an array from the end and drops elements until the provided
|
|
7
|
+
* predicate function returns false. It then returns a new array with the remaining elements.
|
|
8
|
+
*
|
|
9
|
+
* @param {T[]} arr - The array from which to drop elements.
|
|
10
|
+
* @param {function(item: T): boolean} canContinueDropping - A predicate function that determines
|
|
11
|
+
* whether to continue dropping elements. The function is called with each element from the end,
|
|
12
|
+
* and dropping continues as long as it returns true.
|
|
13
|
+
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const array = [1, 2, 3, 4, 5];
|
|
17
|
+
* const result = dropRightWhile(array, x => x > 3);
|
|
18
|
+
* // result will be [1, 2, 3] since elements greater than 3 are dropped from the end.
|
|
8
19
|
*/
|
|
9
20
|
function dropRightWhile(arr, canContinueDropping) {
|
|
10
21
|
var reversed = arr.slice().reverse();
|
package/esm/array/dropWhile.mjs
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Removes elements from the beginning of an array until the predicate returns false.
|
|
3
|
+
*
|
|
4
|
+
* This function iterates over an array and drops elements from the start until the provided
|
|
5
|
+
* predicate function returns false. It then returns a new array with the remaining elements.
|
|
6
|
+
*
|
|
7
|
+
* @param {T[]} arr - The array from which to drop elements.
|
|
8
|
+
* @param {(item: T) => boolean} canContinueDropping - A predicate function that determines
|
|
9
|
+
* whether to continue dropping elements. The function is called with each element, and dropping
|
|
10
|
+
* continues as long as it returns true.
|
|
11
|
+
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const array = [1, 2, 3, 4, 5];
|
|
15
|
+
* const result = dropWhile(array, x => x < 3);
|
|
16
|
+
* // result will be [3, 4, 5] since elements less than 3 are dropped.
|
|
6
17
|
*/
|
|
7
18
|
function dropWhile(arr, canContinueDropping) {
|
|
8
19
|
var dropEndIndex = arr.findIndex(function (item) {
|
package/esm/array/groupBy.mjs
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createForOfIteratorHelper as _createForOfIteratorHelper } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Groups the elements of an array based on a provided key-generating function.
|
|
5
|
+
*
|
|
6
|
+
* This function takes an array and a function that generates a key from each element. It returns
|
|
7
|
+
* an object where the keys are the generated keys and the values are arrays of elements that share
|
|
8
|
+
* the same key.
|
|
9
|
+
*
|
|
10
|
+
* @param {T[]} arr - The array to group.
|
|
11
|
+
* @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.
|
|
12
|
+
* @returns {Record<K, T[]>} An object where each key is associated with an array of elements that
|
|
13
|
+
* share that key.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const array = [
|
|
17
|
+
* { category: 'fruit', name: 'apple' },
|
|
18
|
+
* { category: 'fruit', name: 'banana' },
|
|
19
|
+
* { category: 'vegetable', name: 'carrot' }
|
|
20
|
+
* ];
|
|
21
|
+
* const result = groupBy(array, item => item.category);
|
|
22
|
+
* // result will be:
|
|
23
|
+
* // {
|
|
24
|
+
* // fruit: [
|
|
25
|
+
* // { category: 'fruit', name: 'apple' },
|
|
26
|
+
* // { category: 'fruit', name: 'banana' }
|
|
27
|
+
* // ],
|
|
28
|
+
* // vegetable: [
|
|
29
|
+
* // { category: 'vegetable', name: 'carrot' }
|
|
30
|
+
* // ]
|
|
31
|
+
* // }
|
|
32
|
+
*/
|
|
33
|
+
function groupBy(arr, getKeyFromItem) {
|
|
34
|
+
var result = {};
|
|
35
|
+
var _iterator = _createForOfIteratorHelper(arr),
|
|
36
|
+
_step;
|
|
37
|
+
try {
|
|
38
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
39
|
+
var item = _step.value;
|
|
40
|
+
var key = getKeyFromItem(item);
|
|
41
|
+
if (result[key] == null) {
|
|
42
|
+
result[key] = [];
|
|
43
|
+
}
|
|
44
|
+
result[key].push(item);
|
|
45
|
+
}
|
|
46
|
+
} catch (err) {
|
|
47
|
+
_iterator.e(err);
|
|
48
|
+
} finally {
|
|
49
|
+
_iterator.f();
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
3
52
|
}
|
|
4
53
|
|
|
5
54
|
export { groupBy };
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @name intersection
|
|
3
|
-
* @description
|
|
4
2
|
* Returns the intersection of two arrays.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* This function takes two arrays and returns a new array containing the elements that are
|
|
5
|
+
* present in both arrays. It effectively filters out any elements from the first array that
|
|
6
|
+
* are not found in the second array.
|
|
7
|
+
*
|
|
8
|
+
* @param {T[]} firstArr - The first array to compare.
|
|
9
|
+
* @param {T[]} secondArr - The second array to compare.
|
|
10
|
+
* @returns {T[]} A new array containing the elements that are present in both arrays.
|
|
11
|
+
*
|
|
7
12
|
* @example
|
|
8
|
-
*
|
|
9
|
-
*
|
|
13
|
+
* const array1 = [1, 2, 3, 4, 5];
|
|
14
|
+
* const array2 = [3, 4, 5, 6, 7];
|
|
15
|
+
* const result = intersection(array1, array2);
|
|
16
|
+
* // result will be [3, 4, 5] since these elements are in both arrays.
|
|
10
17
|
*/
|
|
11
18
|
function intersection(firstArr, secondArr) {
|
|
12
19
|
return firstArr.filter(function (item) {
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
2
|
+
* Returns the intersection of two arrays based on a mapping function.
|
|
3
|
+
*
|
|
4
|
+
* This function takes two arrays and a mapping function. It returns a new array containing
|
|
5
|
+
* the elements from the first array that, when mapped using the provided function, have matching
|
|
6
|
+
* mapped elements in the second array. It effectively filters out any elements from the first array
|
|
7
|
+
* that do not have corresponding mapped values in the second array.
|
|
8
|
+
*
|
|
9
|
+
* @param {T[]} firstArr - The first array to compare.
|
|
10
|
+
* @param {T[]} secondArr - The second array to compare.
|
|
11
|
+
* @param {(item: T) => U} mapper - A function to map the elements of both arrays for comparison.
|
|
12
|
+
* @returns {T[]} A new array containing the elements from the first array that have corresponding mapped values in the second array.
|
|
13
|
+
*
|
|
8
14
|
* @example
|
|
9
|
-
*
|
|
10
|
-
*
|
|
15
|
+
* const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
16
|
+
* const array2 = [{ id: 2 }, { id: 4 }];
|
|
17
|
+
* const mapper = item => item.id;
|
|
18
|
+
* const result = intersectionBy(array1, array2, mapper);
|
|
19
|
+
* // result will be [{ id: 2 }] since only this element has a matching id in both arrays.
|
|
11
20
|
*/
|
|
12
21
|
function intersectionBy(firstArr, secondArr, mapper) {
|
|
13
22
|
var mappedSecondArr = secondArr.map(function (x) {
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
2
|
+
* Returns the intersection of two arrays based on a custom equality function.
|
|
3
|
+
*
|
|
4
|
+
* This function takes two arrays and a custom equality function. It returns a new array containing
|
|
5
|
+
* the elements from the first array that have matching elements in the second array, as determined
|
|
6
|
+
* by the custom equality function. It effectively filters out any elements from the first array that
|
|
7
|
+
* do not have corresponding matches in the second array according to the equality function.
|
|
8
|
+
*
|
|
9
|
+
* @param {T[]} firstArr - The first array to compare.
|
|
10
|
+
* @param {T[]} secondArr - The second array to compare.
|
|
11
|
+
* @param {(x: T, y: T) => boolean} areItemsEqual - A custom function to determine if two elements are equal.
|
|
12
|
+
* This function takes two arguments, one from each array, and returns `true` if the elements are considered equal, and `false` otherwise.
|
|
13
|
+
* @returns {T[]} A new array containing the elements from the first array that have corresponding matches in the second array according to the custom equality function.
|
|
14
|
+
*
|
|
8
15
|
* @example
|
|
9
|
-
*
|
|
10
|
-
*
|
|
16
|
+
* * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
17
|
+
* const array2 = [{ id: 2 }, { id: 4 }];
|
|
18
|
+
* const areItemsEqual = (a, b) => a.id === b.id;
|
|
19
|
+
* const result = intersectionWith(array1, array2, areItemsEqual);
|
|
20
|
+
* // result will be [{ id: 2 }] since this element has a matching id in both arrays.
|
|
11
21
|
*/
|
|
12
22
|
function intersectionWith(firstArr, secondArr, areItemsEqual) {
|
|
13
23
|
return firstArr.filter(function (firstItem) {
|
package/esm/array/partition.mjs
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import { createForOfIteratorHelper as _createForOfIteratorHelper } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Splits an array into two groups based on a predicate function.
|
|
5
|
+
*
|
|
6
|
+
* This function takes an array and a predicate function. It returns a tuple of two arrays:
|
|
7
|
+
* the first array contains elements for which the predicate function returns true, and
|
|
8
|
+
* the second array contains elements for which the predicate function returns false.
|
|
9
|
+
*
|
|
10
|
+
* @param {T[]} arr - The array to partition.
|
|
11
|
+
* @param {(value: T) => boolean} isInTruthy - A predicate function that determines
|
|
12
|
+
* whether an element should be placed in the truthy array. The function is called with each
|
|
13
|
+
* element of the array.
|
|
14
|
+
* @returns {[T[], T[]]} A tuple containing two arrays: the first array contains elements for
|
|
15
|
+
* which the predicate returned true, and the second array contains elements for which the
|
|
16
|
+
* predicate returned false.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const array = [1, 2, 3, 4, 5];
|
|
20
|
+
* const isEven = x => x % 2 === 0;
|
|
21
|
+
* const [even, odd] = partition(array, isEven);
|
|
22
|
+
* // even will be [2, 4], and odd will be [1, 3, 5]
|
|
9
23
|
*/
|
|
10
24
|
function partition(arr, isInTruthy) {
|
|
11
25
|
var truthy = [];
|
package/esm/array/sample.mjs
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @name sample
|
|
3
|
-
* @description
|
|
4
2
|
* Returns a random element from an array.
|
|
5
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array and returns a single element selected randomly from the array.
|
|
5
|
+
*
|
|
6
|
+
* @param {T[]} arr - The array to sample from.
|
|
7
|
+
* @returns {T} A random element from the array.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const array = [1, 2, 3, 4, 5];
|
|
11
|
+
* const randomElement = sample(array);
|
|
12
|
+
* // randomElement will be one of the elements from the array, selected randomly.
|
|
6
13
|
*/
|
|
7
14
|
function sample(arr) {
|
|
8
15
|
var randomIndex = Math.floor(Math.random() * arr.length);
|