es-toolkit 1.50.0-dev.2057 → 1.50.0-dev.2059
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/dist/browser.global.js +3 -3
- package/dist/compat/array/drop.d.mts +1 -1
- package/dist/compat/array/drop.d.ts +1 -1
- package/dist/compat/array/pull.js +1 -1
- package/dist/compat/array/pull.mjs +1 -1
- package/dist/compat/array/remove.js +8 -4
- package/dist/compat/array/remove.mjs +8 -4
- package/dist/compat/array/unzipWith.js +1 -1
- package/dist/compat/array/unzipWith.mjs +1 -1
- package/dist/compat/function/curry.d.mts +1 -1
- package/dist/compat/function/curry.d.ts +1 -1
- package/dist/compat/function/flowRight.d.mts +1 -1
- package/dist/compat/function/flowRight.d.ts +1 -1
- package/dist/compat/function/partial.d.mts +1 -1
- package/dist/compat/function/partial.d.ts +1 -1
- package/dist/compat/function/rest.d.mts +1 -1
- package/dist/compat/function/rest.d.ts +1 -1
- package/dist/compat/function/rest.js +1 -1
- package/dist/compat/function/rest.mjs +1 -1
- package/dist/compat/object/cloneDeep.d.mts +5 -5
- package/dist/compat/object/cloneDeep.d.ts +5 -5
- package/dist/compat/object/cloneDeep.js +5 -5
- package/dist/compat/object/cloneDeep.mjs +5 -5
- package/dist/compat/object/cloneDeepWith.js +3 -1
- package/dist/compat/object/cloneDeepWith.mjs +3 -1
- package/dist/compat/object/cloneWith.d.mts +1 -1
- package/dist/compat/object/cloneWith.d.ts +1 -1
- package/dist/compat/object/cloneWith.js +1 -1
- package/dist/compat/object/cloneWith.mjs +1 -1
- package/dist/compat/object/transform.js +1 -1
- package/dist/compat/object/transform.mjs +1 -1
- package/dist/compat/string/words.js +17 -13
- package/dist/compat/string/words.mjs +17 -13
- package/dist/compat/util/toArray.d.mts +5 -5
- package/dist/compat/util/toArray.d.ts +5 -5
- package/dist/compat/util/toArray.js +4 -4
- package/dist/compat/util/toArray.mjs +4 -4
- package/dist/function/memoize.d.mts +3 -2
- package/dist/function/memoize.d.ts +3 -2
- package/dist/function/memoize.js +3 -2
- package/dist/function/memoize.mjs +3 -2
- package/dist/function/partial.d.mts +2 -2
- package/dist/function/partial.d.ts +2 -2
- package/dist/function/partialRight.d.mts +5 -5
- package/dist/function/partialRight.d.ts +5 -5
- package/dist/function/rest.d.mts +1 -1
- package/dist/function/rest.d.ts +1 -1
- package/dist/function/rest.js +1 -1
- package/dist/function/rest.mjs +1 -1
- package/dist/object/cloneDeepWith.d.mts +3 -1
- package/dist/object/cloneDeepWith.d.ts +3 -1
- package/dist/object/cloneDeepWith.js +3 -1
- package/dist/object/cloneDeepWith.mjs +3 -1
- package/dist/object/flattenObject.d.mts +16 -1
- package/dist/object/flattenObject.d.ts +16 -1
- package/dist/object/flattenObject.js +15 -6
- package/dist/object/flattenObject.mjs +15 -6
- package/package.json +5 -2
|
@@ -24,7 +24,7 @@ const require_rest = require("../../function/rest.js");
|
|
|
24
24
|
*
|
|
25
25
|
* // Using start index 1
|
|
26
26
|
* const transformedFnWithStart = rest(fn, 1);
|
|
27
|
-
* console.log(transformedFnWithStart(1, 2, 3, 4)); // [1, [2, 3, 4]]
|
|
27
|
+
* console.log(transformedFnWithStart(1, 2, 3, 4)); // [1, [2, 3, 4], undefined]
|
|
28
28
|
*
|
|
29
29
|
* // With fewer arguments than the start index
|
|
30
30
|
* console.log(transformedFn(1)); // [1, undefined, []]
|
|
@@ -24,7 +24,7 @@ import { rest as rest$1 } from "../../function/rest.mjs";
|
|
|
24
24
|
*
|
|
25
25
|
* // Using start index 1
|
|
26
26
|
* const transformedFnWithStart = rest(fn, 1);
|
|
27
|
-
* console.log(transformedFnWithStart(1, 2, 3, 4)); // [1, [2, 3, 4]]
|
|
27
|
+
* console.log(transformedFnWithStart(1, 2, 3, 4)); // [1, [2, 3, 4], undefined]
|
|
28
28
|
*
|
|
29
29
|
* // With fewer arguments than the start index
|
|
30
30
|
* console.log(transformedFn(1)); // [1, undefined, []]
|
|
@@ -16,30 +16,30 @@
|
|
|
16
16
|
* @example
|
|
17
17
|
* // Clone an array
|
|
18
18
|
* const arr = [1, 2, 3];
|
|
19
|
-
* const clonedArr =
|
|
19
|
+
* const clonedArr = cloneDeep(arr);
|
|
20
20
|
* console.log(clonedArr); // [1, 2, 3]
|
|
21
21
|
* console.log(clonedArr === arr); // false
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
24
|
* // Clone an array with nested objects
|
|
25
25
|
* const arr = [1, { a: 1 }, [1, 2, 3]];
|
|
26
|
-
* const clonedArr =
|
|
26
|
+
* const clonedArr = cloneDeep(arr);
|
|
27
27
|
* arr[1].a = 2;
|
|
28
|
-
* console.log(arr); // [
|
|
28
|
+
* console.log(arr); // [1, { a: 2 }, [1, 2, 3]]
|
|
29
29
|
* console.log(clonedArr); // [1, { a: 1 }, [1, 2, 3]]
|
|
30
30
|
* console.log(clonedArr === arr); // false
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
33
|
* // Clone an object
|
|
34
34
|
* const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
|
|
35
|
-
* const clonedObj =
|
|
35
|
+
* const clonedObj = cloneDeep(obj);
|
|
36
36
|
* console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
|
|
37
37
|
* console.log(clonedObj === obj); // false
|
|
38
38
|
*
|
|
39
39
|
* @example
|
|
40
40
|
* // Clone an object with nested objects
|
|
41
41
|
* const obj = { a: 1, b: { c: 1 } };
|
|
42
|
-
* const clonedObj =
|
|
42
|
+
* const clonedObj = cloneDeep(obj);
|
|
43
43
|
* obj.b.c = 2;
|
|
44
44
|
* console.log(obj); // { a: 1, b: { c: 2 } }
|
|
45
45
|
* console.log(clonedObj); // { a: 1, b: { c: 1 } }
|
|
@@ -16,30 +16,30 @@
|
|
|
16
16
|
* @example
|
|
17
17
|
* // Clone an array
|
|
18
18
|
* const arr = [1, 2, 3];
|
|
19
|
-
* const clonedArr =
|
|
19
|
+
* const clonedArr = cloneDeep(arr);
|
|
20
20
|
* console.log(clonedArr); // [1, 2, 3]
|
|
21
21
|
* console.log(clonedArr === arr); // false
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
24
|
* // Clone an array with nested objects
|
|
25
25
|
* const arr = [1, { a: 1 }, [1, 2, 3]];
|
|
26
|
-
* const clonedArr =
|
|
26
|
+
* const clonedArr = cloneDeep(arr);
|
|
27
27
|
* arr[1].a = 2;
|
|
28
|
-
* console.log(arr); // [
|
|
28
|
+
* console.log(arr); // [1, { a: 2 }, [1, 2, 3]]
|
|
29
29
|
* console.log(clonedArr); // [1, { a: 1 }, [1, 2, 3]]
|
|
30
30
|
* console.log(clonedArr === arr); // false
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
33
|
* // Clone an object
|
|
34
34
|
* const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
|
|
35
|
-
* const clonedObj =
|
|
35
|
+
* const clonedObj = cloneDeep(obj);
|
|
36
36
|
* console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
|
|
37
37
|
* console.log(clonedObj === obj); // false
|
|
38
38
|
*
|
|
39
39
|
* @example
|
|
40
40
|
* // Clone an object with nested objects
|
|
41
41
|
* const obj = { a: 1, b: { c: 1 } };
|
|
42
|
-
* const clonedObj =
|
|
42
|
+
* const clonedObj = cloneDeep(obj);
|
|
43
43
|
* obj.b.c = 2;
|
|
44
44
|
* console.log(obj); // { a: 1, b: { c: 2 } }
|
|
45
45
|
* console.log(clonedObj); // { a: 1, b: { c: 1 } }
|
|
@@ -17,30 +17,30 @@ const require_cloneDeepWith = require("./cloneDeepWith.js");
|
|
|
17
17
|
* @example
|
|
18
18
|
* // Clone an array
|
|
19
19
|
* const arr = [1, 2, 3];
|
|
20
|
-
* const clonedArr =
|
|
20
|
+
* const clonedArr = cloneDeep(arr);
|
|
21
21
|
* console.log(clonedArr); // [1, 2, 3]
|
|
22
22
|
* console.log(clonedArr === arr); // false
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
25
|
* // Clone an array with nested objects
|
|
26
26
|
* const arr = [1, { a: 1 }, [1, 2, 3]];
|
|
27
|
-
* const clonedArr =
|
|
27
|
+
* const clonedArr = cloneDeep(arr);
|
|
28
28
|
* arr[1].a = 2;
|
|
29
|
-
* console.log(arr); // [
|
|
29
|
+
* console.log(arr); // [1, { a: 2 }, [1, 2, 3]]
|
|
30
30
|
* console.log(clonedArr); // [1, { a: 1 }, [1, 2, 3]]
|
|
31
31
|
* console.log(clonedArr === arr); // false
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
34
34
|
* // Clone an object
|
|
35
35
|
* const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
|
|
36
|
-
* const clonedObj =
|
|
36
|
+
* const clonedObj = cloneDeep(obj);
|
|
37
37
|
* console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
|
|
38
38
|
* console.log(clonedObj === obj); // false
|
|
39
39
|
*
|
|
40
40
|
* @example
|
|
41
41
|
* // Clone an object with nested objects
|
|
42
42
|
* const obj = { a: 1, b: { c: 1 } };
|
|
43
|
-
* const clonedObj =
|
|
43
|
+
* const clonedObj = cloneDeep(obj);
|
|
44
44
|
* obj.b.c = 2;
|
|
45
45
|
* console.log(obj); // { a: 1, b: { c: 2 } }
|
|
46
46
|
* console.log(clonedObj); // { a: 1, b: { c: 1 } }
|
|
@@ -17,30 +17,30 @@ import { cloneDeepWith } from "./cloneDeepWith.mjs";
|
|
|
17
17
|
* @example
|
|
18
18
|
* // Clone an array
|
|
19
19
|
* const arr = [1, 2, 3];
|
|
20
|
-
* const clonedArr =
|
|
20
|
+
* const clonedArr = cloneDeep(arr);
|
|
21
21
|
* console.log(clonedArr); // [1, 2, 3]
|
|
22
22
|
* console.log(clonedArr === arr); // false
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
25
|
* // Clone an array with nested objects
|
|
26
26
|
* const arr = [1, { a: 1 }, [1, 2, 3]];
|
|
27
|
-
* const clonedArr =
|
|
27
|
+
* const clonedArr = cloneDeep(arr);
|
|
28
28
|
* arr[1].a = 2;
|
|
29
|
-
* console.log(arr); // [
|
|
29
|
+
* console.log(arr); // [1, { a: 2 }, [1, 2, 3]]
|
|
30
30
|
* console.log(clonedArr); // [1, { a: 1 }, [1, 2, 3]]
|
|
31
31
|
* console.log(clonedArr === arr); // false
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
34
34
|
* // Clone an object
|
|
35
35
|
* const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
|
|
36
|
-
* const clonedObj =
|
|
36
|
+
* const clonedObj = cloneDeep(obj);
|
|
37
37
|
* console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
|
|
38
38
|
* console.log(clonedObj === obj); // false
|
|
39
39
|
*
|
|
40
40
|
* @example
|
|
41
41
|
* // Clone an object with nested objects
|
|
42
42
|
* const obj = { a: 1, b: { c: 1 } };
|
|
43
|
-
* const clonedObj =
|
|
43
|
+
* const clonedObj = cloneDeep(obj);
|
|
44
44
|
* obj.b.c = 2;
|
|
45
45
|
* console.log(obj); // { a: 1, b: { c: 2 } }
|
|
46
46
|
* console.log(clonedObj); // { a: 1, b: { c: 1 } }
|
|
@@ -32,7 +32,9 @@ const require_cloneDeepWith = require("../../object/cloneDeepWith.js");
|
|
|
32
32
|
* // Clone an array with a customizer
|
|
33
33
|
* const arr = [1, 2, 3];
|
|
34
34
|
* const clonedArr = cloneDeepWith(arr, (value) => {
|
|
35
|
-
*
|
|
35
|
+
* if (typeof value === 'number') {
|
|
36
|
+
* return value + 1; // Increment each number
|
|
37
|
+
* }
|
|
36
38
|
* });
|
|
37
39
|
* console.log(clonedArr); // [2, 3, 4]
|
|
38
40
|
* console.log(clonedArr === arr); // false
|
|
@@ -32,7 +32,9 @@ import { cloneDeepWith as cloneDeepWith$1, copyProperties } from "../../object/c
|
|
|
32
32
|
* // Clone an array with a customizer
|
|
33
33
|
* const arr = [1, 2, 3];
|
|
34
34
|
* const clonedArr = cloneDeepWith(arr, (value) => {
|
|
35
|
-
*
|
|
35
|
+
* if (typeof value === 'number') {
|
|
36
|
+
* return value + 1; // Increment each number
|
|
37
|
+
* }
|
|
36
38
|
* });
|
|
37
39
|
* console.log(clonedArr); // [2, 3, 4]
|
|
38
40
|
* console.log(clonedArr === arr); // false
|
|
@@ -35,7 +35,7 @@ declare function cloneWith<T, R extends object | string | number | boolean | nul
|
|
|
35
35
|
* return value * 2;
|
|
36
36
|
* }
|
|
37
37
|
* });
|
|
38
|
-
* // => { a:
|
|
38
|
+
* // => { a: 1, b: 2 } (customizer returns undefined for objects, so the default shallow clone is used)
|
|
39
39
|
*/
|
|
40
40
|
declare function cloneWith<T, R>(value: T, customizer: CloneWithCustomizer<T, R | undefined>): R | T;
|
|
41
41
|
/**
|
|
@@ -35,7 +35,7 @@ declare function cloneWith<T, R extends object | string | number | boolean | nul
|
|
|
35
35
|
* return value * 2;
|
|
36
36
|
* }
|
|
37
37
|
* });
|
|
38
|
-
* // => { a:
|
|
38
|
+
* // => { a: 1, b: 2 } (customizer returns undefined for objects, so the default shallow clone is used)
|
|
39
39
|
*/
|
|
40
40
|
declare function cloneWith<T, R>(value: T, customizer: CloneWithCustomizer<T, R | undefined>): R | T;
|
|
41
41
|
/**
|
|
@@ -43,7 +43,7 @@ const require_clone = require("./clone.js");
|
|
|
43
43
|
* }
|
|
44
44
|
* // Returning undefined uses the default cloning
|
|
45
45
|
* });
|
|
46
|
-
* console.log(clonedObj); // { a:
|
|
46
|
+
* console.log(clonedObj); // { a: 1, b: 2 } (customizer returns undefined for objects, so the default shallow clone is used)
|
|
47
47
|
*/
|
|
48
48
|
function cloneWith(value, customizer) {
|
|
49
49
|
if (!customizer) return require_clone.clone(value);
|
|
@@ -43,7 +43,7 @@ import { clone } from "./clone.mjs";
|
|
|
43
43
|
* }
|
|
44
44
|
* // Returning undefined uses the default cloning
|
|
45
45
|
* });
|
|
46
|
-
* console.log(clonedObj); // { a:
|
|
46
|
+
* console.log(clonedObj); // { a: 1, b: 2 } (customizer returns undefined for objects, so the default shallow clone is used)
|
|
47
47
|
*/
|
|
48
48
|
function cloneWith(value, customizer) {
|
|
49
49
|
if (!customizer) return clone(value);
|
|
@@ -23,7 +23,7 @@ The traversal is interrupted when the `iteratee` function returns `false`.
|
|
|
23
23
|
* @example
|
|
24
24
|
* // Transform an array
|
|
25
25
|
* const array = [2, 3, 4];
|
|
26
|
-
* transform(array, (acc, value) => { acc += value; return value % 2 === 0; }, 0) // => 5
|
|
26
|
+
* transform(array, (acc, value) => { acc.sum += value; return value % 2 === 0; }, { sum: 0 }) // => { sum: 5 }
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* // Transform an object
|
|
@@ -23,7 +23,7 @@ The traversal is interrupted when the `iteratee` function returns `false`.
|
|
|
23
23
|
* @example
|
|
24
24
|
* // Transform an array
|
|
25
25
|
* const array = [2, 3, 4];
|
|
26
|
-
* transform(array, (acc, value) => { acc += value; return value % 2 === 0; }, 0) // => 5
|
|
26
|
+
* transform(array, (acc, value) => { acc.sum += value; return value % 2 === 0; }, { sum: 0 }) // => { sum: 5 }
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* // Transform an object
|
|
@@ -10,17 +10,21 @@ const rUnicodeOptContrUpper = "(?:['’](?:D|LL|M|RE|S|T|VE))?";
|
|
|
10
10
|
const rUnicodeBreak = `[\\p{Z}\\p{P}${rNonCharLatin}]`;
|
|
11
11
|
const rUnicodeMiscUpper = `(?:${rUnicodeUpper}|${rMisc})`;
|
|
12
12
|
const rUnicodeMiscLower = `(?:${rUnicodeLower}|${rMisc})`;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
let rUnicodeWord;
|
|
14
|
+
function getUnicodeWordPattern() {
|
|
15
|
+
if (rUnicodeWord == null) rUnicodeWord = RegExp([
|
|
16
|
+
`${rUnicodeUpper}?${rUnicodeLower}+${rUnicodeOptContrLower}(?=${rUnicodeBreak}|${rUnicodeUpper}|$)`,
|
|
17
|
+
`${rUnicodeMiscUpper}+${rUnicodeOptContrUpper}(?=${rUnicodeBreak}|${rUnicodeUpper}${rUnicodeMiscLower}|$)`,
|
|
18
|
+
`${rUnicodeUpper}?${rUnicodeMiscLower}+${rUnicodeOptContrLower}`,
|
|
19
|
+
`${rUnicodeUpper}+${rUnicodeOptContrUpper}`,
|
|
20
|
+
`${rNumber}*(?:1ST|2ND|3RD|(?![123])${rNumber}TH)(?=\\b|[a-z_])`,
|
|
21
|
+
`${rNumber}*(?:1st|2nd|3rd|(?![123])${rNumber}th)(?=\\b|[A-Z_])`,
|
|
22
|
+
`${rNumber}+`,
|
|
23
|
+
"\\p{Emoji_Presentation}",
|
|
24
|
+
"\\p{Extended_Pictographic}"
|
|
25
|
+
].join("|"), "gu");
|
|
26
|
+
return rUnicodeWord;
|
|
27
|
+
}
|
|
24
28
|
/**
|
|
25
29
|
* Splits `string` into an array of its words.
|
|
26
30
|
*
|
|
@@ -32,9 +36,9 @@ const rUnicodeWord = RegExp([
|
|
|
32
36
|
* const wordsArray1 = words('fred, barney, & pebbles');
|
|
33
37
|
* // => ['fred', 'barney', 'pebbles']
|
|
34
38
|
*/
|
|
35
|
-
function words(str, pattern
|
|
39
|
+
function words(str, pattern, guard) {
|
|
36
40
|
const input = require_toString.toString(str);
|
|
37
|
-
if (guard) pattern =
|
|
41
|
+
if (guard || pattern === void 0) pattern = getUnicodeWordPattern();
|
|
38
42
|
if (typeof pattern === "number") pattern = pattern.toString();
|
|
39
43
|
return Array.from(input.match(pattern) ?? []).filter((x) => x !== "");
|
|
40
44
|
}
|
|
@@ -10,17 +10,21 @@ const rUnicodeOptContrUpper = "(?:['’](?:D|LL|M|RE|S|T|VE))?";
|
|
|
10
10
|
const rUnicodeBreak = `[\\p{Z}\\p{P}${rNonCharLatin}]`;
|
|
11
11
|
const rUnicodeMiscUpper = `(?:${rUnicodeUpper}|${rMisc})`;
|
|
12
12
|
const rUnicodeMiscLower = `(?:${rUnicodeLower}|${rMisc})`;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
let rUnicodeWord;
|
|
14
|
+
function getUnicodeWordPattern() {
|
|
15
|
+
if (rUnicodeWord == null) rUnicodeWord = RegExp([
|
|
16
|
+
`${rUnicodeUpper}?${rUnicodeLower}+${rUnicodeOptContrLower}(?=${rUnicodeBreak}|${rUnicodeUpper}|$)`,
|
|
17
|
+
`${rUnicodeMiscUpper}+${rUnicodeOptContrUpper}(?=${rUnicodeBreak}|${rUnicodeUpper}${rUnicodeMiscLower}|$)`,
|
|
18
|
+
`${rUnicodeUpper}?${rUnicodeMiscLower}+${rUnicodeOptContrLower}`,
|
|
19
|
+
`${rUnicodeUpper}+${rUnicodeOptContrUpper}`,
|
|
20
|
+
`${rNumber}*(?:1ST|2ND|3RD|(?![123])${rNumber}TH)(?=\\b|[a-z_])`,
|
|
21
|
+
`${rNumber}*(?:1st|2nd|3rd|(?![123])${rNumber}th)(?=\\b|[A-Z_])`,
|
|
22
|
+
`${rNumber}+`,
|
|
23
|
+
"\\p{Emoji_Presentation}",
|
|
24
|
+
"\\p{Extended_Pictographic}"
|
|
25
|
+
].join("|"), "gu");
|
|
26
|
+
return rUnicodeWord;
|
|
27
|
+
}
|
|
24
28
|
/**
|
|
25
29
|
* Splits `string` into an array of its words.
|
|
26
30
|
*
|
|
@@ -32,9 +36,9 @@ const rUnicodeWord = RegExp([
|
|
|
32
36
|
* const wordsArray1 = words('fred, barney, & pebbles');
|
|
33
37
|
* // => ['fred', 'barney', 'pebbles']
|
|
34
38
|
*/
|
|
35
|
-
function words(str, pattern
|
|
39
|
+
function words(str, pattern, guard) {
|
|
36
40
|
const input = toString(str);
|
|
37
|
-
if (guard) pattern =
|
|
41
|
+
if (guard || pattern === void 0) pattern = getUnicodeWordPattern();
|
|
38
42
|
if (typeof pattern === "number") pattern = pattern.toString();
|
|
39
43
|
return Array.from(input.match(pattern) ?? []).filter((x) => x !== "");
|
|
40
44
|
}
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* @returns Returns an array of the record's values or an empty array if null/undefined.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* toArray({ 'a': 1, 'b': 2 }) // =>
|
|
11
|
-
* toArray(null) // =>
|
|
10
|
+
* toArray({ 'a': 1, 'b': 2 }) // => [1, 2]
|
|
11
|
+
* toArray(null) // => []
|
|
12
12
|
*/
|
|
13
13
|
declare function toArray<T>(value: Record<string, T> | Record<number, T> | null | undefined): T[];
|
|
14
14
|
/**
|
|
@@ -19,8 +19,8 @@ declare function toArray<T>(value: Record<string, T> | Record<number, T> | null
|
|
|
19
19
|
* @returns Returns an array of the value's values.
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
|
-
* toArray({ x: 10, y: 20 }) // =>
|
|
23
|
-
* toArray('abc') // =>
|
|
22
|
+
* toArray({ x: 10, y: 20 }) // => [10, 20]
|
|
23
|
+
* toArray('abc') // => ['a', 'b', 'c']
|
|
24
24
|
*/
|
|
25
25
|
declare function toArray<T>(value: T): Array<T[keyof T]>;
|
|
26
26
|
/**
|
|
@@ -29,7 +29,7 @@ declare function toArray<T>(value: T): Array<T[keyof T]>;
|
|
|
29
29
|
* @returns Returns an empty array.
|
|
30
30
|
*
|
|
31
31
|
* @example
|
|
32
|
-
* toArray() // =>
|
|
32
|
+
* toArray() // => []
|
|
33
33
|
*/
|
|
34
34
|
declare function toArray(): any[];
|
|
35
35
|
//#endregion
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* @returns Returns an array of the record's values or an empty array if null/undefined.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* toArray({ 'a': 1, 'b': 2 }) // =>
|
|
11
|
-
* toArray(null) // =>
|
|
10
|
+
* toArray({ 'a': 1, 'b': 2 }) // => [1, 2]
|
|
11
|
+
* toArray(null) // => []
|
|
12
12
|
*/
|
|
13
13
|
declare function toArray<T>(value: Record<string, T> | Record<number, T> | null | undefined): T[];
|
|
14
14
|
/**
|
|
@@ -19,8 +19,8 @@ declare function toArray<T>(value: Record<string, T> | Record<number, T> | null
|
|
|
19
19
|
* @returns Returns an array of the value's values.
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
|
-
* toArray({ x: 10, y: 20 }) // =>
|
|
23
|
-
* toArray('abc') // =>
|
|
22
|
+
* toArray({ x: 10, y: 20 }) // => [10, 20]
|
|
23
|
+
* toArray('abc') // => ['a', 'b', 'c']
|
|
24
24
|
*/
|
|
25
25
|
declare function toArray<T>(value: T): Array<T[keyof T]>;
|
|
26
26
|
/**
|
|
@@ -29,7 +29,7 @@ declare function toArray<T>(value: T): Array<T[keyof T]>;
|
|
|
29
29
|
* @returns Returns an empty array.
|
|
30
30
|
*
|
|
31
31
|
* @example
|
|
32
|
-
* toArray() // =>
|
|
32
|
+
* toArray() // => []
|
|
33
33
|
*/
|
|
34
34
|
declare function toArray(): any[];
|
|
35
35
|
//#endregion
|
|
@@ -10,10 +10,10 @@ const require_isSet = require("../predicate/isSet.js");
|
|
|
10
10
|
* @returns Returns the converted array.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
|
-
* toArray({ 'a': 1, 'b': 2 }) // =>
|
|
14
|
-
* toArray('abc') // =>
|
|
15
|
-
* toArray(1) // =>
|
|
16
|
-
* toArray(null) // =>
|
|
13
|
+
* toArray({ 'a': 1, 'b': 2 }) // => [1,2]
|
|
14
|
+
* toArray('abc') // => ['a', 'b', 'c']
|
|
15
|
+
* toArray(1) // => []
|
|
16
|
+
* toArray(null) // => []
|
|
17
17
|
*/
|
|
18
18
|
function toArray(value) {
|
|
19
19
|
if (value == null) return [];
|
|
@@ -10,10 +10,10 @@ import { isSet } from "../predicate/isSet.mjs";
|
|
|
10
10
|
* @returns Returns the converted array.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
|
-
* toArray({ 'a': 1, 'b': 2 }) // =>
|
|
14
|
-
* toArray('abc') // =>
|
|
15
|
-
* toArray(1) // =>
|
|
16
|
-
* toArray(null) // =>
|
|
13
|
+
* toArray({ 'a': 1, 'b': 2 }) // => [1,2]
|
|
14
|
+
* toArray('abc') // => ['a', 'b', 'c']
|
|
15
|
+
* toArray(1) // => []
|
|
16
|
+
* toArray(null) // => []
|
|
17
17
|
*/
|
|
18
18
|
function toArray(value) {
|
|
19
19
|
if (value == null) return [];
|
|
@@ -67,8 +67,9 @@
|
|
|
67
67
|
* }
|
|
68
68
|
* const customCache = new CustomCache<string, number>();
|
|
69
69
|
* const memoizedSumWithCustomCache = memoize(sum, { cache: customCache });
|
|
70
|
-
*
|
|
71
|
-
* console.log(memoizedSumWithCustomCache(
|
|
70
|
+
* const arr = [1, 2];
|
|
71
|
+
* console.log(memoizedSumWithCustomCache(arr)); // 3
|
|
72
|
+
* console.log(memoizedSumWithCustomCache(arr)); // 3 (cached result)
|
|
72
73
|
* console.log(memoizedSumWithCustomCache.cache.size); // 1
|
|
73
74
|
*/
|
|
74
75
|
declare function memoize<F extends (...args: any) => any>(fn: F, options?: {
|
|
@@ -67,8 +67,9 @@
|
|
|
67
67
|
* }
|
|
68
68
|
* const customCache = new CustomCache<string, number>();
|
|
69
69
|
* const memoizedSumWithCustomCache = memoize(sum, { cache: customCache });
|
|
70
|
-
*
|
|
71
|
-
* console.log(memoizedSumWithCustomCache(
|
|
70
|
+
* const arr = [1, 2];
|
|
71
|
+
* console.log(memoizedSumWithCustomCache(arr)); // 3
|
|
72
|
+
* console.log(memoizedSumWithCustomCache(arr)); // 3 (cached result)
|
|
72
73
|
* console.log(memoizedSumWithCustomCache.cache.size); // 1
|
|
73
74
|
*/
|
|
74
75
|
declare function memoize<F extends (...args: any) => any>(fn: F, options?: {
|
package/dist/function/memoize.js
CHANGED
|
@@ -67,8 +67,9 @@
|
|
|
67
67
|
* }
|
|
68
68
|
* const customCache = new CustomCache<string, number>();
|
|
69
69
|
* const memoizedSumWithCustomCache = memoize(sum, { cache: customCache });
|
|
70
|
-
*
|
|
71
|
-
* console.log(memoizedSumWithCustomCache(
|
|
70
|
+
* const arr = [1, 2];
|
|
71
|
+
* console.log(memoizedSumWithCustomCache(arr)); // 3
|
|
72
|
+
* console.log(memoizedSumWithCustomCache(arr)); // 3 (cached result)
|
|
72
73
|
* console.log(memoizedSumWithCustomCache.cache.size); // 1
|
|
73
74
|
*/
|
|
74
75
|
function memoize(fn, options = {}) {
|
|
@@ -67,8 +67,9 @@
|
|
|
67
67
|
* }
|
|
68
68
|
* const customCache = new CustomCache<string, number>();
|
|
69
69
|
* const memoizedSumWithCustomCache = memoize(sum, { cache: customCache });
|
|
70
|
-
*
|
|
71
|
-
* console.log(memoizedSumWithCustomCache(
|
|
70
|
+
* const arr = [1, 2];
|
|
71
|
+
* console.log(memoizedSumWithCustomCache(arr)); // 3
|
|
72
|
+
* console.log(memoizedSumWithCustomCache(arr)); // 3 (cached result)
|
|
72
73
|
* console.log(memoizedSumWithCustomCache.cache.size); // 1
|
|
73
74
|
*/
|
|
74
75
|
function memoize(fn, options = {}) {
|
|
@@ -330,7 +330,7 @@ declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3,
|
|
|
330
330
|
* @returns A new function that takes the first and third arguments and returns the result of the original function.
|
|
331
331
|
*
|
|
332
332
|
* @example
|
|
333
|
-
* const multiply = (x: number, y: number, z: number
|
|
333
|
+
* const multiply = (x: number, y: number, z: number) => x * y * z;
|
|
334
334
|
* const multiplyWithPlaceholder = partial(multiply, partial.placeholder, 2, 3);
|
|
335
335
|
* console.log(multiplyWithPlaceholder(4)); // => 24
|
|
336
336
|
*/
|
|
@@ -540,7 +540,7 @@ declare function partial<TS extends any[], T1, R>(func: (arg1: T1, ...args: TS)
|
|
|
540
540
|
*
|
|
541
541
|
* @example
|
|
542
542
|
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`;
|
|
543
|
-
* const greetWithHello = partial(greet, 'Hello', '!');
|
|
543
|
+
* const greetWithHello = partial(greet, 'Hello', partial.placeholder, '!');
|
|
544
544
|
* console.log(greetWithHello('John')); // => 'Hello, John!'
|
|
545
545
|
*/
|
|
546
546
|
declare function partial<TS extends any[], T1, T2, R>(func: (arg1: T1, arg2: T2, ...args: TS) => R, t1: T1, arg2: T2): (...args: TS) => R;
|
|
@@ -330,7 +330,7 @@ declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3,
|
|
|
330
330
|
* @returns A new function that takes the first and third arguments and returns the result of the original function.
|
|
331
331
|
*
|
|
332
332
|
* @example
|
|
333
|
-
* const multiply = (x: number, y: number, z: number
|
|
333
|
+
* const multiply = (x: number, y: number, z: number) => x * y * z;
|
|
334
334
|
* const multiplyWithPlaceholder = partial(multiply, partial.placeholder, 2, 3);
|
|
335
335
|
* console.log(multiplyWithPlaceholder(4)); // => 24
|
|
336
336
|
*/
|
|
@@ -540,7 +540,7 @@ declare function partial<TS extends any[], T1, R>(func: (arg1: T1, ...args: TS)
|
|
|
540
540
|
*
|
|
541
541
|
* @example
|
|
542
542
|
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`;
|
|
543
|
-
* const greetWithHello = partial(greet, 'Hello', '!');
|
|
543
|
+
* const greetWithHello = partial(greet, 'Hello', partial.placeholder, '!');
|
|
544
544
|
* console.log(greetWithHello('John')); // => 'Hello, John!'
|
|
545
545
|
*/
|
|
546
546
|
declare function partial<TS extends any[], T1, T2, R>(func: (arg1: T1, arg2: T2, ...args: TS) => R, t1: T1, arg2: T2): (...args: TS) => R;
|
|
@@ -203,7 +203,7 @@ declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3
|
|
|
203
203
|
* @returns Returns the new partially applied function.
|
|
204
204
|
* @example
|
|
205
205
|
* const createUser = (name: string, age: number, country: string) => `${name}, ${age} years old from ${country}`;
|
|
206
|
-
* const createUserFromUSA = partialRight(createUser, 'USA'
|
|
206
|
+
* const createUserFromUSA = partialRight(createUser, 'USA');
|
|
207
207
|
* console.log(createUserFromUSA('John', 30)); // => 'John, 30 years old from USA'
|
|
208
208
|
*/
|
|
209
209
|
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg2: T2, arg3: Placeholder): (arg1: T1, arg3: T3) => R;
|
|
@@ -225,7 +225,7 @@ declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3
|
|
|
225
225
|
* @returns Returns the new partially applied function.
|
|
226
226
|
* @example
|
|
227
227
|
* const logMessage = (level: string, message: string, timestamp: string) => `[${level}] ${message} at ${timestamp}`;
|
|
228
|
-
* const logError = partialRight(logMessage, 'ERROR', '2023-10-01');
|
|
228
|
+
* const logError = partialRight(logMessage, 'ERROR', partialRight.placeholder, '2023-10-01');
|
|
229
229
|
* console.log(logError('Something went wrong!')); // => '[ERROR] Something went wrong! at 2023-10-01'
|
|
230
230
|
*/
|
|
231
231
|
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: T2, arg3: Placeholder): (arg3: T3) => R;
|
|
@@ -288,7 +288,7 @@ declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3
|
|
|
288
288
|
* @returns Returns the new partially applied function.
|
|
289
289
|
* @example
|
|
290
290
|
* const createProfile = (name: string, age: number, country: string) => `${name}, ${age} from ${country}`;
|
|
291
|
-
* const createProfileFromCanada = partialRight(createProfile, '
|
|
291
|
+
* const createProfileFromCanada = partialRight(createProfile, 'John', partialRight.placeholder, 'Canada');
|
|
292
292
|
* console.log(createProfileFromCanada(30)); // => 'John, 30 from Canada'
|
|
293
293
|
*/
|
|
294
294
|
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg2: T2, arg3: T3): (arg1: T1) => R;
|
|
@@ -615,9 +615,9 @@ declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3
|
|
|
615
615
|
* @param args The arguments to be partially applied.
|
|
616
616
|
* @returns Returns the new partially applied function.
|
|
617
617
|
* @example
|
|
618
|
-
* const log = (...messages: string[]) =>
|
|
618
|
+
* const log = (...messages: string[]) => messages.join(' ');
|
|
619
619
|
* const logError = partialRight(log, 'Error:');
|
|
620
|
-
* logError('Something went wrong!'); // => '
|
|
620
|
+
* logError('Something went wrong!'); // => 'Something went wrong! Error:'
|
|
621
621
|
*/
|
|
622
622
|
declare function partialRight(func: (...args: any[]) => any, ...args: any[]): (...args: any[]) => any;
|
|
623
623
|
declare namespace partialRight {
|
|
@@ -203,7 +203,7 @@ declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3
|
|
|
203
203
|
* @returns Returns the new partially applied function.
|
|
204
204
|
* @example
|
|
205
205
|
* const createUser = (name: string, age: number, country: string) => `${name}, ${age} years old from ${country}`;
|
|
206
|
-
* const createUserFromUSA = partialRight(createUser, 'USA'
|
|
206
|
+
* const createUserFromUSA = partialRight(createUser, 'USA');
|
|
207
207
|
* console.log(createUserFromUSA('John', 30)); // => 'John, 30 years old from USA'
|
|
208
208
|
*/
|
|
209
209
|
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg2: T2, arg3: Placeholder): (arg1: T1, arg3: T3) => R;
|
|
@@ -225,7 +225,7 @@ declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3
|
|
|
225
225
|
* @returns Returns the new partially applied function.
|
|
226
226
|
* @example
|
|
227
227
|
* const logMessage = (level: string, message: string, timestamp: string) => `[${level}] ${message} at ${timestamp}`;
|
|
228
|
-
* const logError = partialRight(logMessage, 'ERROR', '2023-10-01');
|
|
228
|
+
* const logError = partialRight(logMessage, 'ERROR', partialRight.placeholder, '2023-10-01');
|
|
229
229
|
* console.log(logError('Something went wrong!')); // => '[ERROR] Something went wrong! at 2023-10-01'
|
|
230
230
|
*/
|
|
231
231
|
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: T2, arg3: Placeholder): (arg3: T3) => R;
|
|
@@ -288,7 +288,7 @@ declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3
|
|
|
288
288
|
* @returns Returns the new partially applied function.
|
|
289
289
|
* @example
|
|
290
290
|
* const createProfile = (name: string, age: number, country: string) => `${name}, ${age} from ${country}`;
|
|
291
|
-
* const createProfileFromCanada = partialRight(createProfile, '
|
|
291
|
+
* const createProfileFromCanada = partialRight(createProfile, 'John', partialRight.placeholder, 'Canada');
|
|
292
292
|
* console.log(createProfileFromCanada(30)); // => 'John, 30 from Canada'
|
|
293
293
|
*/
|
|
294
294
|
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg2: T2, arg3: T3): (arg1: T1) => R;
|
|
@@ -615,9 +615,9 @@ declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3
|
|
|
615
615
|
* @param args The arguments to be partially applied.
|
|
616
616
|
* @returns Returns the new partially applied function.
|
|
617
617
|
* @example
|
|
618
|
-
* const log = (...messages: string[]) =>
|
|
618
|
+
* const log = (...messages: string[]) => messages.join(' ');
|
|
619
619
|
* const logError = partialRight(log, 'Error:');
|
|
620
|
-
* logError('Something went wrong!'); // => '
|
|
620
|
+
* logError('Something went wrong!'); // => 'Something went wrong! Error:'
|
|
621
621
|
*/
|
|
622
622
|
declare function partialRight(func: (...args: any[]) => any, ...args: any[]): (...args: any[]) => any;
|
|
623
623
|
declare namespace partialRight {
|
package/dist/function/rest.d.mts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
*
|
|
25
25
|
* // Using start index 1
|
|
26
26
|
* const transformedFnWithStart = rest(fn, 1);
|
|
27
|
-
* console.log(transformedFnWithStart(1, 2, 3, 4)); // [1, [2, 3, 4]]
|
|
27
|
+
* console.log(transformedFnWithStart(1, 2, 3, 4)); // [1, [2, 3, 4], undefined]
|
|
28
28
|
*
|
|
29
29
|
* // With fewer arguments than the start index
|
|
30
30
|
* console.log(transformedFn(1)); // [1, undefined, []]
|
package/dist/function/rest.d.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
*
|
|
25
25
|
* // Using start index 1
|
|
26
26
|
* const transformedFnWithStart = rest(fn, 1);
|
|
27
|
-
* console.log(transformedFnWithStart(1, 2, 3, 4)); // [1, [2, 3, 4]]
|
|
27
|
+
* console.log(transformedFnWithStart(1, 2, 3, 4)); // [1, [2, 3, 4], undefined]
|
|
28
28
|
*
|
|
29
29
|
* // With fewer arguments than the start index
|
|
30
30
|
* console.log(transformedFn(1)); // [1, undefined, []]
|