es-toolkit 1.18.0 → 1.19.0
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 +11 -0
- package/dist/_chunk/{rest-CXt9w3.js → curry-BmwJrK.js} +21 -0
- package/dist/_chunk/{isWeakSet-CogETi.js → isWeakSet-E_VMwB.js} +9 -3
- package/dist/_chunk/range-BXlMmn.js +68 -0
- package/dist/_chunk/{toMerged-DN1PPP.js → toMerged-Bzkqyz.js} +28 -46
- package/dist/_chunk/{zipWith-CYaH1Y.js → zipWith-B-5AMf.js} +1 -1
- package/dist/array/forEachRight.d.mts +23 -0
- package/dist/array/forEachRight.d.ts +23 -0
- package/dist/array/groupBy.mjs +1 -1
- package/dist/array/index.js +1 -1
- package/dist/array/orderBy.d.mts +1 -1
- package/dist/array/orderBy.d.ts +1 -1
- package/dist/array/sortBy.d.mts +1 -1
- package/dist/array/sortBy.d.ts +1 -1
- package/dist/array/unzip.d.mts +1 -1
- package/dist/array/unzip.d.ts +1 -1
- package/dist/array/zipObject.d.mts +1 -1
- package/dist/array/zipObject.d.ts +1 -1
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/decimalAdjust.mjs +19 -0
- package/dist/compat/_internal/isDeepKey.mjs +1 -3
- package/dist/compat/_internal/normalizeForCase.mjs +5 -4
- package/dist/compat/_internal/toKey.mjs +2 -7
- package/dist/compat/array/flatten.d.mts +1 -1
- package/dist/compat/array/flatten.d.ts +1 -1
- package/dist/compat/array/flattenDepth.d.mts +1 -1
- package/dist/compat/array/flattenDepth.d.ts +1 -1
- package/dist/compat/array/indexOf.d.mts +1 -1
- package/dist/compat/array/indexOf.d.ts +1 -1
- package/dist/compat/array/orderBy.d.mts +1 -1
- package/dist/compat/array/orderBy.d.ts +1 -1
- package/dist/compat/array/orderBy.mjs +1 -1
- package/dist/compat/array/size.d.mts +1 -1
- package/dist/compat/array/size.d.ts +1 -1
- package/dist/compat/array/sortBy.d.mts +1 -1
- package/dist/compat/array/sortBy.d.ts +1 -1
- package/dist/compat/array/zipObjectDeep.d.mts +1 -1
- package/dist/compat/array/zipObjectDeep.d.ts +1 -1
- package/dist/compat/index.d.mts +20 -7
- package/dist/compat/index.d.ts +20 -7
- package/dist/compat/index.js +459 -137
- package/dist/compat/index.mjs +20 -7
- package/dist/compat/math/ceil.d.mts +15 -0
- package/dist/compat/math/ceil.d.ts +15 -0
- package/dist/compat/math/ceil.mjs +7 -0
- package/dist/compat/math/floor.d.mts +15 -0
- package/dist/compat/math/floor.d.ts +15 -0
- package/dist/compat/math/floor.mjs +7 -0
- package/dist/compat/math/round.d.mts +15 -0
- package/dist/compat/math/round.d.ts +15 -0
- package/dist/compat/math/round.mjs +7 -0
- package/dist/compat/object/fromPairs.d.mts +2 -2
- package/dist/compat/object/fromPairs.d.ts +2 -2
- package/dist/compat/object/get.d.mts +12 -12
- package/dist/compat/object/get.d.ts +12 -12
- package/dist/compat/object/get.mjs +54 -17
- package/dist/compat/object/has.mjs +1 -1
- package/dist/compat/object/mergeWith.mjs +14 -2
- package/dist/compat/object/omit.d.mts +34 -0
- package/dist/compat/object/omit.d.ts +34 -0
- package/dist/compat/object/omit.mjs +33 -0
- package/dist/compat/object/pick.d.mts +47 -0
- package/dist/compat/object/pick.d.ts +47 -0
- package/dist/compat/object/pick.mjs +38 -0
- package/dist/compat/object/set.mjs +1 -1
- package/dist/compat/object/unset.d.mts +20 -0
- package/dist/compat/object/unset.d.ts +20 -0
- package/dist/compat/object/unset.mjs +68 -0
- package/dist/compat/predicate/isInteger.d.mts +17 -0
- package/dist/compat/predicate/isInteger.d.ts +17 -0
- package/dist/compat/predicate/isInteger.mjs +5 -0
- package/dist/compat/predicate/isMatch.mjs +44 -4
- package/dist/compat/predicate/isNil.mjs +5 -0
- package/dist/compat/predicate/isObject.d.mts +4 -4
- package/dist/compat/predicate/isObject.d.ts +4 -4
- package/dist/compat/predicate/isSafeInteger.d.mts +20 -0
- package/dist/compat/predicate/isSafeInteger.d.ts +20 -0
- package/dist/compat/predicate/isSafeInteger.mjs +5 -0
- package/dist/compat/predicate/matchesProperty.mjs +12 -1
- package/dist/compat/string/kebabCase.d.mts +17 -0
- package/dist/compat/string/kebabCase.d.ts +17 -0
- package/dist/compat/string/kebabCase.mjs +9 -0
- package/dist/compat/string/lowerCase.d.mts +17 -0
- package/dist/compat/string/lowerCase.d.ts +17 -0
- package/dist/compat/string/lowerCase.mjs +8 -0
- package/dist/compat/string/snakeCase.d.mts +17 -0
- package/dist/compat/string/snakeCase.d.ts +17 -0
- package/dist/compat/string/snakeCase.mjs +8 -0
- package/dist/compat/string/startCase.d.mts +16 -0
- package/dist/compat/string/startCase.d.ts +16 -0
- package/dist/compat/string/startCase.mjs +8 -0
- package/dist/compat/string/trim.d.mts +16 -0
- package/dist/compat/string/trim.d.ts +16 -0
- package/dist/compat/string/trim.mjs +25 -0
- package/dist/compat/string/trimEnd.d.mts +17 -0
- package/dist/compat/string/trimEnd.d.ts +17 -0
- package/dist/compat/string/trimEnd.mjs +25 -0
- package/dist/compat/string/trimStart.d.mts +17 -0
- package/dist/compat/string/trimStart.d.ts +17 -0
- package/dist/compat/string/trimStart.mjs +25 -0
- package/dist/compat/util/toPath.d.mts +20 -0
- package/dist/compat/util/toPath.d.ts +20 -0
- package/dist/compat/util/toPath.mjs +37 -0
- package/dist/compat/util/toString.d.mts +19 -0
- package/dist/compat/util/toString.d.ts +19 -0
- package/dist/compat/util/toString.mjs +15 -0
- package/dist/function/curry.d.mts +127 -0
- package/dist/function/curry.d.ts +127 -0
- package/dist/function/curry.mjs +21 -0
- package/dist/function/index.d.mts +1 -0
- package/dist/function/index.d.ts +1 -0
- package/dist/function/index.js +15 -14
- package/dist/function/index.mjs +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +40 -33
- package/dist/index.mjs +6 -0
- package/dist/math/index.js +8 -66
- package/dist/object/clone.mjs +28 -25
- package/dist/object/index.js +19 -3
- package/dist/object/pick.d.mts +1 -1
- package/dist/object/pick.d.ts +1 -1
- package/dist/predicate/index.d.mts +1 -0
- package/dist/predicate/index.d.ts +1 -0
- package/dist/predicate/index.js +6 -5
- package/dist/predicate/index.mjs +1 -0
- package/dist/predicate/isDate.d.mts +16 -0
- package/dist/predicate/isDate.d.ts +16 -0
- package/dist/predicate/isDate.mjs +5 -0
- package/dist/predicate/isNotNil.mjs +1 -1
- package/dist/string/capitalize.d.mts +1 -0
- package/dist/string/capitalize.d.ts +1 -0
- package/dist/string/index.d.mts +4 -0
- package/dist/string/index.d.ts +4 -0
- package/dist/string/index.js +65 -0
- package/dist/string/index.mjs +4 -0
- package/dist/string/startCase.d.mts +1 -1
- package/dist/string/startCase.d.ts +1 -1
- package/dist/string/trim.d.mts +15 -0
- package/dist/string/trim.d.ts +15 -0
- package/dist/string/trim.mjs +11 -0
- package/dist/string/trimEnd.d.mts +16 -0
- package/dist/string/trimEnd.d.ts +16 -0
- package/dist/string/trimEnd.mjs +22 -0
- package/dist/string/trimStart.d.mts +16 -0
- package/dist/string/trimStart.d.ts +16 -0
- package/dist/string/trimStart.mjs +22 -0
- package/dist/string/upperCase.d.mts +17 -0
- package/dist/string/upperCase.d.ts +17 -0
- package/dist/string/upperCase.mjs +15 -0
- package/package.json +1 -1
- package/dist/compat/_internal/isArrayMatch.mjs +0 -24
- package/dist/compat/_internal/isMapMatch.mjs +0 -18
- package/dist/compat/_internal/isSetMatch.mjs +0 -13
- package/dist/compat/_internal/toPath.mjs +0 -40
- package/dist/_chunk/{isTypedArray-Dsrnb1.js → isPlainObject-BIekvL.js} +8 -8
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the first character of each word in a string to uppercase and the remaining characters to lowercase.
|
|
3
|
+
*
|
|
4
|
+
* Start case is the naming convention in which each word is written with an initial capital letter.
|
|
5
|
+
* @param {string} str - The string to convert.
|
|
6
|
+
* @returns {string} The converted string.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const result1 = startCase('hello world'); // result will be 'Hello World'
|
|
10
|
+
* const result2 = startCase('HELLO WORLD'); // result will be 'HELLO WORLD'
|
|
11
|
+
* const result3 = startCase('hello-world'); // result will be 'Hello World'
|
|
12
|
+
* const result4 = startCase('hello_world'); // result will be 'Hello World'
|
|
13
|
+
*/
|
|
14
|
+
declare function startCase(str: string | object): string;
|
|
15
|
+
|
|
16
|
+
export { startCase };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the first character of each word in a string to uppercase and the remaining characters to lowercase.
|
|
3
|
+
*
|
|
4
|
+
* Start case is the naming convention in which each word is written with an initial capital letter.
|
|
5
|
+
* @param {string} str - The string to convert.
|
|
6
|
+
* @returns {string} The converted string.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const result1 = startCase('hello world'); // result will be 'Hello World'
|
|
10
|
+
* const result2 = startCase('HELLO WORLD'); // result will be 'HELLO WORLD'
|
|
11
|
+
* const result3 = startCase('hello-world'); // result will be 'Hello World'
|
|
12
|
+
* const result4 = startCase('hello_world'); // result will be 'Hello World'
|
|
13
|
+
*/
|
|
14
|
+
declare function startCase(str: string | object): string;
|
|
15
|
+
|
|
16
|
+
export { startCase };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes leading and trailing whitespace or specified characters from a string.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str - The string from which leading and trailing characters will be trimmed.
|
|
5
|
+
* @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
|
|
6
|
+
* @param guard
|
|
7
|
+
* @returns {string} - The resulting string after the specified leading and trailing characters have been removed.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* trim(" hello "); // "hello"
|
|
11
|
+
* trim("--hello--", "-"); // "hello"
|
|
12
|
+
* trim("##hello##", ["#", "o"]); // "hell"
|
|
13
|
+
*/
|
|
14
|
+
declare function trim(str: string, chars?: string | string[], guard?: unknown): string;
|
|
15
|
+
|
|
16
|
+
export { trim };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes leading and trailing whitespace or specified characters from a string.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str - The string from which leading and trailing characters will be trimmed.
|
|
5
|
+
* @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
|
|
6
|
+
* @param guard
|
|
7
|
+
* @returns {string} - The resulting string after the specified leading and trailing characters have been removed.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* trim(" hello "); // "hello"
|
|
11
|
+
* trim("--hello--", "-"); // "hello"
|
|
12
|
+
* trim("##hello##", ["#", "o"]); // "hell"
|
|
13
|
+
*/
|
|
14
|
+
declare function trim(str: string, chars?: string | string[], guard?: unknown): string;
|
|
15
|
+
|
|
16
|
+
export { trim };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { trim as trim$1 } from '../../string/trim.mjs';
|
|
2
|
+
|
|
3
|
+
function trim(str, chars, guard) {
|
|
4
|
+
if (str == null) {
|
|
5
|
+
return '';
|
|
6
|
+
}
|
|
7
|
+
if (guard != null || chars == null) {
|
|
8
|
+
return str.toString().trim();
|
|
9
|
+
}
|
|
10
|
+
switch (typeof chars) {
|
|
11
|
+
case 'string': {
|
|
12
|
+
return trim$1(str, chars.toString().split(''));
|
|
13
|
+
}
|
|
14
|
+
case 'object': {
|
|
15
|
+
if (Array.isArray(chars)) {
|
|
16
|
+
return trim$1(str, chars.map(x => x.toString()));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return trim$1(str, chars.toString().split(''));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { trim };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes trailing whitespace or specified characters from a string.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str - The string from which trailing characters will be trimmed.
|
|
5
|
+
* @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
|
|
6
|
+
* @param guard
|
|
7
|
+
* @returns {string} - The resulting string after the specified trailing character has been removed.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const trimmedStr1 = trimEnd('hello---', '-') // returns 'hello'
|
|
11
|
+
* const trimmedStr2 = trimEnd('123000', '0') // returns '123'
|
|
12
|
+
* const trimmedStr3 = trimEnd('abcabcabc', 'c') // returns 'abcabcab'
|
|
13
|
+
* const trimmedStr4 = trimEnd('trimmedxxx', 'x') // returns 'trimmed'
|
|
14
|
+
*/
|
|
15
|
+
declare function trimEnd(str: string, chars?: string | string[], guard?: unknown): string;
|
|
16
|
+
|
|
17
|
+
export { trimEnd };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes trailing whitespace or specified characters from a string.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str - The string from which trailing characters will be trimmed.
|
|
5
|
+
* @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
|
|
6
|
+
* @param guard
|
|
7
|
+
* @returns {string} - The resulting string after the specified trailing character has been removed.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const trimmedStr1 = trimEnd('hello---', '-') // returns 'hello'
|
|
11
|
+
* const trimmedStr2 = trimEnd('123000', '0') // returns '123'
|
|
12
|
+
* const trimmedStr3 = trimEnd('abcabcabc', 'c') // returns 'abcabcab'
|
|
13
|
+
* const trimmedStr4 = trimEnd('trimmedxxx', 'x') // returns 'trimmed'
|
|
14
|
+
*/
|
|
15
|
+
declare function trimEnd(str: string, chars?: string | string[], guard?: unknown): string;
|
|
16
|
+
|
|
17
|
+
export { trimEnd };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { trimEnd as trimEnd$1 } from '../../string/trimEnd.mjs';
|
|
2
|
+
|
|
3
|
+
function trimEnd(str, chars, guard) {
|
|
4
|
+
if (str == null) {
|
|
5
|
+
return '';
|
|
6
|
+
}
|
|
7
|
+
if (guard != null || chars == null) {
|
|
8
|
+
return str.toString().trimEnd();
|
|
9
|
+
}
|
|
10
|
+
switch (typeof chars) {
|
|
11
|
+
case 'string': {
|
|
12
|
+
return trimEnd$1(str, chars.toString().split(''));
|
|
13
|
+
}
|
|
14
|
+
case 'object': {
|
|
15
|
+
if (Array.isArray(chars)) {
|
|
16
|
+
return trimEnd$1(str, chars.map(x => x.toString()));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return trimEnd$1(str, chars.toString().split(''));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { trimEnd };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes leading whitespace or specified characters from a string.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str - The string from which leading characters will be trimmed.
|
|
5
|
+
* @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
|
|
6
|
+
* @param guard
|
|
7
|
+
* @returns {string} - The resulting string after the specified leading character has been removed.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const trimmedStr1 = ltrim('---hello', '-') // returns 'hello'
|
|
11
|
+
* const trimmedStr2 = ltrim('000123', '0') // returns '123'
|
|
12
|
+
* const trimmedStr3 = ltrim('abcabcabc', 'a') // returns 'bcabcabc'
|
|
13
|
+
* const trimmedStr4 = ltrim('xxxtrimmed', 'x') // returns 'trimmed'
|
|
14
|
+
*/
|
|
15
|
+
declare function trimStart(str: string, chars?: string | string[], guard?: unknown): string;
|
|
16
|
+
|
|
17
|
+
export { trimStart };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes leading whitespace or specified characters from a string.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str - The string from which leading characters will be trimmed.
|
|
5
|
+
* @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
|
|
6
|
+
* @param guard
|
|
7
|
+
* @returns {string} - The resulting string after the specified leading character has been removed.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const trimmedStr1 = ltrim('---hello', '-') // returns 'hello'
|
|
11
|
+
* const trimmedStr2 = ltrim('000123', '0') // returns '123'
|
|
12
|
+
* const trimmedStr3 = ltrim('abcabcabc', 'a') // returns 'bcabcabc'
|
|
13
|
+
* const trimmedStr4 = ltrim('xxxtrimmed', 'x') // returns 'trimmed'
|
|
14
|
+
*/
|
|
15
|
+
declare function trimStart(str: string, chars?: string | string[], guard?: unknown): string;
|
|
16
|
+
|
|
17
|
+
export { trimStart };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { trimStart as trimStart$1 } from '../../string/trimStart.mjs';
|
|
2
|
+
|
|
3
|
+
function trimStart(str, chars, guard) {
|
|
4
|
+
if (str == null) {
|
|
5
|
+
return '';
|
|
6
|
+
}
|
|
7
|
+
if (guard != null || chars == null) {
|
|
8
|
+
return str.toString().trimStart();
|
|
9
|
+
}
|
|
10
|
+
switch (typeof chars) {
|
|
11
|
+
case 'string': {
|
|
12
|
+
return trimStart$1(str, chars.toString().split(''));
|
|
13
|
+
}
|
|
14
|
+
case 'object': {
|
|
15
|
+
if (Array.isArray(chars)) {
|
|
16
|
+
return trimStart$1(str, chars.map(x => x.toString()));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return trimStart$1(str, chars.toString().split(''));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { trimStart };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a deep key string into an array of path segments.
|
|
3
|
+
*
|
|
4
|
+
* This function takes a string representing a deep key (e.g., 'a.b.c' or 'a[b][c]') and breaks it down into an array of strings, each representing a segment of the path.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} deepKey - The deep key string to convert.
|
|
7
|
+
* @returns {string[]} An array of strings, each representing a segment of the path.
|
|
8
|
+
*
|
|
9
|
+
* Examples:
|
|
10
|
+
*
|
|
11
|
+
* toPath('a.b.c') // Returns ['a', 'b', 'c']
|
|
12
|
+
* toPath('a[b][c]') // Returns ['a', 'b', 'c']
|
|
13
|
+
* toPath('.a.b.c') // Returns ['', 'a', 'b', 'c']
|
|
14
|
+
* toPath('a["b.c"].d') // Returns ['a', 'b.c', 'd']
|
|
15
|
+
* toPath('') // Returns []
|
|
16
|
+
* toPath('.a[b].c.d[e]["f.g"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']
|
|
17
|
+
*/
|
|
18
|
+
declare function toPath(deepKey: string): string[];
|
|
19
|
+
|
|
20
|
+
export { toPath };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a deep key string into an array of path segments.
|
|
3
|
+
*
|
|
4
|
+
* This function takes a string representing a deep key (e.g., 'a.b.c' or 'a[b][c]') and breaks it down into an array of strings, each representing a segment of the path.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} deepKey - The deep key string to convert.
|
|
7
|
+
* @returns {string[]} An array of strings, each representing a segment of the path.
|
|
8
|
+
*
|
|
9
|
+
* Examples:
|
|
10
|
+
*
|
|
11
|
+
* toPath('a.b.c') // Returns ['a', 'b', 'c']
|
|
12
|
+
* toPath('a[b][c]') // Returns ['a', 'b', 'c']
|
|
13
|
+
* toPath('.a.b.c') // Returns ['', 'a', 'b', 'c']
|
|
14
|
+
* toPath('a["b.c"].d') // Returns ['a', 'b.c', 'd']
|
|
15
|
+
* toPath('') // Returns []
|
|
16
|
+
* toPath('.a[b].c.d[e]["f.g"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']
|
|
17
|
+
*/
|
|
18
|
+
declare function toPath(deepKey: string): string[];
|
|
19
|
+
|
|
20
|
+
export { toPath };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const DOTS_KEY = /^[\w.]+$/g;
|
|
2
|
+
const ESCAPE_REGEXP = /\\(\\)?/g;
|
|
3
|
+
const PROPERTY_REGEXP = RegExp('[^.[\\]]+' +
|
|
4
|
+
'|' +
|
|
5
|
+
'\\[(?:' +
|
|
6
|
+
'([^"\'][^[]*)' +
|
|
7
|
+
'|' +
|
|
8
|
+
'(["\'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2' +
|
|
9
|
+
')\\]' +
|
|
10
|
+
'|' +
|
|
11
|
+
'(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))', 'g');
|
|
12
|
+
function toPath(deepKey) {
|
|
13
|
+
if (DOTS_KEY.test(deepKey)) {
|
|
14
|
+
return deepKey.split('.');
|
|
15
|
+
}
|
|
16
|
+
const result = [];
|
|
17
|
+
if (deepKey[0] === '.') {
|
|
18
|
+
result.push('');
|
|
19
|
+
}
|
|
20
|
+
const matches = deepKey.matchAll(PROPERTY_REGEXP);
|
|
21
|
+
for (const match of matches) {
|
|
22
|
+
let key = match[0];
|
|
23
|
+
const expr = match[1];
|
|
24
|
+
const quote = match[2];
|
|
25
|
+
const substr = match[3];
|
|
26
|
+
if (quote) {
|
|
27
|
+
key = substr.replace(ESCAPE_REGEXP, '$1');
|
|
28
|
+
}
|
|
29
|
+
else if (expr) {
|
|
30
|
+
key = expr;
|
|
31
|
+
}
|
|
32
|
+
result.push(key);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { toPath };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts `value` to a string.
|
|
3
|
+
*
|
|
4
|
+
* An empty string is returned for `null` and `undefined` values.
|
|
5
|
+
* The sign of `-0` is preserved.
|
|
6
|
+
*
|
|
7
|
+
* @param {unknown} value - The value to convert.
|
|
8
|
+
* @returns {string} Returns the converted string.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* toString(null) // returns ''
|
|
12
|
+
* toString(undefined) // returns ''
|
|
13
|
+
* toString(-0) // returns '-0'
|
|
14
|
+
* toString([1, 2, -0]) // returns '1,2,-0'
|
|
15
|
+
* toString([Symbol('a'), Symbol('b')]) // returns 'Symbol(a),Symbol(b)'
|
|
16
|
+
*/
|
|
17
|
+
declare function toString(value?: unknown): string;
|
|
18
|
+
|
|
19
|
+
export { toString };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts `value` to a string.
|
|
3
|
+
*
|
|
4
|
+
* An empty string is returned for `null` and `undefined` values.
|
|
5
|
+
* The sign of `-0` is preserved.
|
|
6
|
+
*
|
|
7
|
+
* @param {unknown} value - The value to convert.
|
|
8
|
+
* @returns {string} Returns the converted string.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* toString(null) // returns ''
|
|
12
|
+
* toString(undefined) // returns ''
|
|
13
|
+
* toString(-0) // returns '-0'
|
|
14
|
+
* toString([1, 2, -0]) // returns '1,2,-0'
|
|
15
|
+
* toString([Symbol('a'), Symbol('b')]) // returns 'Symbol(a),Symbol(b)'
|
|
16
|
+
*/
|
|
17
|
+
declare function toString(value?: unknown): string;
|
|
18
|
+
|
|
19
|
+
export { toString };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function toString(value) {
|
|
2
|
+
if (value == null) {
|
|
3
|
+
return '';
|
|
4
|
+
}
|
|
5
|
+
if (Array.isArray(value)) {
|
|
6
|
+
return value.map(toString).join(',');
|
|
7
|
+
}
|
|
8
|
+
const result = String(value);
|
|
9
|
+
if (result === '0' && Object.is(Number(value), -0)) {
|
|
10
|
+
return '-0';
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { toString };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
3
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
4
|
+
*
|
|
5
|
+
* @param {() => R} func - The function to curry.
|
|
6
|
+
* @returns {() => R} A curried function.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* function noArgFunc() {
|
|
10
|
+
* return 42;
|
|
11
|
+
* }
|
|
12
|
+
* const curriedNoArgFunc = curry(noArgFunc);
|
|
13
|
+
* console.log(curriedNoArgFunc()); // 42
|
|
14
|
+
*/
|
|
15
|
+
declare function curry<R>(func: () => R): () => R;
|
|
16
|
+
/**
|
|
17
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
18
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
19
|
+
*
|
|
20
|
+
* @param {(p: P) => R} func - The function to curry.
|
|
21
|
+
* @returns {(p: P) => R} A curried function.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* function oneArgFunc(a: number) {
|
|
25
|
+
* return a * 2;
|
|
26
|
+
* }
|
|
27
|
+
* const curriedOneArgFunc = curry(oneArgFunc);
|
|
28
|
+
* console.log(curriedOneArgFunc(5)); // 10
|
|
29
|
+
*/
|
|
30
|
+
declare function curry<P, R>(func: (p: P) => R): (p: P) => R;
|
|
31
|
+
/**
|
|
32
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
33
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
34
|
+
*
|
|
35
|
+
* @param {(p1: P1, p2: P2) => R} func - The function to curry.
|
|
36
|
+
* @returns {(p1: P1) => (p2: P2) => R} A curried function.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* function twoArgFunc(a: number, b: number) {
|
|
40
|
+
* return a + b;
|
|
41
|
+
* }
|
|
42
|
+
* const curriedTwoArgFunc = curry(twoArgFunc);
|
|
43
|
+
* const add5 = curriedTwoArgFunc(5);
|
|
44
|
+
* console.log(add5(10)); // 15
|
|
45
|
+
*/
|
|
46
|
+
declare function curry<P1, P2, R>(func: (p1: P1, p2: P2) => R): (p1: P1) => (p2: P2) => R;
|
|
47
|
+
/**
|
|
48
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
49
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
50
|
+
*
|
|
51
|
+
* @param {(p1: P1, p2: P2, p3: P3, p4: P4) => R} func - The function to curry.
|
|
52
|
+
* @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R} A curried function.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* function fourArgFunc(a: number, b: number, c: number, d: number) {
|
|
56
|
+
* return a + b + c + d;
|
|
57
|
+
* }
|
|
58
|
+
* const curriedFourArgFunc = curry(fourArgFunc);
|
|
59
|
+
* const add1 = curriedFourArgFunc(1);
|
|
60
|
+
* const add2 = add1(2);
|
|
61
|
+
* const add3 = add2(3);
|
|
62
|
+
* console.log(add3(4)); // 10
|
|
63
|
+
*/
|
|
64
|
+
declare function curry<P1, P2, P3, R>(func: (p1: P1, p2: P2, p3: P3) => R): (p1: P1) => (p2: P2) => (p3: P3) => R;
|
|
65
|
+
/**
|
|
66
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
67
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
68
|
+
*
|
|
69
|
+
* @param {(p1: P1, p2: P2, p3: P3, p4: P4) => R} func - The function to curry.
|
|
70
|
+
* @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R} A curried function.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* function fourArgFunc(a: number, b: number, c: number, d: number) {
|
|
74
|
+
* return a + b + c + d;
|
|
75
|
+
* }
|
|
76
|
+
* const curriedFourArgFunc = curry(fourArgFunc);
|
|
77
|
+
* const add1 = curriedFourArgFunc(1);
|
|
78
|
+
* const add2 = add1(2);
|
|
79
|
+
* const add3 = add2(3);
|
|
80
|
+
* console.log(add3(4)); // 10
|
|
81
|
+
*/
|
|
82
|
+
declare function curry<P1, P2, P3, P4, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R;
|
|
83
|
+
/**
|
|
84
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
85
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
86
|
+
*
|
|
87
|
+
* @param {(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R} func - The function to curry.
|
|
88
|
+
* @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => (p5: P5) => R} A curried function.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* function fiveArgFunc(a: number, b: number, c: number, d: number, e: number) {
|
|
92
|
+
* return a + b + c + d + e;
|
|
93
|
+
* }
|
|
94
|
+
* const curriedFiveArgFunc = curry(fiveArgFunc);
|
|
95
|
+
* const add1 = curriedFiveArgFunc(1);
|
|
96
|
+
* const add2 = add1(2);
|
|
97
|
+
* const add3 = add2(3);
|
|
98
|
+
* const add4 = add3(4);
|
|
99
|
+
* console.log(add4(5)); // 15
|
|
100
|
+
*/
|
|
101
|
+
declare function curry<P1, P2, P3, P4, P5, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => (p5: P5) => R;
|
|
102
|
+
/**
|
|
103
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
104
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
105
|
+
*
|
|
106
|
+
* @param {(...args: any[]) => any} func - The function to curry.
|
|
107
|
+
* @returns {(...args: any[]) => any} A curried function that can be called with a single argument at a time.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* function sum(a: number, b: number, c: number) {
|
|
111
|
+
* return a + b + c;
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* const curriedSum = curry(sum);
|
|
115
|
+
*
|
|
116
|
+
* // The parameter `a` should be given the value `10`.
|
|
117
|
+
* const sum10 = curriedSum(10);
|
|
118
|
+
*
|
|
119
|
+
* // The parameter `b` should be given the value `15`.
|
|
120
|
+
* const sum25 = sum10(15);
|
|
121
|
+
*
|
|
122
|
+
* // The parameter `c` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
|
|
123
|
+
* const result = sum25(5);
|
|
124
|
+
*/
|
|
125
|
+
declare function curry(func: (...args: any[]) => any): (...args: any[]) => any;
|
|
126
|
+
|
|
127
|
+
export { curry };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
3
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
4
|
+
*
|
|
5
|
+
* @param {() => R} func - The function to curry.
|
|
6
|
+
* @returns {() => R} A curried function.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* function noArgFunc() {
|
|
10
|
+
* return 42;
|
|
11
|
+
* }
|
|
12
|
+
* const curriedNoArgFunc = curry(noArgFunc);
|
|
13
|
+
* console.log(curriedNoArgFunc()); // 42
|
|
14
|
+
*/
|
|
15
|
+
declare function curry<R>(func: () => R): () => R;
|
|
16
|
+
/**
|
|
17
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
18
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
19
|
+
*
|
|
20
|
+
* @param {(p: P) => R} func - The function to curry.
|
|
21
|
+
* @returns {(p: P) => R} A curried function.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* function oneArgFunc(a: number) {
|
|
25
|
+
* return a * 2;
|
|
26
|
+
* }
|
|
27
|
+
* const curriedOneArgFunc = curry(oneArgFunc);
|
|
28
|
+
* console.log(curriedOneArgFunc(5)); // 10
|
|
29
|
+
*/
|
|
30
|
+
declare function curry<P, R>(func: (p: P) => R): (p: P) => R;
|
|
31
|
+
/**
|
|
32
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
33
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
34
|
+
*
|
|
35
|
+
* @param {(p1: P1, p2: P2) => R} func - The function to curry.
|
|
36
|
+
* @returns {(p1: P1) => (p2: P2) => R} A curried function.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* function twoArgFunc(a: number, b: number) {
|
|
40
|
+
* return a + b;
|
|
41
|
+
* }
|
|
42
|
+
* const curriedTwoArgFunc = curry(twoArgFunc);
|
|
43
|
+
* const add5 = curriedTwoArgFunc(5);
|
|
44
|
+
* console.log(add5(10)); // 15
|
|
45
|
+
*/
|
|
46
|
+
declare function curry<P1, P2, R>(func: (p1: P1, p2: P2) => R): (p1: P1) => (p2: P2) => R;
|
|
47
|
+
/**
|
|
48
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
49
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
50
|
+
*
|
|
51
|
+
* @param {(p1: P1, p2: P2, p3: P3, p4: P4) => R} func - The function to curry.
|
|
52
|
+
* @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R} A curried function.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* function fourArgFunc(a: number, b: number, c: number, d: number) {
|
|
56
|
+
* return a + b + c + d;
|
|
57
|
+
* }
|
|
58
|
+
* const curriedFourArgFunc = curry(fourArgFunc);
|
|
59
|
+
* const add1 = curriedFourArgFunc(1);
|
|
60
|
+
* const add2 = add1(2);
|
|
61
|
+
* const add3 = add2(3);
|
|
62
|
+
* console.log(add3(4)); // 10
|
|
63
|
+
*/
|
|
64
|
+
declare function curry<P1, P2, P3, R>(func: (p1: P1, p2: P2, p3: P3) => R): (p1: P1) => (p2: P2) => (p3: P3) => R;
|
|
65
|
+
/**
|
|
66
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
67
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
68
|
+
*
|
|
69
|
+
* @param {(p1: P1, p2: P2, p3: P3, p4: P4) => R} func - The function to curry.
|
|
70
|
+
* @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R} A curried function.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* function fourArgFunc(a: number, b: number, c: number, d: number) {
|
|
74
|
+
* return a + b + c + d;
|
|
75
|
+
* }
|
|
76
|
+
* const curriedFourArgFunc = curry(fourArgFunc);
|
|
77
|
+
* const add1 = curriedFourArgFunc(1);
|
|
78
|
+
* const add2 = add1(2);
|
|
79
|
+
* const add3 = add2(3);
|
|
80
|
+
* console.log(add3(4)); // 10
|
|
81
|
+
*/
|
|
82
|
+
declare function curry<P1, P2, P3, P4, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R;
|
|
83
|
+
/**
|
|
84
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
85
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
86
|
+
*
|
|
87
|
+
* @param {(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R} func - The function to curry.
|
|
88
|
+
* @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => (p5: P5) => R} A curried function.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* function fiveArgFunc(a: number, b: number, c: number, d: number, e: number) {
|
|
92
|
+
* return a + b + c + d + e;
|
|
93
|
+
* }
|
|
94
|
+
* const curriedFiveArgFunc = curry(fiveArgFunc);
|
|
95
|
+
* const add1 = curriedFiveArgFunc(1);
|
|
96
|
+
* const add2 = add1(2);
|
|
97
|
+
* const add3 = add2(3);
|
|
98
|
+
* const add4 = add3(4);
|
|
99
|
+
* console.log(add4(5)); // 15
|
|
100
|
+
*/
|
|
101
|
+
declare function curry<P1, P2, P3, P4, P5, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => (p5: P5) => R;
|
|
102
|
+
/**
|
|
103
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
104
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
105
|
+
*
|
|
106
|
+
* @param {(...args: any[]) => any} func - The function to curry.
|
|
107
|
+
* @returns {(...args: any[]) => any} A curried function that can be called with a single argument at a time.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* function sum(a: number, b: number, c: number) {
|
|
111
|
+
* return a + b + c;
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* const curriedSum = curry(sum);
|
|
115
|
+
*
|
|
116
|
+
* // The parameter `a` should be given the value `10`.
|
|
117
|
+
* const sum10 = curriedSum(10);
|
|
118
|
+
*
|
|
119
|
+
* // The parameter `b` should be given the value `15`.
|
|
120
|
+
* const sum25 = sum10(15);
|
|
121
|
+
*
|
|
122
|
+
* // The parameter `c` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
|
|
123
|
+
* const result = sum25(5);
|
|
124
|
+
*/
|
|
125
|
+
declare function curry(func: (...args: any[]) => any): (...args: any[]) => any;
|
|
126
|
+
|
|
127
|
+
export { curry };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function curry(func) {
|
|
2
|
+
if (func.length === 0 || func.length === 1) {
|
|
3
|
+
return func;
|
|
4
|
+
}
|
|
5
|
+
return function (arg) {
|
|
6
|
+
return makeCurry(func, func.length, [arg]);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function makeCurry(origin, argsLength, args) {
|
|
10
|
+
if (args.length === argsLength) {
|
|
11
|
+
return origin(...args);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
const next = function (arg) {
|
|
15
|
+
return makeCurry(origin, argsLength, [...args, arg]);
|
|
16
|
+
};
|
|
17
|
+
return next;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { curry };
|