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
package/dist/function/rest.js
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.mjs
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, []]
|
|
@@ -34,7 +34,9 @@
|
|
|
34
34
|
* // Clone an array with a customizer
|
|
35
35
|
* const arr = [1, 2, 3];
|
|
36
36
|
* const clonedArr = cloneDeepWith(arr, (value) => {
|
|
37
|
-
*
|
|
37
|
+
* if (typeof value === 'number') {
|
|
38
|
+
* return value + 1; // Increment each number
|
|
39
|
+
* }
|
|
38
40
|
* });
|
|
39
41
|
* console.log(clonedArr); // [2, 3, 4]
|
|
40
42
|
* console.log(clonedArr === arr); // false
|
|
@@ -34,7 +34,9 @@
|
|
|
34
34
|
* // Clone an array with a customizer
|
|
35
35
|
* const arr = [1, 2, 3];
|
|
36
36
|
* const clonedArr = cloneDeepWith(arr, (value) => {
|
|
37
|
-
*
|
|
37
|
+
* if (typeof value === 'number') {
|
|
38
|
+
* return value + 1; // Increment each number
|
|
39
|
+
* }
|
|
38
40
|
* });
|
|
39
41
|
* console.log(clonedArr); // [2, 3, 4]
|
|
40
42
|
* console.log(clonedArr === arr); // false
|
|
@@ -40,7 +40,9 @@ const require_isBuffer = require("../predicate/isBuffer.js");
|
|
|
40
40
|
* // Clone an array with a customizer
|
|
41
41
|
* const arr = [1, 2, 3];
|
|
42
42
|
* const clonedArr = cloneDeepWith(arr, (value) => {
|
|
43
|
-
*
|
|
43
|
+
* if (typeof value === 'number') {
|
|
44
|
+
* return value + 1; // Increment each number
|
|
45
|
+
* }
|
|
44
46
|
* });
|
|
45
47
|
* console.log(clonedArr); // [2, 3, 4]
|
|
46
48
|
* console.log(clonedArr === arr); // false
|
|
@@ -40,7 +40,9 @@ import { isBuffer } from "../predicate/isBuffer.mjs";
|
|
|
40
40
|
* // Clone an array with a customizer
|
|
41
41
|
* const arr = [1, 2, 3];
|
|
42
42
|
* const clonedArr = cloneDeepWith(arr, (value) => {
|
|
43
|
-
*
|
|
43
|
+
* if (typeof value === 'number') {
|
|
44
|
+
* return value + 1; // Increment each number
|
|
45
|
+
* }
|
|
44
46
|
* });
|
|
45
47
|
* console.log(clonedArr); // [2, 3, 4]
|
|
46
48
|
* console.log(clonedArr === arr); // false
|
|
@@ -5,12 +5,18 @@ interface FlattenObjectOptions {
|
|
|
5
5
|
* @default '.'
|
|
6
6
|
*/
|
|
7
7
|
delimiter?: string;
|
|
8
|
+
/**
|
|
9
|
+
* If true, arrays are kept as values instead of being flattened.
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
preserveArrays?: boolean;
|
|
8
13
|
}
|
|
9
14
|
/**
|
|
10
15
|
* Flattens a nested object into a single level object with delimiter-separated keys.
|
|
11
16
|
*
|
|
12
17
|
* @param object - The object to flatten.
|
|
13
18
|
* @param [options.delimiter='.'] - The delimiter to use between nested keys.
|
|
19
|
+
* @param [options.preserveArrays=false] - If true, arrays are kept as values instead of being flattened.
|
|
14
20
|
* @returns The flattened object.
|
|
15
21
|
*
|
|
16
22
|
* @example
|
|
@@ -31,9 +37,18 @@ interface FlattenObjectOptions {
|
|
|
31
37
|
* // 'd.0': 2,
|
|
32
38
|
* // 'd.1': 3
|
|
33
39
|
* // }
|
|
40
|
+
*
|
|
41
|
+
* const preserved = flattenObject(nestedObject, { preserveArrays: true });
|
|
42
|
+
* console.log(preserved);
|
|
43
|
+
* // Output:
|
|
44
|
+
* // {
|
|
45
|
+
* // 'a.b.c': 1,
|
|
46
|
+
* // 'd': [2, 3]
|
|
47
|
+
* // }
|
|
34
48
|
*/
|
|
35
49
|
declare function flattenObject(object: object, {
|
|
36
|
-
delimiter
|
|
50
|
+
delimiter,
|
|
51
|
+
preserveArrays
|
|
37
52
|
}?: FlattenObjectOptions): Record<string, any>;
|
|
38
53
|
//#endregion
|
|
39
54
|
export { flattenObject };
|
|
@@ -5,12 +5,18 @@ interface FlattenObjectOptions {
|
|
|
5
5
|
* @default '.'
|
|
6
6
|
*/
|
|
7
7
|
delimiter?: string;
|
|
8
|
+
/**
|
|
9
|
+
* If true, arrays are kept as values instead of being flattened.
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
preserveArrays?: boolean;
|
|
8
13
|
}
|
|
9
14
|
/**
|
|
10
15
|
* Flattens a nested object into a single level object with delimiter-separated keys.
|
|
11
16
|
*
|
|
12
17
|
* @param object - The object to flatten.
|
|
13
18
|
* @param [options.delimiter='.'] - The delimiter to use between nested keys.
|
|
19
|
+
* @param [options.preserveArrays=false] - If true, arrays are kept as values instead of being flattened.
|
|
14
20
|
* @returns The flattened object.
|
|
15
21
|
*
|
|
16
22
|
* @example
|
|
@@ -31,9 +37,18 @@ interface FlattenObjectOptions {
|
|
|
31
37
|
* // 'd.0': 2,
|
|
32
38
|
* // 'd.1': 3
|
|
33
39
|
* // }
|
|
40
|
+
*
|
|
41
|
+
* const preserved = flattenObject(nestedObject, { preserveArrays: true });
|
|
42
|
+
* console.log(preserved);
|
|
43
|
+
* // Output:
|
|
44
|
+
* // {
|
|
45
|
+
* // 'a.b.c': 1,
|
|
46
|
+
* // 'd': [2, 3]
|
|
47
|
+
* // }
|
|
34
48
|
*/
|
|
35
49
|
declare function flattenObject(object: object, {
|
|
36
|
-
delimiter
|
|
50
|
+
delimiter,
|
|
51
|
+
preserveArrays
|
|
37
52
|
}?: FlattenObjectOptions): Record<string, any>;
|
|
38
53
|
//#endregion
|
|
39
54
|
export { flattenObject };
|
|
@@ -5,6 +5,7 @@ const require_isPlainObject = require("../predicate/isPlainObject.js");
|
|
|
5
5
|
*
|
|
6
6
|
* @param object - The object to flatten.
|
|
7
7
|
* @param [options.delimiter='.'] - The delimiter to use between nested keys.
|
|
8
|
+
* @param [options.preserveArrays=false] - If true, arrays are kept as values instead of being flattened.
|
|
8
9
|
* @returns The flattened object.
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
@@ -25,11 +26,19 @@ const require_isPlainObject = require("../predicate/isPlainObject.js");
|
|
|
25
26
|
* // 'd.0': 2,
|
|
26
27
|
* // 'd.1': 3
|
|
27
28
|
* // }
|
|
29
|
+
*
|
|
30
|
+
* const preserved = flattenObject(nestedObject, { preserveArrays: true });
|
|
31
|
+
* console.log(preserved);
|
|
32
|
+
* // Output:
|
|
33
|
+
* // {
|
|
34
|
+
* // 'a.b.c': 1,
|
|
35
|
+
* // 'd': [2, 3]
|
|
36
|
+
* // }
|
|
28
37
|
*/
|
|
29
|
-
function flattenObject(object, { delimiter = "." } = {}) {
|
|
30
|
-
return flattenObjectImpl(object, "", delimiter);
|
|
38
|
+
function flattenObject(object, { delimiter = ".", preserveArrays = false } = {}) {
|
|
39
|
+
return flattenObjectImpl(object, "", delimiter, preserveArrays);
|
|
31
40
|
}
|
|
32
|
-
function flattenObjectImpl(object, prefix, delimiter) {
|
|
41
|
+
function flattenObjectImpl(object, prefix, delimiter, preserveArrays) {
|
|
33
42
|
const result = {};
|
|
34
43
|
const keys = Object.keys(object);
|
|
35
44
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -37,11 +46,11 @@ function flattenObjectImpl(object, prefix, delimiter) {
|
|
|
37
46
|
const value = object[key];
|
|
38
47
|
const prefixedKey = prefix ? `${prefix}${delimiter}${key}` : key;
|
|
39
48
|
if (require_isPlainObject.isPlainObject(value) && Object.keys(value).length > 0) {
|
|
40
|
-
Object.assign(result, flattenObjectImpl(value, prefixedKey, delimiter));
|
|
49
|
+
Object.assign(result, flattenObjectImpl(value, prefixedKey, delimiter, preserveArrays));
|
|
41
50
|
continue;
|
|
42
51
|
}
|
|
43
|
-
if (Array.isArray(value) && value.length > 0) {
|
|
44
|
-
Object.assign(result, flattenObjectImpl(value, prefixedKey, delimiter));
|
|
52
|
+
if (Array.isArray(value) && !preserveArrays && value.length > 0) {
|
|
53
|
+
Object.assign(result, flattenObjectImpl(value, prefixedKey, delimiter, preserveArrays));
|
|
45
54
|
continue;
|
|
46
55
|
}
|
|
47
56
|
result[prefixedKey] = value;
|
|
@@ -5,6 +5,7 @@ import { isPlainObject } from "../predicate/isPlainObject.mjs";
|
|
|
5
5
|
*
|
|
6
6
|
* @param object - The object to flatten.
|
|
7
7
|
* @param [options.delimiter='.'] - The delimiter to use between nested keys.
|
|
8
|
+
* @param [options.preserveArrays=false] - If true, arrays are kept as values instead of being flattened.
|
|
8
9
|
* @returns The flattened object.
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
@@ -25,11 +26,19 @@ import { isPlainObject } from "../predicate/isPlainObject.mjs";
|
|
|
25
26
|
* // 'd.0': 2,
|
|
26
27
|
* // 'd.1': 3
|
|
27
28
|
* // }
|
|
29
|
+
*
|
|
30
|
+
* const preserved = flattenObject(nestedObject, { preserveArrays: true });
|
|
31
|
+
* console.log(preserved);
|
|
32
|
+
* // Output:
|
|
33
|
+
* // {
|
|
34
|
+
* // 'a.b.c': 1,
|
|
35
|
+
* // 'd': [2, 3]
|
|
36
|
+
* // }
|
|
28
37
|
*/
|
|
29
|
-
function flattenObject(object, { delimiter = "." } = {}) {
|
|
30
|
-
return flattenObjectImpl(object, "", delimiter);
|
|
38
|
+
function flattenObject(object, { delimiter = ".", preserveArrays = false } = {}) {
|
|
39
|
+
return flattenObjectImpl(object, "", delimiter, preserveArrays);
|
|
31
40
|
}
|
|
32
|
-
function flattenObjectImpl(object, prefix, delimiter) {
|
|
41
|
+
function flattenObjectImpl(object, prefix, delimiter, preserveArrays) {
|
|
33
42
|
const result = {};
|
|
34
43
|
const keys = Object.keys(object);
|
|
35
44
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -37,11 +46,11 @@ function flattenObjectImpl(object, prefix, delimiter) {
|
|
|
37
46
|
const value = object[key];
|
|
38
47
|
const prefixedKey = prefix ? `${prefix}${delimiter}${key}` : key;
|
|
39
48
|
if (isPlainObject(value) && Object.keys(value).length > 0) {
|
|
40
|
-
Object.assign(result, flattenObjectImpl(value, prefixedKey, delimiter));
|
|
49
|
+
Object.assign(result, flattenObjectImpl(value, prefixedKey, delimiter, preserveArrays));
|
|
41
50
|
continue;
|
|
42
51
|
}
|
|
43
|
-
if (Array.isArray(value) && value.length > 0) {
|
|
44
|
-
Object.assign(result, flattenObjectImpl(value, prefixedKey, delimiter));
|
|
52
|
+
if (Array.isArray(value) && !preserveArrays && value.length > 0) {
|
|
53
|
+
Object.assign(result, flattenObjectImpl(value, prefixedKey, delimiter, preserveArrays));
|
|
45
54
|
continue;
|
|
46
55
|
}
|
|
47
56
|
result[prefixedKey] = value;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
|
-
"version": "1.50.0-dev.
|
|
3
|
+
"version": "1.50.0-dev.2059+87fc74fc",
|
|
4
4
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
5
5
|
"homepage": "https://es-toolkit.dev",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
@@ -218,7 +218,8 @@
|
|
|
218
218
|
"workspaces": [
|
|
219
219
|
"docs",
|
|
220
220
|
"benchmarks",
|
|
221
|
-
"tests/types"
|
|
221
|
+
"tests/types",
|
|
222
|
+
"tests/browser-compat"
|
|
222
223
|
],
|
|
223
224
|
"scripts": {
|
|
224
225
|
"bench": "yarn workspace benchmarks bench",
|
|
@@ -250,6 +251,8 @@
|
|
|
250
251
|
"broken-link-checker": "0.7.8",
|
|
251
252
|
"eslint": "^9.39.2",
|
|
252
253
|
"eslint-config-prettier": "^9.1.0",
|
|
254
|
+
"eslint-plugin-compat": "^7.0.2",
|
|
255
|
+
"eslint-plugin-es-x": "^10.0.0",
|
|
253
256
|
"eslint-plugin-no-for-of-array": "^0.0.1",
|
|
254
257
|
"eslint-plugin-prettier": "^5.2.1",
|
|
255
258
|
"eslint-plugin-vue": "^9.28.0",
|