es-toolkit 0.0.1 → 1.0.0-dev.24
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,11 +1,18 @@
|
|
|
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
|
export declare function intersection<T>(firstArr: T[], secondArr: T[]): T[];
|
|
@@ -1,12 +1,21 @@
|
|
|
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
|
export declare function intersectionBy<T, U>(firstArr: T[], secondArr: T[], mapper: (item: T) => U): T[];
|
|
@@ -1,12 +1,22 @@
|
|
|
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
|
export declare function intersectionWith<T>(firstArr: T[], secondArr: T[], areItemsEqual: (x: T, y: T) => boolean): T[];
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Splits an array into two groups based on a predicate function.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array and a predicate function. It returns a tuple of two arrays:
|
|
5
|
+
* the first array contains elements for which the predicate function returns true, and
|
|
6
|
+
* the second array contains elements for which the predicate function returns false.
|
|
7
|
+
*
|
|
8
|
+
* @param {T[]} arr - The array to partition.
|
|
9
|
+
* @param {(value: T) => boolean} isInTruthy - A predicate function that determines
|
|
10
|
+
* whether an element should be placed in the truthy array. The function is called with each
|
|
11
|
+
* element of the array.
|
|
12
|
+
* @returns {[T[], T[]]} A tuple containing two arrays: the first array contains elements for
|
|
13
|
+
* which the predicate returned true, and the second array contains elements for which the
|
|
14
|
+
* predicate returned false.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const array = [1, 2, 3, 4, 5];
|
|
18
|
+
* const isEven = x => x % 2 === 0;
|
|
19
|
+
* const [even, odd] = partition(array, isEven);
|
|
20
|
+
* // even will be [2, 4], and odd will be [1, 3, 5]
|
|
7
21
|
*/
|
|
8
22
|
export declare function partition<T>(arr: T[], isInTruthy: (value: T) => boolean): [truthy: T[], falsy: T[]];
|
package/dist/array/sample.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
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
|
export declare function sample<T>(arr: T[]): T;
|
package/dist/array/shuffle.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Randomizes the order of elements in an array using the Fisher-Yates algorithm.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array and returns a new array with its elements shuffled in a random order.
|
|
5
|
+
*
|
|
6
|
+
* @param {T[]} arr - The array to shuffle.
|
|
7
|
+
* @returns {T[]} A new array with its elements shuffled in random order.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const array = [1, 2, 3, 4, 5];
|
|
11
|
+
* const shuffledArray = shuffle(array);
|
|
12
|
+
* // shuffledArray will be a new array with elements of array in random order, e.g., [3, 1, 4, 5, 2]
|
|
6
13
|
*/
|
|
7
14
|
export declare function shuffle<T>(arr: T[]): T[];
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Returns a new array containing the last `count` elements from the input array `arr`.
|
|
3
3
|
* If `count` is greater than the length of `arr`, the entire array is returned.
|
|
4
4
|
*
|
|
5
|
-
* @template T - Type of elements in the input array.
|
|
6
|
-
*
|
|
7
5
|
* @param {T[]} arr - The array to take elements from.
|
|
8
6
|
* @param {number} count - The number of elements to take.
|
|
9
7
|
* @returns {T[]} A new array containing the last `count` elements from `arr`.
|
package/dist/array/union.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Creates an array of unique values from all given arrays.
|
|
3
|
+
*
|
|
4
|
+
* This function takes two arrays, merges them into a single array, and returns a new array
|
|
5
|
+
* containing only the unique values from the merged array.
|
|
6
|
+
*
|
|
7
|
+
* @param {T[]} arr1 - The first array to merge and filter for unique values.
|
|
8
|
+
* @param {T[]} arr2 - The second array to merge and filter for unique values.
|
|
9
|
+
* @returns {T[]} A new array of unique values.
|
|
3
10
|
*
|
|
4
11
|
* @example
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
12
|
+
* const array1 = [1, 2, 3];
|
|
13
|
+
* const array2 = [3, 4, 5];
|
|
14
|
+
* const result = union(array1, array2);
|
|
15
|
+
* // result will be [1, 2, 3, 4, 5]
|
|
9
16
|
*/
|
|
10
|
-
export declare function union<T>(
|
|
17
|
+
export declare function union<T>(arr1: T[], arr2: T[]): T[];
|
package/dist/array/unionBy.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Creates an array of unique values, in order, from all given arrays using a provided mapping function to determine equality.
|
|
3
3
|
*
|
|
4
|
-
* @template T - Type of elements in the input arrays.
|
|
5
|
-
* @template U - Type of the values returned by the mapping function.
|
|
6
|
-
*
|
|
7
4
|
* @param {T[]} arr1 - The first array.
|
|
8
5
|
* @param {T[]} arr2 - The second array.
|
|
9
6
|
* @param {function(item: T): U} mapper - The function to map array elements to comparison values.
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Creates an array of unique values from two given arrays based on a custom equality function.
|
|
3
|
+
*
|
|
4
|
+
* This function takes two arrays and a custom equality function, merges the arrays, and returns
|
|
5
|
+
* a new array containing only the unique values as determined by the custom equality function.
|
|
6
|
+
*
|
|
7
|
+
* @param {T[]} arr1 - The first array to merge and filter for unique values.
|
|
8
|
+
* @param {T[]} arr2 - The second array to merge and filter for unique values.
|
|
9
|
+
* @param {(item1: T, item2: T) => boolean} areItemsEqual - A custom function to determine if two elements are equal.
|
|
10
|
+
* It takes two arguments and returns `true` if the elements are considered equal, and `false` otherwise.
|
|
11
|
+
* @returns {T[]} A new array of unique values based on the custom equality function.
|
|
3
12
|
*
|
|
4
13
|
* @example
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* );
|
|
11
|
-
* // [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
|
|
12
|
-
* ```
|
|
14
|
+
* const array1 = [{ id: 1 }, { id: 2 }];
|
|
15
|
+
* const array2 = [{ id: 2 }, { id: 3 }];
|
|
16
|
+
* const areItemsEqual = (a, b) => a.id === b.id;
|
|
17
|
+
* const result = unionWith(array1, array2, areItemsEqual);
|
|
18
|
+
* // result will be [{ id: 1 }, { id: 2 }, { id: 3 }] since { id: 2 } is considered equal in both arrays
|
|
13
19
|
*/
|
|
14
20
|
export declare function unionWith<T>(arr1: T[], arr2: T[], areItemsEqual: (item1: T, item2: T) => boolean): T[];
|
package/dist/array/uniq.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @description
|
|
4
|
-
* `uniq` removes duplicated elements from the array given as an argument.
|
|
2
|
+
* Creates a duplicate-free version of an array.
|
|
5
3
|
*
|
|
6
|
-
*
|
|
4
|
+
* This function takes an array and returns a new array containing only the unique values
|
|
5
|
+
* from the original array, preserving the order of first occurrence.
|
|
6
|
+
*
|
|
7
|
+
* @param {T[]} arr - The array to process.
|
|
8
|
+
* @returns {T[]} A new array with only unique values from the original array.
|
|
7
9
|
*
|
|
8
10
|
* @example
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* // [1, 2, 3,
|
|
12
|
-
* ```
|
|
11
|
+
* * const array = [1, 2, 2, 3, 4, 4, 5];
|
|
12
|
+
* const result = uniq(array);
|
|
13
|
+
* // result will be [1, 2, 3, 4, 5]
|
|
13
14
|
*/
|
|
14
15
|
export declare function uniq<T>(arr: T[]): T[];
|
package/dist/array/xor.d.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Computes the symmetric difference between two arrays. The symmetric difference is the set of elements
|
|
3
3
|
* which are in either of the arrays, but not in their intersection.
|
|
4
4
|
*
|
|
5
|
-
* @template T - Type of elements in the input arrays.
|
|
6
|
-
*
|
|
7
5
|
* @param {T[]} arr1 - The first array.
|
|
8
6
|
* @param {T[]} arr2 - The second array.
|
|
9
7
|
* @returns {T[]} An array containing the elements that are present in either `arr1` or `arr2` but not in both.
|
package/dist/array/zip.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* elements from the input arrays at the corresponding index.
|
|
2
|
+
* Combines multiple arrays into a single array of tuples.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* This function takes multiple arrays and returns a new array where each element is a tuple
|
|
5
|
+
* containing the corresponding elements from the input arrays. If the input arrays are of
|
|
6
|
+
* different lengths, the resulting array will have the length of the longest input array,
|
|
7
|
+
* with undefined values for missing elements.
|
|
8
|
+
*
|
|
9
|
+
* @param {...T[][]} arrs - The arrays to zip together.
|
|
10
|
+
* @returns {T[][]} A new array of tuples containing the corresponding elements from the input arrays.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const arr1 = [1, 2, 3];
|
|
14
|
+
* const arr2 = ['a', 'b', 'c'];
|
|
15
|
+
* const result = zip(arr1, arr2);
|
|
16
|
+
* // result will be [[1, 'a'], [2, 'b'], [3, 'c']]
|
|
17
|
+
*
|
|
18
|
+
* const arr3 = [true, false];
|
|
19
|
+
* const result2 = zip(arr1, arr2, arr3);
|
|
20
|
+
* // result2 will be [[1, 'a', true], [2, 'b', false], [3, 'c', undefined]]
|
|
9
21
|
*/
|
|
10
22
|
export declare function zip<T>(arr1: T[]): [T][];
|
|
11
23
|
export declare function zip<T, U>(arr1: T[], arr2: U[]): [T, U][];
|
package/dist/array/zipWith.d.ts
CHANGED
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Combines multiple arrays
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Combines multiple arrays into a single array using a custom combiner function.
|
|
3
|
+
*
|
|
4
|
+
* This function takes multiple arrays and a combiner function, and returns a new array where each element
|
|
5
|
+
* is the result of applying the combiner function to the corresponding elements of the input arrays.
|
|
6
|
+
*
|
|
7
|
+
* @param {T[]} arr1 - The first array to zip.
|
|
8
|
+
* @param {U[]} [arr2] - The second array to zip (optional).
|
|
9
|
+
* @param {V[]} [arr3] - The third array to zip (optional).
|
|
10
|
+
* @param {W[]} [arr4] - The fourth array to zip (optional).
|
|
11
|
+
* @param {function} combine - The combiner function that takes corresponding elements from each array and returns a single value.
|
|
12
|
+
* @returns {R[]} A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Example usage with two arrays:
|
|
16
|
+
* const arr1 = [1, 2, 3];
|
|
17
|
+
* const arr2 = [4, 5, 6];
|
|
18
|
+
* const result = zipWith(arr1, arr2, (a, b) => a + b);
|
|
19
|
+
* // result will be [5, 7, 9]
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Example usage with three arrays:
|
|
23
|
+
* const arr1 = [1, 2];
|
|
24
|
+
* const arr2 = [3, 4];
|
|
25
|
+
* const arr3 = [5, 6];
|
|
26
|
+
* const result = zipWith(arr1, arr2, arr3, (a, b, c) => `${a}${b}${c}`);
|
|
27
|
+
* // result will be [`135`, `246`]
|
|
5
28
|
*/
|
|
6
29
|
export declare function zipWith<T, R>(arr1: T[], combine: (item: T) => R): R[];
|
|
7
30
|
export declare function zipWith<T, U, R>(arr1: T[], arr2: U[], combine: (item1: T, item2: U) => R): R[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Creates a debounced function that delays invoking the provided function until after `
|
|
2
|
+
* Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
|
|
3
3
|
* have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`
|
|
4
4
|
* method to cancel any pending execution.
|
|
5
5
|
*
|
|
6
6
|
* @param {() => void} func - The function to debounce.
|
|
7
|
-
* @param {number}
|
|
7
|
+
* @param {number} debounceMs - The number of milliseconds to delay.
|
|
8
8
|
* @returns {{ (): void; cancel: () => void }} A new debounced function with a `cancel` method.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* // Will not log anything as the previous call is canceled
|
|
19
19
|
* debouncedFunction.cancel();
|
|
20
20
|
*/
|
|
21
|
-
export declare function debounce(func: () => void,
|
|
21
|
+
export declare function debounce(func: () => void, debounceMs: number): {
|
|
22
22
|
(): void;
|
|
23
|
-
cancel()
|
|
23
|
+
cancel: () => void;
|
|
24
24
|
};
|
package/dist/function/index.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Creates a debounced function that delays invoking the provided function until after `
|
|
6
|
+
* Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
|
|
7
7
|
* have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`
|
|
8
8
|
* method to cancel any pending execution.
|
|
9
9
|
*
|
|
10
10
|
* @param {() => void} func - The function to debounce.
|
|
11
|
-
* @param {number}
|
|
11
|
+
* @param {number} debounceMs - The number of milliseconds to delay.
|
|
12
12
|
* @returns {{ (): void; cancel: () => void }} A new debounced function with a `cancel` method.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
@@ -22,7 +22,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
22
22
|
* // Will not log anything as the previous call is canceled
|
|
23
23
|
* debouncedFunction.cancel();
|
|
24
24
|
*/
|
|
25
|
-
function debounce(func,
|
|
25
|
+
function debounce(func, debounceMs) {
|
|
26
26
|
var timeoutId = null;
|
|
27
27
|
var debounced = function debounced() {
|
|
28
28
|
if (timeoutId != null) {
|
|
@@ -30,7 +30,7 @@ function debounce(func, waitMs) {
|
|
|
30
30
|
}
|
|
31
31
|
timeoutId = setTimeout(function () {
|
|
32
32
|
func();
|
|
33
|
-
},
|
|
33
|
+
}, debounceMs);
|
|
34
34
|
};
|
|
35
35
|
debounced.cancel = function () {
|
|
36
36
|
if (timeoutId != null) {
|
|
@@ -44,7 +44,6 @@ function debounce(func, waitMs) {
|
|
|
44
44
|
* Creates a function that is restricted to invoking the provided function `func` once.
|
|
45
45
|
* Repeated calls to the function will return the value from the first invocation.
|
|
46
46
|
*
|
|
47
|
-
* @template F - The type of the function to be invoked once.
|
|
48
47
|
* @param {F} func - The function to restrict.
|
|
49
48
|
* @returns {F} A new function that invokes `func` once and caches the result.
|
|
50
49
|
*
|
package/dist/function/once.d.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Creates a function that is restricted to invoking the provided function `func` once.
|
|
3
3
|
* Repeated calls to the function will return the value from the first invocation.
|
|
4
4
|
*
|
|
5
|
-
* @template F - The type of the function to be invoked once.
|
|
6
5
|
* @param {F} func - The function to restrict.
|
|
7
6
|
* @returns {F} A new function that invokes `func` once and caches the result.
|
|
8
7
|
*
|