es-toolkit 1.17.0 → 1.18.0-dev.573
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 +7 -0
- package/README.md +1 -1
- package/dist/_chunk/{index-CoqN5B.js → index-BGZDR9.js} +4 -1
- package/dist/_chunk/{isTypedArray-BBEkFl.js → isTypedArray-Dsrnb1.js} +1 -11
- package/dist/_chunk/{isFunction-aCEz9d.js → isWeakSet-BerD1A.js} +12 -2
- package/dist/_chunk/rest-CXt9w3.js +182 -0
- package/dist/_chunk/{toMerged-BGwYW5.js → toMerged-DN1PPP.js} +1 -1
- package/dist/_chunk/{initial-Ci2bn_.js → zipWith-CYaH1Y.js} +46 -70
- package/dist/array/countBy.d.mts +10 -0
- package/dist/array/countBy.d.ts +10 -0
- package/dist/array/fill.d.mts +55 -2
- package/dist/array/fill.d.ts +55 -2
- package/dist/array/flatMapDeep.d.mts +18 -0
- package/dist/array/flatMapDeep.d.ts +18 -0
- package/dist/array/flatMapDeep.mjs +7 -0
- package/dist/array/flattenDeep.d.mts +1 -1
- package/dist/array/flattenDeep.d.ts +1 -1
- package/dist/array/head.d.mts +14 -3
- package/dist/array/head.d.ts +14 -3
- package/dist/array/index.d.mts +9 -8
- package/dist/array/index.d.ts +9 -8
- package/dist/array/index.js +87 -58
- package/dist/array/index.mjs +9 -8
- package/dist/array/last.d.mts +23 -1
- package/dist/array/last.d.ts +23 -1
- package/dist/array/maxBy.d.mts +13 -1
- package/dist/array/maxBy.d.ts +13 -1
- package/dist/array/minBy.d.mts +13 -1
- package/dist/array/minBy.d.ts +13 -1
- package/dist/array/toFilled.d.mts +59 -2
- package/dist/array/toFilled.d.ts +59 -2
- package/dist/array/zip.d.mts +65 -7
- package/dist/array/zip.d.ts +65 -7
- package/dist/array/zipObject.d.mts +2 -4
- package/dist/array/zipObject.d.ts +2 -4
- package/dist/array/zipWith.d.mts +39 -6
- package/dist/array/zipWith.d.ts +39 -6
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/compareValues.mjs +30 -5
- package/dist/compat/_internal/normalizeForCase.mjs +9 -0
- package/dist/compat/array/castArray.d.mts +29 -0
- package/dist/compat/array/castArray.d.ts +29 -0
- package/dist/compat/array/castArray.mjs +8 -0
- package/dist/compat/array/difference.d.mts +19 -0
- package/dist/compat/array/difference.d.ts +19 -0
- package/dist/compat/array/fill.d.mts +55 -2
- package/dist/compat/array/fill.d.ts +55 -2
- package/dist/compat/array/findLastIndex.d.mts +66 -0
- package/dist/compat/array/findLastIndex.d.ts +66 -0
- package/dist/compat/array/findLastIndex.mjs +33 -0
- package/dist/compat/array/join.d.mts +16 -0
- package/dist/compat/array/join.d.ts +16 -0
- package/dist/compat/array/join.mjs +5 -0
- package/dist/compat/array/orderBy.d.mts +6 -6
- package/dist/compat/array/orderBy.d.ts +6 -6
- package/dist/compat/array/orderBy.mjs +26 -18
- package/dist/compat/array/some.d.mts +86 -0
- package/dist/compat/array/some.d.ts +86 -0
- package/dist/compat/array/some.mjs +36 -0
- package/dist/compat/array/sortBy.d.mts +34 -0
- package/dist/compat/array/sortBy.d.ts +34 -0
- package/dist/compat/array/sortBy.mjs +7 -0
- package/dist/compat/function/ary.d.mts +11 -1
- package/dist/compat/function/ary.d.ts +11 -1
- package/dist/compat/function/attempt.d.mts +33 -0
- package/dist/compat/function/attempt.d.ts +33 -0
- package/dist/compat/function/attempt.mjs +10 -0
- package/dist/compat/function/bindKey.d.mts +45 -0
- package/dist/compat/function/bindKey.d.ts +45 -0
- package/dist/compat/function/bindKey.mjs +27 -0
- package/dist/compat/function/rearg.d.mts +18 -0
- package/dist/compat/function/rearg.d.ts +18 -0
- package/dist/compat/function/rearg.mjs +14 -0
- package/dist/compat/function/spread.d.mts +47 -0
- package/dist/compat/function/spread.d.ts +47 -0
- package/dist/compat/function/spread.mjs +16 -0
- package/dist/compat/index.d.mts +31 -10
- package/dist/compat/index.d.ts +31 -10
- package/dist/compat/index.js +401 -143
- package/dist/compat/index.mjs +32 -11
- package/dist/compat/math/max.d.mts +16 -5
- package/dist/compat/math/max.d.ts +16 -5
- package/dist/compat/math/min.d.mts +16 -4
- package/dist/compat/math/min.d.ts +16 -4
- package/dist/compat/math/parseInt.d.mts +20 -0
- package/dist/compat/math/parseInt.d.ts +20 -0
- package/dist/compat/math/parseInt.mjs +8 -0
- package/dist/compat/object/fromPairs.d.mts +29 -0
- package/dist/compat/object/fromPairs.d.ts +29 -0
- package/dist/compat/object/fromPairs.mjs +14 -0
- package/dist/compat/predicate/conforms.d.mts +22 -0
- package/dist/compat/predicate/conforms.d.ts +22 -0
- package/dist/compat/predicate/conforms.mjs +11 -0
- package/dist/compat/predicate/conformsTo.d.mts +29 -0
- package/dist/compat/predicate/conformsTo.d.ts +29 -0
- package/dist/compat/predicate/conformsTo.mjs +18 -0
- package/dist/compat/predicate/isObject.d.mts +26 -0
- package/dist/compat/predicate/isObject.d.ts +26 -0
- package/dist/compat/predicate/isObject.mjs +5 -0
- package/dist/compat/predicate/isRegExp.d.mts +7 -0
- package/dist/compat/predicate/isRegExp.d.ts +7 -0
- package/dist/compat/predicate/isTypedArray.d.mts +10 -0
- package/dist/compat/predicate/isTypedArray.d.ts +10 -0
- package/dist/compat/predicate/isWeakMap.d.mts +23 -0
- package/dist/compat/predicate/isWeakMap.d.ts +23 -0
- package/dist/compat/predicate/isWeakMap.mjs +7 -0
- package/dist/compat/predicate/isWeakSet.d.mts +23 -0
- package/dist/compat/predicate/isWeakSet.d.ts +23 -0
- package/dist/compat/predicate/isWeakSet.mjs +7 -0
- package/dist/compat/string/camelCase.d.mts +18 -0
- package/dist/compat/string/camelCase.d.ts +18 -0
- package/dist/compat/string/camelCase.mjs +8 -0
- package/dist/compat/string/endsWith.d.mts +1 -1
- package/dist/compat/string/endsWith.d.ts +1 -1
- package/dist/compat/string/endsWith.mjs +2 -2
- package/dist/compat/string/repeat.d.mts +17 -0
- package/dist/compat/string/repeat.d.ts +17 -0
- package/dist/compat/string/repeat.mjs +5 -0
- package/dist/compat/string/startsWith.d.mts +1 -1
- package/dist/compat/string/startsWith.d.ts +1 -1
- package/dist/compat/string/startsWith.mjs +2 -2
- package/dist/function/after.d.mts +1 -1
- package/dist/function/after.d.ts +1 -1
- package/dist/function/after.mjs +2 -2
- package/dist/function/before.d.mts +1 -1
- package/dist/function/before.d.ts +1 -1
- package/dist/function/before.mjs +2 -2
- package/dist/function/debounce.d.mts +3 -3
- package/dist/function/debounce.d.ts +3 -3
- package/dist/function/index.d.mts +1 -0
- package/dist/function/index.d.ts +1 -0
- package/dist/function/index.js +22 -180
- package/dist/function/index.mjs +1 -0
- package/dist/function/memoize.d.mts +37 -1
- package/dist/function/memoize.d.ts +37 -1
- package/dist/function/negate.d.mts +7 -1
- package/dist/function/negate.d.ts +7 -1
- package/dist/function/spread.d.mts +19 -0
- package/dist/function/spread.d.ts +19 -0
- package/dist/function/spread.mjs +7 -0
- package/dist/function/unary.d.mts +7 -0
- package/dist/function/unary.d.ts +7 -0
- package/dist/index.d.mts +16 -8
- package/dist/index.d.ts +16 -8
- package/dist/index.js +89 -80
- package/dist/index.mjs +16 -8
- package/dist/math/clamp.d.mts +14 -3
- package/dist/math/clamp.d.ts +14 -3
- package/dist/math/random.d.mts +13 -2
- package/dist/math/random.d.ts +13 -2
- package/dist/math/randomInt.d.mts +11 -3
- package/dist/math/randomInt.d.ts +11 -3
- package/dist/math/range.d.mts +25 -0
- package/dist/math/range.d.ts +25 -0
- package/dist/object/index.js +1 -1
- package/dist/object/invert.d.mts +2 -4
- package/dist/object/invert.d.ts +2 -4
- package/dist/predicate/index.d.mts +2 -0
- package/dist/predicate/index.d.ts +2 -0
- package/dist/predicate/index.js +11 -9
- package/dist/predicate/index.mjs +2 -0
- package/dist/predicate/isNotNil.mjs +1 -1
- package/dist/predicate/isPrimitive.d.mts +14 -0
- package/dist/predicate/isPrimitive.d.ts +14 -0
- package/dist/predicate/isRegExp.d.mts +8 -1
- package/dist/predicate/isRegExp.d.ts +8 -1
- package/dist/predicate/isSymbol.d.mts +15 -0
- package/dist/predicate/isSymbol.d.ts +15 -0
- package/dist/predicate/isTypedArray.d.mts +10 -0
- package/dist/predicate/isTypedArray.d.ts +10 -0
- package/dist/predicate/isTypedArray.mjs +1 -11
- package/dist/predicate/isWeakMap.d.mts +23 -0
- package/dist/predicate/isWeakMap.d.ts +23 -0
- package/dist/predicate/isWeakMap.mjs +5 -0
- package/dist/predicate/isWeakSet.d.mts +23 -0
- package/dist/predicate/isWeakSet.d.ts +23 -0
- package/dist/predicate/isWeakSet.mjs +5 -0
- package/dist/promise/delay.mjs +4 -1
- package/dist/promise/index.js +1 -1
- package/dist/promise/timeout.d.mts +7 -0
- package/dist/promise/timeout.d.ts +7 -0
- package/dist/string/capitalize.d.mts +1 -1
- package/dist/string/capitalize.d.ts +1 -1
- package/dist/string/capitalize.mjs +2 -2
- package/dist/string/deburr.mjs +5 -5
- package/dist/string/escape.d.mts +16 -0
- package/dist/string/escape.d.ts +16 -0
- package/dist/string/escape.mjs +12 -0
- package/dist/string/escapeRegExp.d.mts +14 -0
- package/dist/string/escapeRegExp.d.ts +14 -0
- package/dist/string/escapeRegExp.mjs +5 -0
- package/dist/string/index.d.mts +4 -0
- package/dist/string/index.d.ts +4 -0
- package/dist/string/index.js +53 -19
- package/dist/string/index.mjs +4 -0
- package/dist/string/kebabCase.d.mts +1 -1
- package/dist/string/kebabCase.d.ts +1 -1
- package/dist/string/kebabCase.mjs +2 -2
- package/dist/string/lowerCase.d.mts +1 -1
- package/dist/string/lowerCase.d.ts +1 -1
- package/dist/string/lowerCase.mjs +2 -2
- package/dist/string/lowerFirst.d.mts +1 -1
- package/dist/string/lowerFirst.d.ts +1 -1
- package/dist/string/lowerFirst.mjs +2 -2
- package/dist/string/pad.d.mts +19 -0
- package/dist/string/pad.d.ts +19 -0
- package/dist/string/pad.mjs +5 -0
- package/dist/string/pascalCase.d.mts +1 -1
- package/dist/string/pascalCase.d.ts +1 -1
- package/dist/string/pascalCase.mjs +2 -2
- package/dist/string/snakeCase.d.mts +1 -1
- package/dist/string/snakeCase.d.ts +1 -1
- package/dist/string/snakeCase.mjs +2 -2
- package/dist/string/unescape.d.mts +16 -0
- package/dist/string/unescape.d.ts +16 -0
- package/dist/string/unescape.mjs +12 -0
- package/dist/string/upperFirst.d.mts +1 -1
- package/dist/string/upperFirst.d.ts +1 -1
- package/dist/string/upperFirst.mjs +2 -2
- package/package.json +7 -2
|
@@ -13,6 +13,16 @@
|
|
|
13
13
|
* | BigInt64Array
|
|
14
14
|
* | Float32Array
|
|
15
15
|
* | Float64Array} Returns true if `x` is a TypedArray, false otherwise.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const arr = new Uint8Array([1, 2, 3]);
|
|
19
|
+
* isTypedArray(arr); // true
|
|
20
|
+
*
|
|
21
|
+
* const regularArray = [1, 2, 3];
|
|
22
|
+
* isTypedArray(regularArray); // false
|
|
23
|
+
*
|
|
24
|
+
* const buffer = new ArrayBuffer(16);
|
|
25
|
+
* isTypedArray(buffer); // false
|
|
16
26
|
*/
|
|
17
27
|
declare function isTypedArray(x?: unknown): x is Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | BigUint64Array | Int8Array | Int16Array | Int32Array | BigInt64Array | Float32Array | Float64Array;
|
|
18
28
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given value is a `WeakMap`.
|
|
3
|
+
*
|
|
4
|
+
* This function tests whether the provided value is an instance of `WeakMap`.
|
|
5
|
+
* It returns `true` if the value is a `WeakMap`, and `false` otherwise.
|
|
6
|
+
*
|
|
7
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `WeakMap`.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} value - The value to test if it is a `WeakMap`.
|
|
10
|
+
* @returns {value is WeakMap<WeakKey, any>} true if the value is a `WeakMap`, false otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const value1 = new WeakMap();
|
|
14
|
+
* const value2 = new Map();
|
|
15
|
+
* const value3 = new Set();
|
|
16
|
+
*
|
|
17
|
+
* console.log(isWeakMap(value1)); // true
|
|
18
|
+
* console.log(isWeakMap(value2)); // false
|
|
19
|
+
* console.log(isWeakMap(value3)); // false
|
|
20
|
+
*/
|
|
21
|
+
declare function isWeakMap(value?: unknown): value is WeakMap<WeakKey, any>;
|
|
22
|
+
|
|
23
|
+
export { isWeakMap };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given value is a `WeakMap`.
|
|
3
|
+
*
|
|
4
|
+
* This function tests whether the provided value is an instance of `WeakMap`.
|
|
5
|
+
* It returns `true` if the value is a `WeakMap`, and `false` otherwise.
|
|
6
|
+
*
|
|
7
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `WeakMap`.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} value - The value to test if it is a `WeakMap`.
|
|
10
|
+
* @returns {value is WeakMap<WeakKey, any>} true if the value is a `WeakMap`, false otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const value1 = new WeakMap();
|
|
14
|
+
* const value2 = new Map();
|
|
15
|
+
* const value3 = new Set();
|
|
16
|
+
*
|
|
17
|
+
* console.log(isWeakMap(value1)); // true
|
|
18
|
+
* console.log(isWeakMap(value2)); // false
|
|
19
|
+
* console.log(isWeakMap(value3)); // false
|
|
20
|
+
*/
|
|
21
|
+
declare function isWeakMap(value?: unknown): value is WeakMap<WeakKey, any>;
|
|
22
|
+
|
|
23
|
+
export { isWeakMap };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given value is a `WeakSet`.
|
|
3
|
+
*
|
|
4
|
+
* This function tests whether the provided value is an instance of `WeakSet`.
|
|
5
|
+
* It returns `true` if the value is a `WeakSet`, and `false` otherwise.
|
|
6
|
+
*
|
|
7
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `WeakSet`.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} value - The value to test if it is a `WeakSet`.
|
|
10
|
+
* @returns {value is WeakSet<WeakKey>} true if the value is a `WeakSet`, false otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const value1 = new WeakSet();
|
|
14
|
+
* const value2 = new Map();
|
|
15
|
+
* const value3 = new Set();
|
|
16
|
+
*
|
|
17
|
+
* console.log(isWeakSet(value1)); // true
|
|
18
|
+
* console.log(isWeakSet(value2)); // false
|
|
19
|
+
* console.log(isWeakSet(value3)); // false
|
|
20
|
+
*/
|
|
21
|
+
declare function isWeakSet(value?: unknown): value is WeakSet<WeakKey>;
|
|
22
|
+
|
|
23
|
+
export { isWeakSet };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given value is a `WeakSet`.
|
|
3
|
+
*
|
|
4
|
+
* This function tests whether the provided value is an instance of `WeakSet`.
|
|
5
|
+
* It returns `true` if the value is a `WeakSet`, and `false` otherwise.
|
|
6
|
+
*
|
|
7
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `WeakSet`.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} value - The value to test if it is a `WeakSet`.
|
|
10
|
+
* @returns {value is WeakSet<WeakKey>} true if the value is a `WeakSet`, false otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const value1 = new WeakSet();
|
|
14
|
+
* const value2 = new Map();
|
|
15
|
+
* const value3 = new Set();
|
|
16
|
+
*
|
|
17
|
+
* console.log(isWeakSet(value1)); // true
|
|
18
|
+
* console.log(isWeakSet(value2)); // false
|
|
19
|
+
* console.log(isWeakSet(value3)); // false
|
|
20
|
+
*/
|
|
21
|
+
declare function isWeakSet(value?: unknown): value is WeakSet<WeakKey>;
|
|
22
|
+
|
|
23
|
+
export { isWeakSet };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to camel case.
|
|
3
|
+
*
|
|
4
|
+
* Camel case is the naming convention in which the first word is written in lowercase and
|
|
5
|
+
* each subsequent word begins with a capital letter, concatenated without any separator characters.
|
|
6
|
+
*
|
|
7
|
+
* @param {string | object} str - The string that is to be changed to camel case.
|
|
8
|
+
* @returns {string} - The converted string to camel case.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const convertedStr1 = camelCase('camelCase') // returns 'camelCase'
|
|
12
|
+
* const convertedStr2 = camelCase('some whitespace') // returns 'someWhitespace'
|
|
13
|
+
* const convertedStr3 = camelCase('hyphen-text') // returns 'hyphenText'
|
|
14
|
+
* const convertedStr4 = camelCase('HTTPRequest') // returns 'httpRequest'
|
|
15
|
+
*/
|
|
16
|
+
declare function camelCase(str: string | object): string;
|
|
17
|
+
|
|
18
|
+
export { camelCase };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to camel case.
|
|
3
|
+
*
|
|
4
|
+
* Camel case is the naming convention in which the first word is written in lowercase and
|
|
5
|
+
* each subsequent word begins with a capital letter, concatenated without any separator characters.
|
|
6
|
+
*
|
|
7
|
+
* @param {string | object} str - The string that is to be changed to camel case.
|
|
8
|
+
* @returns {string} - The converted string to camel case.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const convertedStr1 = camelCase('camelCase') // returns 'camelCase'
|
|
12
|
+
* const convertedStr2 = camelCase('some whitespace') // returns 'someWhitespace'
|
|
13
|
+
* const convertedStr3 = camelCase('hyphen-text') // returns 'hyphenText'
|
|
14
|
+
* const convertedStr4 = camelCase('HTTPRequest') // returns 'httpRequest'
|
|
15
|
+
*/
|
|
16
|
+
declare function camelCase(str: string | object): string;
|
|
17
|
+
|
|
18
|
+
export { camelCase };
|
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
* const isPrefix = endsWith('fooBar', 'foo', 3) // returns true
|
|
16
16
|
* const isPrefix = endsWith('fooBar', 'abc', 5) // returns false
|
|
17
17
|
*/
|
|
18
|
-
declare
|
|
18
|
+
declare function endsWith(str: string, target: string, position?: number): boolean;
|
|
19
19
|
|
|
20
20
|
export { endsWith };
|
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
* const isPrefix = endsWith('fooBar', 'foo', 3) // returns true
|
|
16
16
|
* const isPrefix = endsWith('fooBar', 'abc', 5) // returns false
|
|
17
17
|
*/
|
|
18
|
-
declare
|
|
18
|
+
declare function endsWith(str: string, target: string, position?: number): boolean;
|
|
19
19
|
|
|
20
20
|
export { endsWith };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repeats the given string n times.
|
|
3
|
+
*
|
|
4
|
+
* If n is less than 1, an empty string is returned, or if the string is an empty string,
|
|
5
|
+
* the original string is returned unchanged.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} str - The string to repeat.
|
|
8
|
+
* @param {number} n - The number of times to repeat the string.
|
|
9
|
+
* @returns {string} - The repeated string, or an empty string if n is less than 1.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* repeat('abc', 0); // ''
|
|
13
|
+
* repeat('abc', 2); // 'abcabc'
|
|
14
|
+
*/
|
|
15
|
+
declare function repeat(str: string, n: number): string;
|
|
16
|
+
|
|
17
|
+
export { repeat };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repeats the given string n times.
|
|
3
|
+
*
|
|
4
|
+
* If n is less than 1, an empty string is returned, or if the string is an empty string,
|
|
5
|
+
* the original string is returned unchanged.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} str - The string to repeat.
|
|
8
|
+
* @param {number} n - The number of times to repeat the string.
|
|
9
|
+
* @returns {string} - The repeated string, or an empty string if n is less than 1.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* repeat('abc', 0); // ''
|
|
13
|
+
* repeat('abc', 2); // 'abcabc'
|
|
14
|
+
*/
|
|
15
|
+
declare function repeat(str: string, n: number): string;
|
|
16
|
+
|
|
17
|
+
export { repeat };
|
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
* const isPrefix = startsWith('fooBar', 'Bar', 2) // returns true
|
|
16
16
|
* const isPrefix = startsWith('fooBar', 'Bar', 5) // returns false
|
|
17
17
|
*/
|
|
18
|
-
declare
|
|
18
|
+
declare function startsWith(str: string, target: string, position?: number): boolean;
|
|
19
19
|
|
|
20
20
|
export { startsWith };
|
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
* const isPrefix = startsWith('fooBar', 'Bar', 2) // returns true
|
|
16
16
|
* const isPrefix = startsWith('fooBar', 'Bar', 5) // returns false
|
|
17
17
|
*/
|
|
18
|
-
declare
|
|
18
|
+
declare function startsWith(str: string, target: string, position?: number): boolean;
|
|
19
19
|
|
|
20
20
|
export { startsWith };
|
package/dist/function/after.d.ts
CHANGED
package/dist/function/after.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
function after(n, func) {
|
|
2
2
|
if (!Number.isInteger(n) || n < 0) {
|
|
3
3
|
throw new Error(`n must be a non-negative integer.`);
|
|
4
4
|
}
|
|
@@ -9,6 +9,6 @@ const after = (n, func) => {
|
|
|
9
9
|
}
|
|
10
10
|
return undefined;
|
|
11
11
|
});
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
13
|
|
|
14
14
|
export { after };
|
package/dist/function/before.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
function before(n, func) {
|
|
2
2
|
if (!Number.isInteger(n) || n < 0) {
|
|
3
3
|
throw new Error('n must be a non-negative integer.');
|
|
4
4
|
}
|
|
@@ -9,6 +9,6 @@ const before = (n, func) => {
|
|
|
9
9
|
}
|
|
10
10
|
return undefined;
|
|
11
11
|
});
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
13
|
|
|
14
14
|
export { before };
|
|
@@ -9,9 +9,9 @@ interface DebounceOptions {
|
|
|
9
9
|
* @template F - The type of function.
|
|
10
10
|
* @param {F} func - The function to debounce.
|
|
11
11
|
* @param {number} debounceMs - The number of milliseconds to delay.
|
|
12
|
-
* @param {DebounceOptions} options - The options object
|
|
12
|
+
* @param {DebounceOptions} options - The options object
|
|
13
13
|
* @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.
|
|
14
|
-
* @returns
|
|
14
|
+
* @returns A new debounced function with a `cancel` method.
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* const debouncedFunction = debounce(() => {
|
|
@@ -36,7 +36,7 @@ interface DebounceOptions {
|
|
|
36
36
|
* // Will cancel the debounced function call
|
|
37
37
|
* controller.abort();
|
|
38
38
|
*/
|
|
39
|
-
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, { signal }?: DebounceOptions): F & {
|
|
39
|
+
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, { signal }?: DebounceOptions): ((...args: Parameters<F>) => void) & {
|
|
40
40
|
cancel: () => void;
|
|
41
41
|
};
|
|
42
42
|
|
|
@@ -9,9 +9,9 @@ interface DebounceOptions {
|
|
|
9
9
|
* @template F - The type of function.
|
|
10
10
|
* @param {F} func - The function to debounce.
|
|
11
11
|
* @param {number} debounceMs - The number of milliseconds to delay.
|
|
12
|
-
* @param {DebounceOptions} options - The options object
|
|
12
|
+
* @param {DebounceOptions} options - The options object
|
|
13
13
|
* @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.
|
|
14
|
-
* @returns
|
|
14
|
+
* @returns A new debounced function with a `cancel` method.
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* const debouncedFunction = debounce(() => {
|
|
@@ -36,7 +36,7 @@ interface DebounceOptions {
|
|
|
36
36
|
* // Will cancel the debounced function call
|
|
37
37
|
* controller.abort();
|
|
38
38
|
*/
|
|
39
|
-
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, { signal }?: DebounceOptions): F & {
|
|
39
|
+
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, { signal }?: DebounceOptions): ((...args: Parameters<F>) => void) & {
|
|
40
40
|
cancel: () => void;
|
|
41
41
|
};
|
|
42
42
|
|
package/dist/function/index.d.ts
CHANGED
package/dist/function/index.js
CHANGED
|
@@ -2,183 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return undefined;
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
function debounce(func, debounceMs, { signal } = {}) {
|
|
32
|
-
let timeoutId = null;
|
|
33
|
-
const debounced = function (...args) {
|
|
34
|
-
if (timeoutId !== null) {
|
|
35
|
-
clearTimeout(timeoutId);
|
|
36
|
-
}
|
|
37
|
-
if (signal?.aborted) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
timeoutId = setTimeout(() => {
|
|
41
|
-
func(...args);
|
|
42
|
-
timeoutId = null;
|
|
43
|
-
}, debounceMs);
|
|
44
|
-
};
|
|
45
|
-
const onAbort = function () {
|
|
46
|
-
debounced.cancel();
|
|
47
|
-
};
|
|
48
|
-
debounced.cancel = function () {
|
|
49
|
-
if (timeoutId !== null) {
|
|
50
|
-
clearTimeout(timeoutId);
|
|
51
|
-
timeoutId = null;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
55
|
-
return debounced;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function noop() { }
|
|
59
|
-
|
|
60
|
-
function once(func) {
|
|
61
|
-
let called = false;
|
|
62
|
-
let cache;
|
|
63
|
-
return function () {
|
|
64
|
-
if (called) {
|
|
65
|
-
return cache;
|
|
66
|
-
}
|
|
67
|
-
const result = func();
|
|
68
|
-
called = true;
|
|
69
|
-
cache = result;
|
|
70
|
-
return result;
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function throttle(func, throttleMs) {
|
|
75
|
-
let lastCallTime;
|
|
76
|
-
const throttledFunction = function (...args) {
|
|
77
|
-
const now = Date.now();
|
|
78
|
-
if (lastCallTime == null || now - lastCallTime >= throttleMs) {
|
|
79
|
-
lastCallTime = now;
|
|
80
|
-
func(...args);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
return throttledFunction;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function negate(func) {
|
|
87
|
-
return ((...args) => !func(...args));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function memoize(fn, options = {}) {
|
|
91
|
-
const { cache = new Map(), getCacheKey } = options;
|
|
92
|
-
const memoizedFn = function (arg) {
|
|
93
|
-
const key = getCacheKey ? getCacheKey(arg) : arg;
|
|
94
|
-
if (cache.has(key)) {
|
|
95
|
-
return cache.get(key);
|
|
96
|
-
}
|
|
97
|
-
const result = fn.call(this, arg);
|
|
98
|
-
cache.set(key, result);
|
|
99
|
-
return result;
|
|
100
|
-
};
|
|
101
|
-
memoizedFn.cache = cache;
|
|
102
|
-
return memoizedFn;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function ary(func, n) {
|
|
106
|
-
return function (...args) {
|
|
107
|
-
return func.apply(this, args.slice(0, n));
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function unary(func) {
|
|
112
|
-
return ary(func, 1);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function partial(func, ...partialArgs) {
|
|
116
|
-
return function (...providedArgs) {
|
|
117
|
-
const args = [];
|
|
118
|
-
let startIndex = 0;
|
|
119
|
-
for (let i = 0; i < partialArgs.length; i++) {
|
|
120
|
-
const arg = partialArgs[i];
|
|
121
|
-
if (arg === partial.placeholder) {
|
|
122
|
-
args.push(providedArgs[startIndex++]);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
args.push(arg);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
for (let i = startIndex; i < providedArgs.length; i++) {
|
|
129
|
-
args.push(providedArgs[i]);
|
|
130
|
-
}
|
|
131
|
-
return func.apply(this, args);
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
const partialPlaceholder = Symbol('partial.placeholder');
|
|
135
|
-
partial.placeholder = partialPlaceholder;
|
|
136
|
-
|
|
137
|
-
function partialRight(func, ...partialArgs) {
|
|
138
|
-
return function (...providedArgs) {
|
|
139
|
-
const placeholderLength = partialArgs.filter(arg => arg === partialRightPlaceholder).length;
|
|
140
|
-
const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
|
|
141
|
-
const args = [];
|
|
142
|
-
let providedIndex = 0;
|
|
143
|
-
for (let i = 0; i < rangeLength; i++) {
|
|
144
|
-
args.push(providedArgs[providedIndex++]);
|
|
145
|
-
}
|
|
146
|
-
for (let i = 0; i < partialArgs.length; i++) {
|
|
147
|
-
const arg = partialArgs[i];
|
|
148
|
-
if (arg === partialRight.placeholder) {
|
|
149
|
-
args.push(providedArgs[providedIndex++]);
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
args.push(arg);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return func.apply(this, args);
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
const partialRightPlaceholder = Symbol('partialRight.placeholder');
|
|
159
|
-
partialRight.placeholder = partialRightPlaceholder;
|
|
160
|
-
|
|
161
|
-
function rest(func, startIndex = func.length - 1) {
|
|
162
|
-
return function (...args) {
|
|
163
|
-
const rest = args.slice(startIndex);
|
|
164
|
-
const params = args.slice(0, startIndex);
|
|
165
|
-
while (params.length < startIndex) {
|
|
166
|
-
params.push(undefined);
|
|
167
|
-
}
|
|
168
|
-
return func.apply(this, [...params, rest]);
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
exports.after = after;
|
|
173
|
-
exports.ary = ary;
|
|
174
|
-
exports.before = before;
|
|
175
|
-
exports.debounce = debounce;
|
|
176
|
-
exports.memoize = memoize;
|
|
177
|
-
exports.negate = negate;
|
|
178
|
-
exports.noop = noop;
|
|
179
|
-
exports.once = once;
|
|
180
|
-
exports.partial = partial;
|
|
181
|
-
exports.partialRight = partialRight;
|
|
182
|
-
exports.rest = rest;
|
|
183
|
-
exports.throttle = throttle;
|
|
184
|
-
exports.unary = unary;
|
|
5
|
+
const rest = require('../_chunk/rest-CXt9w3.js');
|
|
6
|
+
|
|
7
|
+
function spread(func) {
|
|
8
|
+
return function (argsArr) {
|
|
9
|
+
return func.apply(this, argsArr);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.after = rest.after;
|
|
14
|
+
exports.ary = rest.ary;
|
|
15
|
+
exports.before = rest.before;
|
|
16
|
+
exports.debounce = rest.debounce;
|
|
17
|
+
exports.memoize = rest.memoize;
|
|
18
|
+
exports.negate = rest.negate;
|
|
19
|
+
exports.noop = rest.noop;
|
|
20
|
+
exports.once = rest.once;
|
|
21
|
+
exports.partial = rest.partial;
|
|
22
|
+
exports.partialRight = rest.partialRight;
|
|
23
|
+
exports.rest = rest.rest;
|
|
24
|
+
exports.throttle = rest.throttle;
|
|
25
|
+
exports.unary = rest.unary;
|
|
26
|
+
exports.spread = spread;
|
package/dist/function/index.mjs
CHANGED