es-toolkit 1.23.0 → 1.24.0-dev.766
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 +9 -0
- package/README.md +1 -1
- package/dist/_chunk/{isWeakSet-BAMm2l.js → isWeakSet-Bd6nry.js} +59 -46
- package/dist/_chunk/{range-BXlMmn.js → sumBy-BkErWJ.js} +25 -5
- package/dist/_chunk/{isObjectLike-aywuSF.js → toMerged-DDLv0D.js} +88 -86
- package/dist/_chunk/{flowRight-Dv8J0U.js → unary-BZ5Ixo.js} +27 -64
- package/dist/_chunk/{zipWith-EOU_KZ.js → zipWith-wpjySR.js} +8 -17
- package/dist/array/dropRightWhile.d.mts +2 -2
- package/dist/array/dropRightWhile.d.ts +2 -2
- package/dist/array/dropRightWhile.mjs +1 -1
- package/dist/array/dropWhile.d.mts +1 -1
- package/dist/array/dropWhile.d.ts +1 -1
- package/dist/array/index.js +1 -1
- package/dist/array/unionBy.mjs +3 -10
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/MAX_ARRAY_LENGTH.mjs +3 -0
- package/dist/compat/_internal/isIterateeCall.mjs +17 -0
- package/dist/compat/array/difference.d.mts +9 -3
- package/dist/compat/array/difference.d.ts +9 -3
- package/dist/compat/array/difference.mjs +12 -3
- package/dist/compat/array/dropRightWhile.d.mts +60 -0
- package/dist/compat/array/dropRightWhile.d.ts +60 -0
- package/dist/compat/array/dropRightWhile.mjs +27 -0
- package/dist/compat/array/every.mjs +4 -5
- package/dist/compat/array/filter.mjs +4 -5
- package/dist/compat/array/find.mjs +4 -5
- package/dist/compat/array/includes.mjs +2 -1
- package/dist/compat/array/slice.d.mts +18 -0
- package/dist/compat/array/slice.d.ts +18 -0
- package/dist/compat/array/slice.mjs +38 -0
- package/dist/compat/array/take.d.mts +25 -0
- package/dist/compat/array/take.d.ts +25 -0
- package/dist/compat/array/take.mjs +10 -0
- package/dist/compat/function/before.d.mts +26 -0
- package/dist/compat/function/before.d.ts +26 -0
- package/dist/compat/function/before.mjs +20 -0
- package/dist/compat/function/curryRight.d.mts +50 -0
- package/dist/compat/function/curryRight.d.ts +50 -0
- package/dist/compat/function/curryRight.mjs +64 -0
- package/dist/compat/index.d.mts +86 -75
- package/dist/compat/index.d.ts +86 -75
- package/dist/compat/index.js +779 -496
- package/dist/compat/index.mjs +86 -75
- package/dist/compat/object/defaults.d.mts +120 -0
- package/dist/compat/object/defaults.d.ts +120 -0
- package/dist/compat/object/defaults.mjs +21 -0
- package/dist/compat/object/invertBy.d.mts +27 -0
- package/dist/compat/object/invertBy.d.ts +27 -0
- package/dist/compat/object/invertBy.mjs +27 -0
- package/dist/compat/object/omit.d.mts +1 -1
- package/dist/compat/object/omit.d.ts +1 -1
- package/dist/compat/object/pick.d.mts +1 -1
- package/dist/compat/object/pick.d.ts +1 -1
- package/dist/compat/object/toDefaulted.d.mts +122 -0
- package/dist/compat/object/toDefaulted.d.ts +122 -0
- package/dist/compat/object/toDefaulted.mjs +9 -0
- package/dist/compat/predicate/isArrayBuffer.d.mts +20 -0
- package/dist/compat/predicate/isArrayBuffer.d.ts +20 -0
- package/dist/compat/predicate/isArrayBuffer.mjs +7 -0
- package/dist/compat/predicate/isDate.d.mts +16 -0
- package/dist/compat/predicate/isDate.d.ts +16 -0
- package/dist/compat/predicate/isDate.mjs +7 -0
- package/dist/compat/predicate/isEqualWith.d.mts +38 -0
- package/dist/compat/predicate/isEqualWith.d.ts +38 -0
- package/dist/compat/predicate/isEqualWith.mjs +23 -0
- package/dist/compat/predicate/isMap.d.mts +20 -0
- package/dist/compat/predicate/isMap.d.ts +20 -0
- package/dist/compat/predicate/isMap.mjs +7 -0
- package/dist/compat/predicate/isMatch.mjs +2 -1
- package/dist/compat/predicate/isSet.d.mts +20 -0
- package/dist/compat/predicate/isSet.d.ts +20 -0
- package/dist/compat/predicate/isSet.mjs +7 -0
- package/dist/compat/string/upperCase.mjs +0 -1
- package/dist/compat/util/constant.d.mts +16 -0
- package/dist/compat/util/constant.d.ts +16 -0
- package/dist/compat/util/constant.mjs +5 -0
- package/dist/compat/util/defaultTo.d.mts +17 -0
- package/dist/compat/util/defaultTo.d.ts +17 -0
- package/dist/compat/util/defaultTo.mjs +8 -0
- package/dist/compat/util/eq.d.mts +16 -0
- package/dist/compat/util/eq.d.ts +16 -0
- package/dist/compat/util/eq.mjs +5 -0
- package/dist/compat/util/times.d.mts +14 -0
- package/dist/compat/util/times.d.ts +14 -0
- package/dist/compat/util/times.mjs +15 -0
- package/dist/compat/util/toLength.d.mts +18 -0
- package/dist/compat/util/toLength.d.ts +18 -0
- package/dist/compat/util/toLength.mjs +12 -0
- package/dist/function/before.d.mts +2 -2
- package/dist/function/before.d.ts +2 -2
- package/dist/function/before.mjs +2 -2
- package/dist/function/index.d.mts +10 -10
- package/dist/function/index.d.ts +10 -10
- package/dist/function/index.js +65 -32
- package/dist/function/index.mjs +10 -10
- package/dist/function/once.d.mts +16 -1
- package/dist/function/once.d.ts +16 -1
- package/dist/function/once.mjs +5 -7
- package/dist/index.d.mts +43 -41
- package/dist/index.d.ts +43 -41
- package/dist/index.js +59 -57
- package/dist/index.mjs +43 -41
- package/dist/math/index.d.mts +2 -1
- package/dist/math/index.d.ts +2 -1
- package/dist/math/index.js +9 -8
- package/dist/math/index.mjs +2 -1
- package/dist/math/rangeRight.d.mts +38 -0
- package/dist/math/rangeRight.d.ts +38 -0
- package/dist/math/rangeRight.mjs +20 -0
- package/dist/object/index.d.mts +7 -7
- package/dist/object/index.d.ts +7 -7
- package/dist/object/index.js +32 -32
- package/dist/object/index.mjs +7 -7
- package/dist/object/omitBy.d.mts +1 -1
- package/dist/object/omitBy.d.ts +1 -1
- package/dist/object/omitBy.mjs +4 -3
- package/dist/object/pickBy.mjs +4 -3
- package/dist/predicate/index.d.mts +11 -10
- package/dist/predicate/index.d.ts +11 -10
- package/dist/predicate/index.js +8 -7
- package/dist/predicate/index.mjs +11 -10
- package/dist/predicate/isBlob.d.mts +19 -0
- package/dist/predicate/isBlob.d.ts +19 -0
- package/dist/predicate/isBlob.mjs +8 -0
- package/dist/predicate/isEqualWith.mjs +2 -1
- package/dist/promise/index.d.mts +1 -1
- package/dist/promise/index.d.ts +1 -1
- package/dist/promise/index.mjs +1 -1
- package/dist/string/index.d.mts +12 -12
- package/dist/string/index.d.ts +12 -12
- package/dist/string/index.js +20 -20
- package/dist/string/index.mjs +12 -12
- package/package.json +10 -6
- package/dist/_chunk/{pad-BWiShN.js → upperFirst-BUECmK.js} +84 -84
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the default value for `null`, `undefined`, and `NaN`.
|
|
3
|
+
*
|
|
4
|
+
* @param {T | null | undefined} value - The value to check.
|
|
5
|
+
* @param {T} [defaultValue] - The default value to return if the first value is null, undefined, or NaN.
|
|
6
|
+
* @returns {T} Returns either the first value or the default value.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* defaultTo(null, 'default') // returns 'default'
|
|
10
|
+
* defaultTo(undefined, 42) // returns 42
|
|
11
|
+
* defaultTo(NaN, 0) // returns 0
|
|
12
|
+
* defaultTo('actual', 'default') // returns 'actual'
|
|
13
|
+
* defaultTo(123, 0) // returns 123
|
|
14
|
+
*/
|
|
15
|
+
declare function defaultTo<T>(value: T | null | undefined, defaultValue?: T): T;
|
|
16
|
+
|
|
17
|
+
export { defaultTo };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performs a `SameValueZero` comparison between two values to determine if they are equivalent.
|
|
3
|
+
*
|
|
4
|
+
* @param {unknown} value - The value to compare.
|
|
5
|
+
* @param {unknown} other - The other value to compare.
|
|
6
|
+
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* eq(1, 1); // true
|
|
10
|
+
* eq(0, -0); // true
|
|
11
|
+
* eq(NaN, NaN); // true
|
|
12
|
+
* eq('a', Object('a')); // false
|
|
13
|
+
*/
|
|
14
|
+
declare function eq(value?: unknown, other?: unknown): boolean;
|
|
15
|
+
|
|
16
|
+
export { eq };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performs a `SameValueZero` comparison between two values to determine if they are equivalent.
|
|
3
|
+
*
|
|
4
|
+
* @param {unknown} value - The value to compare.
|
|
5
|
+
* @param {unknown} other - The other value to compare.
|
|
6
|
+
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* eq(1, 1); // true
|
|
10
|
+
* eq(0, -0); // true
|
|
11
|
+
* eq(NaN, NaN); // true
|
|
12
|
+
* eq('a', Object('a')); // false
|
|
13
|
+
*/
|
|
14
|
+
declare function eq(value?: unknown, other?: unknown): boolean;
|
|
15
|
+
|
|
16
|
+
export { eq };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invokes the getValue function n times, returning an array of the results.
|
|
3
|
+
*
|
|
4
|
+
* @template R The return type of the getValue function.
|
|
5
|
+
* @param {number} n - The number of times to invoke getValue.
|
|
6
|
+
* @param {(index: number) => R} getValue - The function to invoke for each index.
|
|
7
|
+
* @returns {R[]} An array containing the results of invoking getValue n times.
|
|
8
|
+
* @example
|
|
9
|
+
* times(3, (i) => i * 2); // => [0, 2, 4]
|
|
10
|
+
* times(2, () => 'es-toolkit'); // => ['es-toolkit', 'es-toolkit']
|
|
11
|
+
*/
|
|
12
|
+
declare function times<R = number>(n?: number, getValue?: (index: number) => R): R[];
|
|
13
|
+
|
|
14
|
+
export { times };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invokes the getValue function n times, returning an array of the results.
|
|
3
|
+
*
|
|
4
|
+
* @template R The return type of the getValue function.
|
|
5
|
+
* @param {number} n - The number of times to invoke getValue.
|
|
6
|
+
* @param {(index: number) => R} getValue - The function to invoke for each index.
|
|
7
|
+
* @returns {R[]} An array containing the results of invoking getValue n times.
|
|
8
|
+
* @example
|
|
9
|
+
* times(3, (i) => i * 2); // => [0, 2, 4]
|
|
10
|
+
* times(2, () => 'es-toolkit'); // => ['es-toolkit', 'es-toolkit']
|
|
11
|
+
*/
|
|
12
|
+
declare function times<R = number>(n?: number, getValue?: (index: number) => R): R[];
|
|
13
|
+
|
|
14
|
+
export { times };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { toInteger } from './toInteger.mjs';
|
|
2
|
+
|
|
3
|
+
function times(n, getValue) {
|
|
4
|
+
n = toInteger(n);
|
|
5
|
+
if (n < 1 || !Number.isSafeInteger(n)) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
const result = new Array(n);
|
|
9
|
+
for (let i = 0; i < n; i++) {
|
|
10
|
+
result[i] = typeof getValue === 'function' ? getValue(i) : i;
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { times };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the value to a valid index. A valid index is an integer that is greater than or equal to `0` and less than or equal to `2^32 - 1`.
|
|
3
|
+
*
|
|
4
|
+
* It converts the given value to a number and floors it to an integer. If the value is less than `0`, it returns `0`. If the value exceeds `2^32 - 1`, it returns `2^32 - 1`.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} value - The value to convert to a valid index.
|
|
7
|
+
* @returns {number} The converted value.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* toLength(3.2) // => 3
|
|
11
|
+
* toLength(-1) // => 0
|
|
12
|
+
* toLength(1.9) // => 1
|
|
13
|
+
* toLength('42') // => 42
|
|
14
|
+
* toLength(null) // => 0
|
|
15
|
+
*/
|
|
16
|
+
declare function toLength(value?: unknown): number;
|
|
17
|
+
|
|
18
|
+
export { toLength };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the value to a valid index. A valid index is an integer that is greater than or equal to `0` and less than or equal to `2^32 - 1`.
|
|
3
|
+
*
|
|
4
|
+
* It converts the given value to a number and floors it to an integer. If the value is less than `0`, it returns `0`. If the value exceeds `2^32 - 1`, it returns `2^32 - 1`.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} value - The value to convert to a valid index.
|
|
7
|
+
* @returns {number} The converted value.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* toLength(3.2) // => 3
|
|
11
|
+
* toLength(-1) // => 0
|
|
12
|
+
* toLength(1.9) // => 1
|
|
13
|
+
* toLength('42') // => 42
|
|
14
|
+
* toLength(null) // => 0
|
|
15
|
+
*/
|
|
16
|
+
declare function toLength(value?: unknown): number;
|
|
17
|
+
|
|
18
|
+
export { toLength };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MAX_ARRAY_LENGTH } from '../_internal/MAX_ARRAY_LENGTH.mjs';
|
|
2
|
+
import { clamp } from '../math/clamp.mjs';
|
|
3
|
+
|
|
4
|
+
function toLength(value) {
|
|
5
|
+
if (value == null) {
|
|
6
|
+
return 0;
|
|
7
|
+
}
|
|
8
|
+
const length = Math.floor(Number(value));
|
|
9
|
+
return clamp(length, 0, MAX_ARRAY_LENGTH);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { toLength };
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - If `n` is 0, `func` will never be called.
|
|
7
7
|
* - If `n` is a positive integer, `func` will be called up to `n-1` times.
|
|
8
8
|
* @param {F} func - The function to be called with the limit applied.
|
|
9
|
-
* @returns {F} - A new function that:
|
|
9
|
+
* @returns {(...args: Parameters<F>) => ReturnType<F> | undefined} - A new function that:
|
|
10
10
|
* - Tracks the number of calls.
|
|
11
11
|
* - Invokes `func` until the `n-1`-th call.
|
|
12
12
|
* - Returns `undefined` if the number of calls reaches or exceeds `n`, stopping further calls.
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
* // Will not log anything.
|
|
27
27
|
* beforeFn();
|
|
28
28
|
*/
|
|
29
|
-
declare function before<F extends (...args: any[]) => any>(n: number, func: F): F;
|
|
29
|
+
declare function before<F extends (...args: any[]) => any>(n: number, func: F): (...args: Parameters<F>) => ReturnType<F> | undefined;
|
|
30
30
|
|
|
31
31
|
export { before };
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - If `n` is 0, `func` will never be called.
|
|
7
7
|
* - If `n` is a positive integer, `func` will be called up to `n-1` times.
|
|
8
8
|
* @param {F} func - The function to be called with the limit applied.
|
|
9
|
-
* @returns {F} - A new function that:
|
|
9
|
+
* @returns {(...args: Parameters<F>) => ReturnType<F> | undefined} - A new function that:
|
|
10
10
|
* - Tracks the number of calls.
|
|
11
11
|
* - Invokes `func` until the `n-1`-th call.
|
|
12
12
|
* - Returns `undefined` if the number of calls reaches or exceeds `n`, stopping further calls.
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
* // Will not log anything.
|
|
27
27
|
* beforeFn();
|
|
28
28
|
*/
|
|
29
|
-
declare function before<F extends (...args: any[]) => any>(n: number, func: F): F;
|
|
29
|
+
declare function before<F extends (...args: any[]) => any>(n: number, func: F): (...args: Parameters<F>) => ReturnType<F> | undefined;
|
|
30
30
|
|
|
31
31
|
export { before };
|
package/dist/function/before.mjs
CHANGED
|
@@ -3,12 +3,12 @@ function before(n, func) {
|
|
|
3
3
|
throw new Error('n must be a non-negative integer.');
|
|
4
4
|
}
|
|
5
5
|
let counter = 0;
|
|
6
|
-
return (
|
|
6
|
+
return (...args) => {
|
|
7
7
|
if (++counter < n) {
|
|
8
8
|
return func(...args);
|
|
9
9
|
}
|
|
10
10
|
return undefined;
|
|
11
|
-
}
|
|
11
|
+
};
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export { before };
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export { before } from './before.mjs';
|
|
2
1
|
export { after } from './after.mjs';
|
|
2
|
+
export { ary } from './ary.mjs';
|
|
3
|
+
export { before } from './before.mjs';
|
|
4
|
+
export { curry } from './curry.mjs';
|
|
5
|
+
export { curryRight } from './curryRight.mjs';
|
|
3
6
|
export { debounce } from './debounce.mjs';
|
|
7
|
+
export { flow } from './flow.mjs';
|
|
8
|
+
export { flowRight } from './flowRight.mjs';
|
|
9
|
+
export { MemoizeCache, memoize } from './memoize.mjs';
|
|
10
|
+
export { negate } from './negate.mjs';
|
|
4
11
|
export { noop } from './noop.mjs';
|
|
5
12
|
export { once } from './once.mjs';
|
|
6
|
-
export { throttle } from './throttle.mjs';
|
|
7
|
-
export { negate } from './negate.mjs';
|
|
8
|
-
export { MemoizeCache, memoize } from './memoize.mjs';
|
|
9
|
-
export { ary } from './ary.mjs';
|
|
10
|
-
export { unary } from './unary.mjs';
|
|
11
13
|
export { partial } from './partial.mjs';
|
|
12
14
|
export { partialRight } from './partialRight.mjs';
|
|
13
15
|
export { rest } from './rest.mjs';
|
|
14
|
-
export { curry } from './curry.mjs';
|
|
15
|
-
export { curryRight } from './curryRight.mjs';
|
|
16
16
|
export { spread } from './spread.mjs';
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
17
|
+
export { throttle } from './throttle.mjs';
|
|
18
|
+
export { unary } from './unary.mjs';
|
package/dist/function/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export { before } from './before.js';
|
|
2
1
|
export { after } from './after.js';
|
|
2
|
+
export { ary } from './ary.js';
|
|
3
|
+
export { before } from './before.js';
|
|
4
|
+
export { curry } from './curry.js';
|
|
5
|
+
export { curryRight } from './curryRight.js';
|
|
3
6
|
export { debounce } from './debounce.js';
|
|
7
|
+
export { flow } from './flow.js';
|
|
8
|
+
export { flowRight } from './flowRight.js';
|
|
9
|
+
export { MemoizeCache, memoize } from './memoize.js';
|
|
10
|
+
export { negate } from './negate.js';
|
|
4
11
|
export { noop } from './noop.js';
|
|
5
12
|
export { once } from './once.js';
|
|
6
|
-
export { throttle } from './throttle.js';
|
|
7
|
-
export { negate } from './negate.js';
|
|
8
|
-
export { MemoizeCache, memoize } from './memoize.js';
|
|
9
|
-
export { ary } from './ary.js';
|
|
10
|
-
export { unary } from './unary.js';
|
|
11
13
|
export { partial } from './partial.js';
|
|
12
14
|
export { partialRight } from './partialRight.js';
|
|
13
15
|
export { rest } from './rest.js';
|
|
14
|
-
export { curry } from './curry.js';
|
|
15
|
-
export { curryRight } from './curryRight.js';
|
|
16
16
|
export { spread } from './spread.js';
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
17
|
+
export { throttle } from './throttle.js';
|
|
18
|
+
export { unary } from './unary.js';
|
package/dist/function/index.js
CHANGED
|
@@ -2,28 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const unary = require('../_chunk/unary-BZ5Ixo.js');
|
|
6
6
|
const noop = require('../_chunk/noop-2IwLUk.js');
|
|
7
7
|
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (Date.now() - pendingAt >= throttleMs) {
|
|
17
|
-
pendingAt = Date.now();
|
|
18
|
-
debounced.cancel();
|
|
19
|
-
debounced(...args);
|
|
20
|
-
}
|
|
8
|
+
function before(n, func) {
|
|
9
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
10
|
+
throw new Error('n must be a non-negative integer.');
|
|
11
|
+
}
|
|
12
|
+
let counter = 0;
|
|
13
|
+
return (...args) => {
|
|
14
|
+
if (++counter < n) {
|
|
15
|
+
return func(...args);
|
|
21
16
|
}
|
|
22
|
-
|
|
17
|
+
return undefined;
|
|
23
18
|
};
|
|
24
|
-
throttled.cancel = debounced.cancel;
|
|
25
|
-
throttled.flush = debounced.flush;
|
|
26
|
-
return throttled;
|
|
27
19
|
}
|
|
28
20
|
|
|
29
21
|
function curry(func) {
|
|
@@ -46,27 +38,68 @@ function makeCurry(origin, argsLength, args) {
|
|
|
46
38
|
}
|
|
47
39
|
}
|
|
48
40
|
|
|
41
|
+
function curryRight(func) {
|
|
42
|
+
if (func.length === 0 || func.length === 1) {
|
|
43
|
+
return func;
|
|
44
|
+
}
|
|
45
|
+
return function (arg) {
|
|
46
|
+
return makeCurryRight(func, func.length, [arg]);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function makeCurryRight(origin, argsLength, args) {
|
|
50
|
+
if (args.length === argsLength) {
|
|
51
|
+
return origin(...args);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const next = function (arg) {
|
|
55
|
+
return makeCurryRight(origin, argsLength, [arg, ...args]);
|
|
56
|
+
};
|
|
57
|
+
return next;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
49
61
|
function spread(func) {
|
|
50
62
|
return function (argsArr) {
|
|
51
63
|
return func.apply(this, argsArr);
|
|
52
64
|
};
|
|
53
65
|
}
|
|
54
66
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
function throttle(func, throttleMs, { signal, edges = ['leading', 'trailing'] } = {}) {
|
|
68
|
+
let pendingAt = null;
|
|
69
|
+
const debounced = unary.debounce(func, throttleMs, { signal, edges });
|
|
70
|
+
const throttled = function (...args) {
|
|
71
|
+
if (pendingAt == null) {
|
|
72
|
+
pendingAt = Date.now();
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
if (Date.now() - pendingAt >= throttleMs) {
|
|
76
|
+
pendingAt = Date.now();
|
|
77
|
+
debounced.cancel();
|
|
78
|
+
debounced(...args);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
debounced(...args);
|
|
82
|
+
};
|
|
83
|
+
throttled.cancel = debounced.cancel;
|
|
84
|
+
throttled.flush = debounced.flush;
|
|
85
|
+
return throttled;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
exports.after = unary.after;
|
|
89
|
+
exports.ary = unary.ary;
|
|
90
|
+
exports.debounce = unary.debounce;
|
|
91
|
+
exports.flow = unary.flow;
|
|
92
|
+
exports.flowRight = unary.flowRight;
|
|
93
|
+
exports.memoize = unary.memoize;
|
|
94
|
+
exports.negate = unary.negate;
|
|
95
|
+
exports.once = unary.once;
|
|
96
|
+
exports.partial = unary.partial;
|
|
97
|
+
exports.partialRight = unary.partialRight;
|
|
98
|
+
exports.rest = unary.rest;
|
|
99
|
+
exports.unary = unary.unary;
|
|
69
100
|
exports.noop = noop.noop;
|
|
101
|
+
exports.before = before;
|
|
70
102
|
exports.curry = curry;
|
|
103
|
+
exports.curryRight = curryRight;
|
|
71
104
|
exports.spread = spread;
|
|
72
105
|
exports.throttle = throttle;
|
package/dist/function/index.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export { before } from './before.mjs';
|
|
2
1
|
export { after } from './after.mjs';
|
|
2
|
+
export { ary } from './ary.mjs';
|
|
3
|
+
export { before } from './before.mjs';
|
|
4
|
+
export { curry } from './curry.mjs';
|
|
5
|
+
export { curryRight } from './curryRight.mjs';
|
|
3
6
|
export { debounce } from './debounce.mjs';
|
|
7
|
+
export { flow } from './flow.mjs';
|
|
8
|
+
export { flowRight } from './flowRight.mjs';
|
|
9
|
+
export { memoize } from './memoize.mjs';
|
|
10
|
+
export { negate } from './negate.mjs';
|
|
4
11
|
export { noop } from './noop.mjs';
|
|
5
12
|
export { once } from './once.mjs';
|
|
6
|
-
export { throttle } from './throttle.mjs';
|
|
7
|
-
export { negate } from './negate.mjs';
|
|
8
|
-
export { memoize } from './memoize.mjs';
|
|
9
|
-
export { ary } from './ary.mjs';
|
|
10
|
-
export { unary } from './unary.mjs';
|
|
11
13
|
export { partial } from './partial.mjs';
|
|
12
14
|
export { partialRight } from './partialRight.mjs';
|
|
13
15
|
export { rest } from './rest.mjs';
|
|
14
|
-
export { curry } from './curry.mjs';
|
|
15
|
-
export { curryRight } from './curryRight.mjs';
|
|
16
16
|
export { spread } from './spread.mjs';
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
17
|
+
export { throttle } from './throttle.mjs';
|
|
18
|
+
export { unary } from './unary.mjs';
|
package/dist/function/once.d.mts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Repeated calls to the function will return the value from the first invocation.
|
|
4
4
|
*
|
|
5
5
|
* @template F - The type of function.
|
|
6
|
-
* @param {F} func - The function to restrict.
|
|
6
|
+
* @param {F extends () => any} func - The function to restrict.
|
|
7
7
|
* @returns {F} A new function that invokes `func` once and caches the result.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
@@ -16,5 +16,20 @@
|
|
|
16
16
|
* initialize(); // Returns true without logging
|
|
17
17
|
*/
|
|
18
18
|
declare function once<F extends () => any>(func: F): F;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a function that is restricted to invoking the provided function `func` once.
|
|
21
|
+
* Repeated calls to the function will return the value from the first invocation.
|
|
22
|
+
*
|
|
23
|
+
* @template F - The type of function.
|
|
24
|
+
* @param {F extends (...args: any[]) => void} func - The function to restrict with arguments.
|
|
25
|
+
* @returns {F} A new function that invokes `func` once.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const log = once(console.log);
|
|
29
|
+
*
|
|
30
|
+
* log('Hello, world!'); // prints 'Hello, world!' and doesn't return anything
|
|
31
|
+
* log('Hello, world!'); // doesn't print anything and doesn't return anything
|
|
32
|
+
*/
|
|
33
|
+
declare function once<F extends (...args: any[]) => void>(func: F): F;
|
|
19
34
|
|
|
20
35
|
export { once };
|
package/dist/function/once.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Repeated calls to the function will return the value from the first invocation.
|
|
4
4
|
*
|
|
5
5
|
* @template F - The type of function.
|
|
6
|
-
* @param {F} func - The function to restrict.
|
|
6
|
+
* @param {F extends () => any} func - The function to restrict.
|
|
7
7
|
* @returns {F} A new function that invokes `func` once and caches the result.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
@@ -16,5 +16,20 @@
|
|
|
16
16
|
* initialize(); // Returns true without logging
|
|
17
17
|
*/
|
|
18
18
|
declare function once<F extends () => any>(func: F): F;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a function that is restricted to invoking the provided function `func` once.
|
|
21
|
+
* Repeated calls to the function will return the value from the first invocation.
|
|
22
|
+
*
|
|
23
|
+
* @template F - The type of function.
|
|
24
|
+
* @param {F extends (...args: any[]) => void} func - The function to restrict with arguments.
|
|
25
|
+
* @returns {F} A new function that invokes `func` once.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const log = once(console.log);
|
|
29
|
+
*
|
|
30
|
+
* log('Hello, world!'); // prints 'Hello, world!' and doesn't return anything
|
|
31
|
+
* log('Hello, world!'); // doesn't print anything and doesn't return anything
|
|
32
|
+
*/
|
|
33
|
+
declare function once<F extends (...args: any[]) => void>(func: F): F;
|
|
19
34
|
|
|
20
35
|
export { once };
|
package/dist/function/once.mjs
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
function once(func) {
|
|
2
2
|
let called = false;
|
|
3
3
|
let cache;
|
|
4
|
-
return function () {
|
|
5
|
-
if (called) {
|
|
6
|
-
|
|
4
|
+
return function (...args) {
|
|
5
|
+
if (!called) {
|
|
6
|
+
called = true;
|
|
7
|
+
cache = func(...args);
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
called = true;
|
|
10
|
-
cache = result;
|
|
11
|
-
return result;
|
|
9
|
+
return cache;
|
|
12
10
|
};
|
|
13
11
|
}
|
|
14
12
|
|
package/dist/index.d.mts
CHANGED
|
@@ -56,91 +56,93 @@ export { zipObject } from './array/zipObject.mjs';
|
|
|
56
56
|
export { zipWith } from './array/zipWith.mjs';
|
|
57
57
|
export { AbortError } from './error/AbortError.mjs';
|
|
58
58
|
export { TimeoutError } from './error/TimeoutError.mjs';
|
|
59
|
-
export { before } from './function/before.mjs';
|
|
60
59
|
export { after } from './function/after.mjs';
|
|
60
|
+
export { ary } from './function/ary.mjs';
|
|
61
|
+
export { before } from './function/before.mjs';
|
|
62
|
+
export { curry } from './function/curry.mjs';
|
|
63
|
+
export { curryRight } from './function/curryRight.mjs';
|
|
61
64
|
export { debounce } from './function/debounce.mjs';
|
|
65
|
+
export { flow } from './function/flow.mjs';
|
|
66
|
+
export { flowRight } from './function/flowRight.mjs';
|
|
67
|
+
export { MemoizeCache, memoize } from './function/memoize.mjs';
|
|
68
|
+
export { negate } from './function/negate.mjs';
|
|
62
69
|
export { noop } from './function/noop.mjs';
|
|
63
70
|
export { once } from './function/once.mjs';
|
|
64
|
-
export { throttle } from './function/throttle.mjs';
|
|
65
|
-
export { negate } from './function/negate.mjs';
|
|
66
|
-
export { MemoizeCache, memoize } from './function/memoize.mjs';
|
|
67
|
-
export { ary } from './function/ary.mjs';
|
|
68
|
-
export { unary } from './function/unary.mjs';
|
|
69
71
|
export { partial } from './function/partial.mjs';
|
|
70
72
|
export { partialRight } from './function/partialRight.mjs';
|
|
71
73
|
export { rest } from './function/rest.mjs';
|
|
72
|
-
export { curry } from './function/curry.mjs';
|
|
73
|
-
export { curryRight } from './function/curryRight.mjs';
|
|
74
74
|
export { spread } from './function/spread.mjs';
|
|
75
|
-
export {
|
|
76
|
-
export {
|
|
75
|
+
export { throttle } from './function/throttle.mjs';
|
|
76
|
+
export { unary } from './function/unary.mjs';
|
|
77
77
|
export { clamp } from './math/clamp.mjs';
|
|
78
78
|
export { inRange } from './math/inRange.mjs';
|
|
79
79
|
export { mean } from './math/mean.mjs';
|
|
80
80
|
export { meanBy } from './math/meanBy.mjs';
|
|
81
81
|
export { random } from './math/random.mjs';
|
|
82
82
|
export { randomInt } from './math/randomInt.mjs';
|
|
83
|
+
export { range } from './math/range.mjs';
|
|
84
|
+
export { rangeRight } from './math/rangeRight.mjs';
|
|
83
85
|
export { round } from './math/round.mjs';
|
|
84
86
|
export { sum } from './math/sum.mjs';
|
|
85
87
|
export { sumBy } from './math/sumBy.mjs';
|
|
86
|
-
export { range } from './math/range.mjs';
|
|
87
|
-
export { omit } from './object/omit.mjs';
|
|
88
|
-
export { omitBy } from './object/omitBy.mjs';
|
|
89
|
-
export { pick } from './object/pick.mjs';
|
|
90
|
-
export { pickBy } from './object/pickBy.mjs';
|
|
91
|
-
export { invert } from './object/invert.mjs';
|
|
92
88
|
export { clone } from './object/clone.mjs';
|
|
89
|
+
export { cloneDeep } from './object/cloneDeep.mjs';
|
|
93
90
|
export { flattenObject } from './object/flattenObject.mjs';
|
|
91
|
+
export { invert } from './object/invert.mjs';
|
|
94
92
|
export { mapKeys } from './object/mapKeys.mjs';
|
|
95
93
|
export { mapValues } from './object/mapValues.mjs';
|
|
96
|
-
export { cloneDeep } from './object/cloneDeep.mjs';
|
|
97
94
|
export { merge } from './object/merge.mjs';
|
|
98
|
-
export { toMerged } from './object/toMerged.mjs';
|
|
99
95
|
export { mergeWith } from './object/mergeWith.mjs';
|
|
96
|
+
export { omit } from './object/omit.mjs';
|
|
97
|
+
export { omitBy } from './object/omitBy.mjs';
|
|
98
|
+
export { pick } from './object/pick.mjs';
|
|
99
|
+
export { pickBy } from './object/pickBy.mjs';
|
|
100
|
+
export { toMerged } from './object/toMerged.mjs';
|
|
100
101
|
export { isArrayBuffer } from './predicate/isArrayBuffer.mjs';
|
|
102
|
+
export { isBlob } from './predicate/isBlob.mjs';
|
|
103
|
+
export { isBoolean } from './predicate/isBoolean.mjs';
|
|
101
104
|
export { isDate } from './predicate/isDate.mjs';
|
|
102
105
|
export { isEqual } from './predicate/isEqual.mjs';
|
|
103
106
|
export { isEqualWith } from './predicate/isEqualWith.mjs';
|
|
104
107
|
export { isError } from './predicate/isError.mjs';
|
|
108
|
+
export { isFunction } from './predicate/isFunction.mjs';
|
|
109
|
+
export { isJSONArray } from './predicate/isJSONArray.mjs';
|
|
110
|
+
export { isJSONObject } from './predicate/isJSONObject.mjs';
|
|
111
|
+
export { isJSONValue } from './predicate/isJSONValue.mjs';
|
|
112
|
+
export { isLength } from './predicate/isLength.mjs';
|
|
105
113
|
export { isMap } from './predicate/isMap.mjs';
|
|
106
114
|
export { isNil } from './predicate/isNil.mjs';
|
|
107
115
|
export { isNotNil } from './predicate/isNotNil.mjs';
|
|
108
116
|
export { isNull } from './predicate/isNull.mjs';
|
|
109
|
-
export { isUndefined } from './predicate/isUndefined.mjs';
|
|
110
|
-
export { isLength } from './predicate/isLength.mjs';
|
|
111
117
|
export { isPlainObject } from './predicate/isPlainObject.mjs';
|
|
112
|
-
export { isFunction } from './predicate/isFunction.mjs';
|
|
113
|
-
export { isTypedArray } from './predicate/isTypedArray.mjs';
|
|
114
118
|
export { isPrimitive } from './predicate/isPrimitive.mjs';
|
|
115
119
|
export { isRegExp } from './predicate/isRegExp.mjs';
|
|
116
|
-
export { isBoolean } from './predicate/isBoolean.mjs';
|
|
117
|
-
export { isSymbol } from './predicate/isSymbol.mjs';
|
|
118
|
-
export { isString } from './predicate/isString.mjs';
|
|
119
|
-
export { isJSONObject } from './predicate/isJSONObject.mjs';
|
|
120
|
-
export { isJSONValue } from './predicate/isJSONValue.mjs';
|
|
121
|
-
export { isJSONArray } from './predicate/isJSONArray.mjs';
|
|
122
120
|
export { isSet } from './predicate/isSet.mjs';
|
|
121
|
+
export { isString } from './predicate/isString.mjs';
|
|
122
|
+
export { isSymbol } from './predicate/isSymbol.mjs';
|
|
123
|
+
export { isTypedArray } from './predicate/isTypedArray.mjs';
|
|
124
|
+
export { isUndefined } from './predicate/isUndefined.mjs';
|
|
123
125
|
export { isWeakMap } from './predicate/isWeakMap.mjs';
|
|
124
126
|
export { isWeakSet } from './predicate/isWeakSet.mjs';
|
|
125
127
|
export { delay } from './promise/delay.mjs';
|
|
126
|
-
export { withTimeout } from './promise/withTimeout.mjs';
|
|
127
128
|
export { timeout } from './promise/timeout.mjs';
|
|
129
|
+
export { withTimeout } from './promise/withTimeout.mjs';
|
|
128
130
|
export { camelCase } from './string/camelCase.mjs';
|
|
129
|
-
export { snakeCase } from './string/snakeCase.mjs';
|
|
130
|
-
export { kebabCase } from './string/kebabCase.mjs';
|
|
131
|
-
export { upperCase } from './string/upperCase.mjs';
|
|
132
|
-
export { lowerCase } from './string/lowerCase.mjs';
|
|
133
|
-
export { startCase } from './string/startCase.mjs';
|
|
134
131
|
export { capitalize } from './string/capitalize.mjs';
|
|
135
|
-
export { pascalCase } from './string/pascalCase.mjs';
|
|
136
132
|
export { constantCase } from './string/constantCase.mjs';
|
|
137
|
-
export { trim } from './string/trim.mjs';
|
|
138
|
-
export { trimStart } from './string/trimStart.mjs';
|
|
139
|
-
export { trimEnd } from './string/trimEnd.mjs';
|
|
140
|
-
export { upperFirst } from './string/upperFirst.mjs';
|
|
141
|
-
export { lowerFirst } from './string/lowerFirst.mjs';
|
|
142
133
|
export { deburr } from './string/deburr.mjs';
|
|
143
134
|
export { escape } from './string/escape.mjs';
|
|
144
135
|
export { escapeRegExp } from './string/escapeRegExp.mjs';
|
|
145
|
-
export {
|
|
136
|
+
export { kebabCase } from './string/kebabCase.mjs';
|
|
137
|
+
export { lowerCase } from './string/lowerCase.mjs';
|
|
138
|
+
export { lowerFirst } from './string/lowerFirst.mjs';
|
|
146
139
|
export { pad } from './string/pad.mjs';
|
|
140
|
+
export { pascalCase } from './string/pascalCase.mjs';
|
|
141
|
+
export { snakeCase } from './string/snakeCase.mjs';
|
|
142
|
+
export { startCase } from './string/startCase.mjs';
|
|
143
|
+
export { trim } from './string/trim.mjs';
|
|
144
|
+
export { trimEnd } from './string/trimEnd.mjs';
|
|
145
|
+
export { trimStart } from './string/trimStart.mjs';
|
|
146
|
+
export { unescape } from './string/unescape.mjs';
|
|
147
|
+
export { upperCase } from './string/upperCase.mjs';
|
|
148
|
+
export { upperFirst } from './string/upperFirst.mjs';
|