es-toolkit 0.0.1
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/.vscode/extensions.json +7 -0
- package/.vscode/settings.json +10 -0
- package/.yarn/sdks/eslint/bin/eslint.js +20 -0
- package/.yarn/sdks/eslint/lib/api.js +20 -0
- package/.yarn/sdks/eslint/lib/unsupported-api.js +20 -0
- package/.yarn/sdks/eslint/package.json +14 -0
- package/.yarn/sdks/integrations.yml +5 -0
- package/.yarn/sdks/prettier/bin/prettier.cjs +20 -0
- package/.yarn/sdks/prettier/index.cjs +20 -0
- package/.yarn/sdks/prettier/package.json +7 -0
- package/.yarn/sdks/typescript/bin/tsc +20 -0
- package/.yarn/sdks/typescript/bin/tsserver +20 -0
- package/.yarn/sdks/typescript/lib/tsc.js +20 -0
- package/.yarn/sdks/typescript/lib/tsserver.js +225 -0
- package/.yarn/sdks/typescript/lib/tsserverlibrary.js +225 -0
- package/.yarn/sdks/typescript/lib/typescript.js +20 -0
- package/.yarn/sdks/typescript/package.json +10 -0
- package/babel.config.js +6 -0
- package/coverage/.tmp/coverage-0.json +1 -0
- package/coverage/.tmp/coverage-1.json +1 -0
- package/coverage/.tmp/coverage-10.json +1 -0
- package/coverage/.tmp/coverage-11.json +1 -0
- package/coverage/.tmp/coverage-12.json +1 -0
- package/coverage/.tmp/coverage-13.json +1 -0
- package/coverage/.tmp/coverage-14.json +1 -0
- package/coverage/.tmp/coverage-15.json +1 -0
- package/coverage/.tmp/coverage-16.json +1 -0
- package/coverage/.tmp/coverage-17.json +1 -0
- package/coverage/.tmp/coverage-18.json +1 -0
- package/coverage/.tmp/coverage-19.json +1 -0
- package/coverage/.tmp/coverage-2.json +1 -0
- package/coverage/.tmp/coverage-20.json +1 -0
- package/coverage/.tmp/coverage-21.json +1 -0
- package/coverage/.tmp/coverage-22.json +1 -0
- package/coverage/.tmp/coverage-23.json +1 -0
- package/coverage/.tmp/coverage-24.json +1 -0
- package/coverage/.tmp/coverage-25.json +1 -0
- package/coverage/.tmp/coverage-26.json +1 -0
- package/coverage/.tmp/coverage-27.json +1 -0
- package/coverage/.tmp/coverage-28.json +1 -0
- package/coverage/.tmp/coverage-29.json +1 -0
- package/coverage/.tmp/coverage-3.json +1 -0
- package/coverage/.tmp/coverage-30.json +1 -0
- package/coverage/.tmp/coverage-4.json +1 -0
- package/coverage/.tmp/coverage-5.json +1 -0
- package/coverage/.tmp/coverage-6.json +1 -0
- package/coverage/.tmp/coverage-7.json +1 -0
- package/coverage/.tmp/coverage-8.json +1 -0
- package/coverage/.tmp/coverage-9.json +1 -0
- package/dist/array/chunk.d.ts +8 -0
- package/dist/array/chunk.spec.d.ts +1 -0
- package/dist/array/difference.d.ts +7 -0
- package/dist/array/difference.spec.d.ts +1 -0
- package/dist/array/differenceBy.d.ts +8 -0
- package/dist/array/differenceBy.spec.d.ts +1 -0
- package/dist/array/differenceWith.d.ts +8 -0
- package/dist/array/differenceWith.spec.d.ts +1 -0
- package/dist/array/drop.d.ts +7 -0
- package/dist/array/drop.spec.d.ts +1 -0
- package/dist/array/dropRight.d.ts +7 -0
- package/dist/array/dropRight.spec.d.ts +1 -0
- package/dist/array/dropRightWhile.d.ts +7 -0
- package/dist/array/dropRightWhile.spec.d.ts +1 -0
- package/dist/array/dropWhile.d.ts +7 -0
- package/dist/array/dropWhile.spec.d.ts +1 -0
- package/dist/array/groupBy.d.ts +1 -0
- package/dist/array/index.d.ts +30 -0
- package/dist/array/index.js +778 -0
- package/dist/array/intersection.d.ts +11 -0
- package/dist/array/intersection.spec.d.ts +1 -0
- package/dist/array/intersectionBy.d.ts +12 -0
- package/dist/array/intersectionBy.spec.d.ts +1 -0
- package/dist/array/intersectionWith.d.ts +12 -0
- package/dist/array/intersectionWith.spec.d.ts +1 -0
- package/dist/array/partition.d.ts +8 -0
- package/dist/array/partition.spec.d.ts +1 -0
- package/dist/array/sample.d.ts +7 -0
- package/dist/array/sample.spec.d.ts +1 -0
- package/dist/array/shuffle.d.ts +7 -0
- package/dist/array/shuffle.spec.d.ts +1 -0
- package/dist/array/take.d.ts +23 -0
- package/dist/array/take.spec.d.ts +1 -0
- package/dist/array/takeRight.d.ts +23 -0
- package/dist/array/takeRight.spec.d.ts +1 -0
- package/dist/array/takeRightWhile.d.ts +18 -0
- package/dist/array/takeRightWhile.spec.d.ts +1 -0
- package/dist/array/takeWhile.d.ts +19 -0
- package/dist/array/takeWhile.spec.d.ts +1 -0
- package/dist/array/union.d.ts +10 -0
- package/dist/array/union.spec.d.ts +1 -0
- package/dist/array/unionBy.d.ts +24 -0
- package/dist/array/unionBy.spec.d.ts +1 -0
- package/dist/array/unionWith.d.ts +14 -0
- package/dist/array/unionWith.spec.d.ts +1 -0
- package/dist/array/uniq.d.ts +14 -0
- package/dist/array/uniq.spec.d.ts +1 -0
- package/dist/array/uniqBy.d.ts +12 -0
- package/dist/array/uniqBy.spec.d.ts +1 -0
- package/dist/array/uniqWith.d.ts +12 -0
- package/dist/array/uniqWith.spec.d.ts +1 -0
- package/dist/array/xor.d.ts +19 -0
- package/dist/array/xor.spec.d.ts +1 -0
- package/dist/array/xorBy.d.ts +20 -0
- package/dist/array/xorBy.spec.d.ts +1 -0
- package/dist/array/xorWith.d.ts +19 -0
- package/dist/array/xorWith.spec.d.ts +1 -0
- package/dist/array/zip.d.ts +13 -0
- package/dist/array/zip.spec.d.ts +1 -0
- package/dist/array/zipWith.d.ts +9 -0
- package/dist/array/zipWith.spec.d.ts +1 -0
- package/dist/function/debounce.d.ts +24 -0
- package/dist/function/debounce.spec.d.ts +1 -0
- package/dist/function/index.d.ts +3 -0
- package/dist/function/index.js +113 -0
- package/dist/function/once.d.ts +18 -0
- package/dist/function/once.spec.d.ts +1 -0
- package/dist/function/throttle.d.ts +26 -0
- package/dist/function/throttle.spec.d.ts +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1111 -0
- package/dist/math/clamp.d.ts +11 -0
- package/dist/math/clamp.spec.d.ts +1 -0
- package/dist/math/index.d.ts +3 -0
- package/dist/math/index.js +63 -0
- package/dist/math/round.d.ts +13 -0
- package/dist/math/round.spec.d.ts +1 -0
- package/dist/math/sum.d.ts +13 -0
- package/dist/math/sum.spec.d.ts +1 -0
- package/dist/object/index.d.ts +4 -0
- package/dist/object/index.js +176 -0
- package/dist/object/omit.d.ts +7 -0
- package/dist/object/omit.spec.d.ts +1 -0
- package/dist/object/omitBy.d.ts +1 -0
- package/dist/object/pick.d.ts +7 -0
- package/dist/object/pick.spec.d.ts +1 -0
- package/dist/object/pickBy.d.ts +1 -0
- package/dist/predicate/index.d.ts +4 -0
- package/dist/predicate/index.js +50 -0
- package/dist/predicate/isNil.d.ts +6 -0
- package/dist/predicate/isNil.spec.d.ts +1 -0
- package/dist/predicate/isNotNil.d.ts +12 -0
- package/dist/predicate/isNotNil.spec.d.ts +1 -0
- package/dist/predicate/isNull.d.ts +6 -0
- package/dist/predicate/isNull.spec.d.ts +1 -0
- package/dist/predicate/isUndefined.d.ts +6 -0
- package/dist/predicate/isUndefined.spec.d.ts +1 -0
- package/dist/promise/delay.d.ts +6 -0
- package/dist/promise/delay.spec.d.ts +1 -0
- package/dist/promise/index.d.ts +1 -0
- package/dist/promise/index.js +16 -0
- package/esm/_virtual/_rollupPluginBabelHelpers.mjs +163 -0
- package/esm/array/_virtual/_rollupPluginBabelHelpers.mjs +114 -0
- package/esm/array/chunk.mjs +35 -0
- package/esm/array/difference.mjs +13 -0
- package/esm/array/differenceBy.mjs +17 -0
- package/esm/array/differenceWith.mjs +16 -0
- package/esm/array/drop.mjs +11 -0
- package/esm/array/dropRight.mjs +11 -0
- package/esm/array/dropRightWhile.mjs +15 -0
- package/esm/array/dropWhile.mjs +14 -0
- package/esm/array/groupBy.mjs +5 -0
- package/esm/array/index.mjs +30 -0
- package/esm/array/intersection.mjs +17 -0
- package/esm/array/intersectionBy.mjs +21 -0
- package/esm/array/intersectionWith.mjs +20 -0
- package/esm/array/partition.mjs +32 -0
- package/esm/array/sample.mjs +12 -0
- package/esm/array/shuffle.mjs +20 -0
- package/esm/array/take.mjs +27 -0
- package/esm/array/takeRight.mjs +30 -0
- package/esm/array/takeRightWhile.mjs +27 -0
- package/esm/array/takeWhile.mjs +41 -0
- package/esm/array/union.mjs +19 -0
- package/esm/array/unionBy.mjs +38 -0
- package/esm/array/unionWith.mjs +21 -0
- package/esm/array/uniq.mjs +18 -0
- package/esm/array/uniqBy.mjs +20 -0
- package/esm/array/uniqWith.mjs +39 -0
- package/esm/array/xor.mjs +27 -0
- package/esm/array/xorBy.mjs +30 -0
- package/esm/array/xorWith.mjs +29 -0
- package/esm/array/zip.mjs +40 -0
- package/esm/array/zipWith.mjs +31 -0
- package/esm/function/debounce.mjs +39 -0
- package/esm/function/index.mjs +3 -0
- package/esm/function/once.mjs +32 -0
- package/esm/function/throttle.mjs +38 -0
- package/esm/index.mjs +45 -0
- package/esm/math/clamp.mjs +18 -0
- package/esm/math/index.mjs +3 -0
- package/esm/math/round.mjs +19 -0
- package/esm/math/sum.mjs +22 -0
- package/esm/object/_virtual/_rollupPluginBabelHelpers.mjs +115 -0
- package/esm/object/index.mjs +4 -0
- package/esm/object/omit.mjs +26 -0
- package/esm/object/omitBy.mjs +5 -0
- package/esm/object/pick.mjs +26 -0
- package/esm/object/pickBy.mjs +5 -0
- package/esm/predicate/index.mjs +4 -0
- package/esm/predicate/isNil.mjs +10 -0
- package/esm/predicate/isNotNil.mjs +16 -0
- package/esm/predicate/isNull.mjs +10 -0
- package/esm/predicate/isUndefined.mjs +10 -0
- package/esm/promise/delay.mjs +12 -0
- package/esm/promise/index.mjs +1 -0
- package/package.json +94 -0
- package/rollup.config.js +5 -0
- package/src/array/chunk.spec.ts +27 -0
- package/src/array/chunk.ts +24 -0
- package/src/array/difference.spec.ts +10 -0
- package/src/array/difference.ts +11 -0
- package/src/array/differenceBy.spec.ts +9 -0
- package/src/array/differenceBy.ts +14 -0
- package/src/array/differenceWith.spec.ts +8 -0
- package/src/array/differenceWith.ts +14 -0
- package/src/array/drop.spec.ts +9 -0
- package/src/array/drop.ts +9 -0
- package/src/array/dropRight.spec.ts +9 -0
- package/src/array/dropRight.ts +9 -0
- package/src/array/dropRightWhile.spec.ts +16 -0
- package/src/array/dropRightWhile.ts +13 -0
- package/src/array/dropWhile.spec.ts +14 -0
- package/src/array/dropWhile.ts +10 -0
- package/src/array/groupBy.ts +3 -0
- package/src/array/index.ts +30 -0
- package/src/array/intersection.spec.ts +11 -0
- package/src/array/intersection.ts +15 -0
- package/src/array/intersectionBy.spec.ts +9 -0
- package/src/array/intersectionBy.ts +18 -0
- package/src/array/intersectionWith.spec.ts +9 -0
- package/src/array/intersectionWith.ts +18 -0
- package/src/array/partition.spec.ts +23 -0
- package/src/array/partition.ts +21 -0
- package/src/array/sample.spec.ts +11 -0
- package/src/array/sample.ts +10 -0
- package/src/array/shuffle.spec.ts +11 -0
- package/src/array/shuffle.ts +18 -0
- package/src/array/take.spec.ts +25 -0
- package/src/array/take.ts +25 -0
- package/src/array/takeRight.spec.ts +25 -0
- package/src/array/takeRight.ts +29 -0
- package/src/array/takeRightWhile.spec.ts +16 -0
- package/src/array/takeRightWhile.ts +26 -0
- package/src/array/takeWhile.spec.ts +34 -0
- package/src/array/takeWhile.ts +31 -0
- package/src/array/union.spec.ts +10 -0
- package/src/array/union.ts +14 -0
- package/src/array/unionBy.spec.ts +12 -0
- package/src/array/unionBy.ts +35 -0
- package/src/array/unionWith.spec.ts +23 -0
- package/src/array/unionWith.ts +18 -0
- package/src/array/uniq.spec.ts +8 -0
- package/src/array/uniq.ts +16 -0
- package/src/array/uniqBy.spec.ts +8 -0
- package/src/array/uniqBy.ts +17 -0
- package/src/array/uniqWith.spec.ts +16 -0
- package/src/array/uniqWith.ts +29 -0
- package/src/array/xor.spec.ts +13 -0
- package/src/array/xor.ts +25 -0
- package/src/array/xorBy.spec.ts +16 -0
- package/src/array/xorBy.ts +29 -0
- package/src/array/xorWith.spec.ts +16 -0
- package/src/array/xorWith.ts +28 -0
- package/src/array/zip.spec.ts +14 -0
- package/src/array/zip.ts +34 -0
- package/src/array/zipWith.spec.ts +13 -0
- package/src/array/zipWith.ts +23 -0
- package/src/function/debounce.spec.ts +76 -0
- package/src/function/debounce.ts +42 -0
- package/src/function/index.ts +3 -0
- package/src/function/once.spec.ts +31 -0
- package/src/function/once.ts +34 -0
- package/src/function/throttle.spec.ts +32 -0
- package/src/function/throttle.ts +39 -0
- package/src/index.ts +6 -0
- package/src/math/clamp.spec.ts +18 -0
- package/src/math/clamp.ts +17 -0
- package/src/math/index.ts +3 -0
- package/src/math/round.spec.ts +53 -0
- package/src/math/round.ts +16 -0
- package/src/math/sum.spec.ts +29 -0
- package/src/math/sum.ts +17 -0
- package/src/object/index.ts +4 -0
- package/src/object/omit.spec.ts +10 -0
- package/src/object/omit.ts +15 -0
- package/src/object/omitBy.ts +3 -0
- package/src/object/pick.spec.ts +10 -0
- package/src/object/pick.ts +15 -0
- package/src/object/pickBy.ts +3 -0
- package/src/predicate/index.ts +4 -0
- package/src/predicate/isNil.spec.ts +23 -0
- package/src/predicate/isNil.ts +8 -0
- package/src/predicate/isNotNil.spec.ts +29 -0
- package/src/predicate/isNotNil.ts +14 -0
- package/src/predicate/isNull.spec.ts +23 -0
- package/src/predicate/isNull.ts +8 -0
- package/src/predicate/isUndefined.spec.ts +23 -0
- package/src/predicate/isUndefined.ts +8 -0
- package/src/promise/delay.spec.ts +13 -0
- package/src/promise/delay.ts +10 -0
- package/src/promise/index.ts +1 -0
- package/tsconfig.json +12 -0
- package/vitest.config.mts +13 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name intersection
|
|
3
|
+
* @description
|
|
4
|
+
* Returns the intersection of two arrays.
|
|
5
|
+
* @param firstArr The first array to get the intersection
|
|
6
|
+
* @param secondArr The second array to get the intersection
|
|
7
|
+
* @example
|
|
8
|
+
* intersection([1, 2], [1, 3]) === [1]
|
|
9
|
+
* intersection([1, 2, 3], [2, 3, 4]) === [2, 3]
|
|
10
|
+
*/
|
|
11
|
+
export declare function intersection<T>(firstArr: T[], secondArr: T[]): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name intersectionBy
|
|
3
|
+
* @description
|
|
4
|
+
* Returns the intersection of two arrays. The identity of two elements is calculated after the elements are mapped with `mapper`.
|
|
5
|
+
* @param firstArr The first array to get the intersection
|
|
6
|
+
* @param secondArr The second array to get the intersection
|
|
7
|
+
* @param mapper The function to map the elements when calculating the intersection
|
|
8
|
+
* @example
|
|
9
|
+
* intersectionBy([1.2, 2.1], [1.4, 3.1], Math.floor) === [1.2]
|
|
10
|
+
* intersectionBy([{ foo: 1 }, { foo: 2 }], [{ foo: 1 }, { foo: 3 }], x => x.foo) === [{ foo: 1 }]
|
|
11
|
+
*/
|
|
12
|
+
export declare function intersectionBy<T, U>(firstArr: T[], secondArr: T[], mapper: (item: T) => U): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name intersectionWith
|
|
3
|
+
* @description
|
|
4
|
+
* Returns the intersection of two arrays. The identity of two elements is compared with `areItemsEqual`.
|
|
5
|
+
* @param firstArr The first array to get the intersection
|
|
6
|
+
* @param secondArr The second array to get the intersection
|
|
7
|
+
* @param areItemsEqual The function to compare the identity of two elements
|
|
8
|
+
* @example
|
|
9
|
+
* intersectionWith([1.2, 2.1], [1.4, 3.1], (x, y) => Math.floor(x) === Math.floor(y)) === [1.2]
|
|
10
|
+
* intersectionWith([{ foo: 1 }, { foo: 2 }], [{ foo: 1 }, { foo: 3 }], (x, y) => x.foo === y.foo) === [{ foo: 1 }]
|
|
11
|
+
*/
|
|
12
|
+
export declare function intersectionWith<T>(firstArr: T[], secondArr: T[], areItemsEqual: (x: T, y: T) => boolean): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name partition
|
|
3
|
+
* @description
|
|
4
|
+
* Creates two arrays: the first array includes items for which isInTruthy returns true, and the second array includes items for which isInTruthy returns false.
|
|
5
|
+
* @param arr The array to split into two arrays
|
|
6
|
+
* @param isInTruthy The predicate to tell whether an item is included in the first array
|
|
7
|
+
*/
|
|
8
|
+
export declare function partition<T>(arr: T[], isInTruthy: (value: T) => boolean): [truthy: T[], falsy: T[]];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a new array containing the first `count` elements from the input array `arr`.
|
|
3
|
+
* If `count` is greater than the length of `arr`, the entire array is returned.
|
|
4
|
+
*
|
|
5
|
+
* @template T - Type of elements in the input array.
|
|
6
|
+
*
|
|
7
|
+
* @param {T[]} arr - The array to take elements from.
|
|
8
|
+
* @param {number} count - The number of elements to take.
|
|
9
|
+
* @returns {T[]} A new array containing the first `count` elements from `arr`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Returns [1, 2, 3]
|
|
13
|
+
* take([1, 2, 3, 4, 5], 3);
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Returns ['a', 'b']
|
|
17
|
+
* take(['a', 'b', 'c'], 2);
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Returns [1, 2, 3]
|
|
21
|
+
* take([1, 2, 3], 5);
|
|
22
|
+
*/
|
|
23
|
+
export declare function take<T>(arr: T[], count: number): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a new array containing the last `count` elements from the input array `arr`.
|
|
3
|
+
* If `count` is greater than the length of `arr`, the entire array is returned.
|
|
4
|
+
*
|
|
5
|
+
* @template T - Type of elements in the input array.
|
|
6
|
+
*
|
|
7
|
+
* @param {T[]} arr - The array to take elements from.
|
|
8
|
+
* @param {number} count - The number of elements to take.
|
|
9
|
+
* @returns {T[]} A new array containing the last `count` elements from `arr`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Returns [4, 5]
|
|
13
|
+
* takeRight([1, 2, 3, 4, 5], 2);
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Returns ['b', 'c']
|
|
17
|
+
* takeRight(['a', 'b', 'c'], 2);
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Returns [1, 2, 3]
|
|
21
|
+
* takeRight([1, 2, 3], 5);
|
|
22
|
+
*/
|
|
23
|
+
export declare function takeRight<T>(arr: T[], count: number): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Takes elements from the end of the array while the predicate function returns `true`.
|
|
3
|
+
*
|
|
4
|
+
* @template T - Type of elements in the input array.
|
|
5
|
+
*
|
|
6
|
+
* @param {T[]} arr - The array to take elements from.
|
|
7
|
+
* @param {function(T): boolean} shouldContinueTaking - The function invoked per element.
|
|
8
|
+
* @returns {T[]} A new array containing the elements taken from the end while the predicate returns `true`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Returns [3, 2, 1]
|
|
12
|
+
* takeRightWhile([5, 4, 3, 2, 1], n => n < 4);
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Returns []
|
|
16
|
+
* takeRightWhile([1, 2, 3], n => n > 3);
|
|
17
|
+
*/
|
|
18
|
+
export declare function takeRightWhile<T>(arr: T[], shouldContinueTaking: (item: T) => boolean): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a new array containing the leading elements of the provided array
|
|
3
|
+
* that satisfy the provided predicate function. It stops taking elements as soon
|
|
4
|
+
* as an element does not satisfy the predicate.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of elements in the array.
|
|
7
|
+
* @param {T[]} arr - The array to process.
|
|
8
|
+
* @param {(element: T) => boolean} shouldContinueTaking - The predicate function that is called with each element. Elements are included in the result as long as this function returns true.
|
|
9
|
+
* @returns {T[]} A new array containing the leading elements that satisfy the predicate.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Returns [1, 2]
|
|
13
|
+
* takeWhile([1, 2, 3, 4], x => x < 3);
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Returns []
|
|
17
|
+
* takeWhile([1, 2, 3, 4], x => x > 3);
|
|
18
|
+
*/
|
|
19
|
+
export declare function takeWhile<T>(arr: T[], shouldContinueTaking: (element: T) => boolean): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an array of unique values, in order, from all given arrays using a provided mapping function to determine equality.
|
|
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
|
+
* @param {T[]} arr1 - The first array.
|
|
8
|
+
* @param {T[]} arr2 - The second array.
|
|
9
|
+
* @param {function(item: T): U} mapper - The function to map array elements to comparison values.
|
|
10
|
+
* @returns {T[]} A new array containing the union of unique elements from `arr1` and `arr2`, based on the values returned by the mapping function.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Custom mapping function for numbers (modulo comparison)
|
|
14
|
+
* const moduloMapper = (x) => x % 3;
|
|
15
|
+
* unionBy([1, 2, 3], [4, 5, 6], moduloMapper);
|
|
16
|
+
* // Returns [1, 2, 3]
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Custom mapping function for objects with an 'id' property
|
|
20
|
+
* const idMapper = (obj) => obj.id;
|
|
21
|
+
* unionBy([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], idMapper);
|
|
22
|
+
* // Returns [{ id: 1 }, { id: 2 }, { id: 3 }]
|
|
23
|
+
*/
|
|
24
|
+
export declare function unionBy<T, U>(arr1: T[], arr2: T[], mapper: (item: T) => U): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `unionWith` function returns the union of multiple arrays passed as arguments. During this process, it removes any duplicated elements.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* unionWith(
|
|
7
|
+
* [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
|
|
8
|
+
* [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
|
|
9
|
+
* (x, y) => x === y
|
|
10
|
+
* );
|
|
11
|
+
* // [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function unionWith<T>(arr1: T[], arr2: T[], areItemsEqual: (item1: T, item2: T) => boolean): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name uniq
|
|
3
|
+
* @description
|
|
4
|
+
* `uniq` removes duplicated elements from the array given as an argument.
|
|
5
|
+
*
|
|
6
|
+
* It filters out elements with the same value, so duplicates of data types like Objects are not checked.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* uniq([1, 1, 2, 3, 5, 5, 7, 'foo', 'bar', 'bar']);
|
|
11
|
+
* // [1, 2, 3, 5, 7, 'foo', 'bar']
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function uniq<T>(arr: T[]): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `uniqBy` function takes an array as its first argument and a 'converter' function as the second. It maps the array elements using the converter function, then removes any duplicates.
|
|
3
|
+
*
|
|
4
|
+
* It filters out elements with the same value, meaning it does not check for duplicates in data types like Objects.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);
|
|
9
|
+
* // [1.2, 2.1, 3.3, 5.7, 7.19]
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function uniqBy<T, U>(arr: T[], converter: (item: T) => U): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `uniqWith` function takes an array as its first argument and a 'comparator' function as the second.
|
|
3
|
+
*
|
|
4
|
+
* It evaluates the elements of the array using the comparator function, and if true is returned, it considers those elements as duplicates and removes them.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* uniqWith([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], (a, b) => );
|
|
9
|
+
* // [1, 2, 3, 5, 7]
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function uniqWith<T>(arr: T[], areItemsEqual: (item1: T, item2: T) => boolean): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the symmetric difference between two arrays. The symmetric difference is the set of elements
|
|
3
|
+
* which are in either of the arrays, but not in their intersection.
|
|
4
|
+
*
|
|
5
|
+
* @template T - Type of elements in the input arrays.
|
|
6
|
+
*
|
|
7
|
+
* @param {T[]} arr1 - The first array.
|
|
8
|
+
* @param {T[]} arr2 - The second array.
|
|
9
|
+
* @returns {T[]} An array containing the elements that are present in either `arr1` or `arr2` but not in both.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Returns [1, 2, 5, 6]
|
|
13
|
+
* xor([1, 2, 3, 4], [3, 4, 5, 6]);
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Returns ['a', 'c']
|
|
17
|
+
* xor(['a', 'b'], ['b', 'c']);
|
|
18
|
+
*/
|
|
19
|
+
export declare function xor<T>(arr1: T[], arr2: T[]): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the symmetric difference between two arrays using a custom mapping function.
|
|
3
|
+
* The symmetric difference is the set of elements which are in either of the arrays,
|
|
4
|
+
* but not in their intersection, determined by the result of the mapping function.
|
|
5
|
+
*
|
|
6
|
+
* @template T - Type of elements in the input arrays.
|
|
7
|
+
* @template U - Type of the values returned by the mapping function.
|
|
8
|
+
*
|
|
9
|
+
* @param {T[]} arr1 - The first array.
|
|
10
|
+
* @param {T[]} arr2 - The second array.
|
|
11
|
+
* @param {function(item: T): U} mapper - The function to map array elements to comparison values.
|
|
12
|
+
* @returns {T[]} An array containing the elements that are present in either `arr1` or `arr2` but not in both, based on the values returned by the mapping function.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Custom mapping function for objects with an 'id' property
|
|
16
|
+
* const idMapper = obj => obj.id;
|
|
17
|
+
* xorBy([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], idMapper);
|
|
18
|
+
* // Returns [{ id: 1 }, { id: 3 }]
|
|
19
|
+
*/
|
|
20
|
+
export declare function xorBy<T, U>(arr1: T[], arr2: T[], mapper: (item: T) => U): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the symmetric difference between two arrays using a custom equality function.
|
|
3
|
+
* The symmetric difference is the set of elements which are in either of the arrays,
|
|
4
|
+
* but not in their intersection.
|
|
5
|
+
*
|
|
6
|
+
* @template T - Type of elements in the input arrays.
|
|
7
|
+
*
|
|
8
|
+
* @param {T[]} arr1 - The first array.
|
|
9
|
+
* @param {T[]} arr2 - The second array.
|
|
10
|
+
* @param {(item1: T, item2: T) => boolean} areElementsEqual - The custom equality function to compare elements.
|
|
11
|
+
* @returns {T[]} An array containing the elements that are present in either `arr1` or `arr2` but not in both, based on the custom equality function.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Custom equality function for objects with an 'id' property
|
|
15
|
+
* const areObjectsEqual = (a, b) => a.id === b.id;
|
|
16
|
+
* xorWith([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], areObjectsEqual);
|
|
17
|
+
* // Returns [{ id: 1 }, { id: 3 }]
|
|
18
|
+
*/
|
|
19
|
+
export declare function xorWith<T>(arr1: T[], arr2: T[], areElementsEqual: (item1: T, item2: T) => boolean): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merges multiple arrays element-wise. Returns an array where each element is an array containing
|
|
3
|
+
* elements from the input arrays at the corresponding index.
|
|
4
|
+
*
|
|
5
|
+
* @param {T[]} arr1 - The first array to be zipped.
|
|
6
|
+
* @param {T[]} arr2 - The second array to be zipped.
|
|
7
|
+
* @param {T[]} arr3 - The third array to be zipped.
|
|
8
|
+
* @param {T[]} arr4 - The fourth array to be zipped.
|
|
9
|
+
*/
|
|
10
|
+
export declare function zip<T>(arr1: T[]): [T][];
|
|
11
|
+
export declare function zip<T, U>(arr1: T[], arr2: U[]): [T, U][];
|
|
12
|
+
export declare function zip<T, U, V>(arr1: T[], arr2: U[], arr3: V[]): [T, U, V][];
|
|
13
|
+
export declare function zip<T, U, V, W>(arr1: T[], arr2: U[], arr3: V[], arr4: W[]): [T, U, V, W][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Combines multiple arrays element-wise using a provided combining function.
|
|
3
|
+
* Returns an array where each element is the result of applying the combining function
|
|
4
|
+
* to the corresponding elements from the input arrays.
|
|
5
|
+
*/
|
|
6
|
+
export declare function zipWith<T, R>(arr1: T[], combine: (item: T) => R): R[];
|
|
7
|
+
export declare function zipWith<T, U, R>(arr1: T[], arr2: U[], combine: (item1: T, item2: U) => R): R[];
|
|
8
|
+
export declare function zipWith<T, U, V, R>(arr1: T[], arr2: U[], arr3: V[], combine: (item1: T, item2: U, item3: V) => R): R[];
|
|
9
|
+
export declare function zipWith<T, U, V, W, R>(arr1: T[], arr2: U[], arr3: V[], arr4: W[], combine: (item1: T, item2: U, item3: V, item4: W) => R): R[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a debounced function that delays invoking the provided function until after `waitMs` milliseconds
|
|
3
|
+
* have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`
|
|
4
|
+
* method to cancel any pending execution.
|
|
5
|
+
*
|
|
6
|
+
* @param {() => void} func - The function to debounce.
|
|
7
|
+
* @param {number} waitMs - The number of milliseconds to delay.
|
|
8
|
+
* @returns {{ (): void; cancel: () => void }} A new debounced function with a `cancel` method.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const debouncedFunction = debounce(() => {
|
|
12
|
+
* console.log('Function executed');
|
|
13
|
+
* }, 1000);
|
|
14
|
+
*
|
|
15
|
+
* // Will log 'Function executed' after 1 second if not called again in that time
|
|
16
|
+
* debouncedFunction();
|
|
17
|
+
*
|
|
18
|
+
* // Will not log anything as the previous call is canceled
|
|
19
|
+
* debouncedFunction.cancel();
|
|
20
|
+
*/
|
|
21
|
+
export declare function debounce(func: () => void, waitMs: number): {
|
|
22
|
+
(): void;
|
|
23
|
+
cancel(): void;
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a debounced function that delays invoking the provided function until after `waitMs` milliseconds
|
|
7
|
+
* have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`
|
|
8
|
+
* method to cancel any pending execution.
|
|
9
|
+
*
|
|
10
|
+
* @param {() => void} func - The function to debounce.
|
|
11
|
+
* @param {number} waitMs - The number of milliseconds to delay.
|
|
12
|
+
* @returns {{ (): void; cancel: () => void }} A new debounced function with a `cancel` method.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const debouncedFunction = debounce(() => {
|
|
16
|
+
* console.log('Function executed');
|
|
17
|
+
* }, 1000);
|
|
18
|
+
*
|
|
19
|
+
* // Will log 'Function executed' after 1 second if not called again in that time
|
|
20
|
+
* debouncedFunction();
|
|
21
|
+
*
|
|
22
|
+
* // Will not log anything as the previous call is canceled
|
|
23
|
+
* debouncedFunction.cancel();
|
|
24
|
+
*/
|
|
25
|
+
function debounce(func, waitMs) {
|
|
26
|
+
var timeoutId = null;
|
|
27
|
+
var debounced = function debounced() {
|
|
28
|
+
if (timeoutId != null) {
|
|
29
|
+
clearTimeout(timeoutId);
|
|
30
|
+
}
|
|
31
|
+
timeoutId = setTimeout(function () {
|
|
32
|
+
func();
|
|
33
|
+
}, waitMs);
|
|
34
|
+
};
|
|
35
|
+
debounced.cancel = function () {
|
|
36
|
+
if (timeoutId != null) {
|
|
37
|
+
clearTimeout(timeoutId);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return debounced;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Creates a function that is restricted to invoking the provided function `func` once.
|
|
45
|
+
* Repeated calls to the function will return the value from the first invocation.
|
|
46
|
+
*
|
|
47
|
+
* @template F - The type of the function to be invoked once.
|
|
48
|
+
* @param {F} func - The function to restrict.
|
|
49
|
+
* @returns {F} A new function that invokes `func` once and caches the result.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const initialize = once(() => {
|
|
53
|
+
* console.log('Initialized!');
|
|
54
|
+
* return true;
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* initialize(); // Logs: 'Initialized!' and returns true
|
|
58
|
+
* initialize(); // Returns true without logging
|
|
59
|
+
*/
|
|
60
|
+
function once(func) {
|
|
61
|
+
var called = false;
|
|
62
|
+
var cache;
|
|
63
|
+
return function () {
|
|
64
|
+
if (called) {
|
|
65
|
+
return cache;
|
|
66
|
+
}
|
|
67
|
+
var result = func();
|
|
68
|
+
called = true;
|
|
69
|
+
cache = result;
|
|
70
|
+
return result;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Creates a throttled function that only invokes the provided function at most once
|
|
76
|
+
* per every `throttleMs` milliseconds. Subsequent calls to the throttled function
|
|
77
|
+
* within the wait time will not trigger the execution of the original function.
|
|
78
|
+
*
|
|
79
|
+
* @param {() => void} func - The function to throttle.
|
|
80
|
+
* @param {number} throttleMs - The number of milliseconds to throttle executions to.
|
|
81
|
+
* @returns {() => void} A new throttled function.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* const throttledFunction = throttle(() => {
|
|
85
|
+
* console.log('Function executed');
|
|
86
|
+
* }, 1000);
|
|
87
|
+
*
|
|
88
|
+
* // Will log 'Function executed' immediately
|
|
89
|
+
* throttledFunction();
|
|
90
|
+
*
|
|
91
|
+
* // Will not log anything as it is within the throttle time
|
|
92
|
+
* throttledFunction();
|
|
93
|
+
*
|
|
94
|
+
* // After 1 second
|
|
95
|
+
* setTimeout(() => {
|
|
96
|
+
* throttledFunction(); // Will log 'Function executed'
|
|
97
|
+
* }, 1000);
|
|
98
|
+
*/
|
|
99
|
+
function throttle(func, throttleMs) {
|
|
100
|
+
var lastCallTime;
|
|
101
|
+
var throttledFunction = function throttledFunction() {
|
|
102
|
+
var now = Date.now();
|
|
103
|
+
if (lastCallTime == null || now - lastCallTime >= throttleMs) {
|
|
104
|
+
lastCallTime = now;
|
|
105
|
+
func();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
return throttledFunction;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
exports.debounce = debounce;
|
|
112
|
+
exports.once = once;
|
|
113
|
+
exports.throttle = throttle;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that is restricted to invoking the provided function `func` once.
|
|
3
|
+
* Repeated calls to the function will return the value from the first invocation.
|
|
4
|
+
*
|
|
5
|
+
* @template F - The type of the function to be invoked once.
|
|
6
|
+
* @param {F} func - The function to restrict.
|
|
7
|
+
* @returns {F} A new function that invokes `func` once and caches the result.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const initialize = once(() => {
|
|
11
|
+
* console.log('Initialized!');
|
|
12
|
+
* return true;
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* initialize(); // Logs: 'Initialized!' and returns true
|
|
16
|
+
* initialize(); // Returns true without logging
|
|
17
|
+
*/
|
|
18
|
+
export declare function once<F extends () => any>(func: F): F;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a throttled function that only invokes the provided function at most once
|
|
3
|
+
* per every `throttleMs` milliseconds. Subsequent calls to the throttled function
|
|
4
|
+
* within the wait time will not trigger the execution of the original function.
|
|
5
|
+
*
|
|
6
|
+
* @param {() => void} func - The function to throttle.
|
|
7
|
+
* @param {number} throttleMs - The number of milliseconds to throttle executions to.
|
|
8
|
+
* @returns {() => void} A new throttled function.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const throttledFunction = throttle(() => {
|
|
12
|
+
* console.log('Function executed');
|
|
13
|
+
* }, 1000);
|
|
14
|
+
*
|
|
15
|
+
* // Will log 'Function executed' immediately
|
|
16
|
+
* throttledFunction();
|
|
17
|
+
*
|
|
18
|
+
* // Will not log anything as it is within the throttle time
|
|
19
|
+
* throttledFunction();
|
|
20
|
+
*
|
|
21
|
+
* // After 1 second
|
|
22
|
+
* setTimeout(() => {
|
|
23
|
+
* throttledFunction(); // Will log 'Function executed'
|
|
24
|
+
* }, 1000);
|
|
25
|
+
*/
|
|
26
|
+
export declare function throttle(func: () => void, throttleMs: number): () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|