es-toolkit 1.25.1-dev.796 → 1.25.1-dev.798
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/_chunk/{isWeakSet-BuFfzX.js → isWeakSet-D8h8bS.js} +17 -19
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/flatten.d.mts +2 -2
- package/dist/compat/array/flatten.d.ts +2 -2
- package/dist/compat/array/flatten.mjs +4 -2
- package/dist/compat/array/flattenDeep.d.mts +2 -2
- package/dist/compat/array/flattenDeep.d.ts +2 -2
- package/dist/compat/array/flattenDepth.d.mts +2 -2
- package/dist/compat/array/flattenDepth.d.ts +2 -2
- package/dist/compat/array/slice.d.mts +2 -2
- package/dist/compat/array/slice.d.ts +2 -2
- package/dist/compat/array/slice.mjs +2 -1
- package/dist/compat/array/zipObjectDeep.d.mts +4 -4
- package/dist/compat/array/zipObjectDeep.d.ts +4 -4
- package/dist/compat/array/zipObjectDeep.mjs +8 -1
- package/dist/compat/index.d.mts +1 -3
- package/dist/compat/index.d.ts +1 -3
- package/dist/compat/index.js +11 -5
- package/dist/compat/index.mjs +1 -3
- package/dist/index.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -3
- package/dist/predicate/index.d.mts +1 -3
- package/dist/predicate/index.d.ts +1 -3
- package/dist/predicate/index.js +1 -1
- package/dist/predicate/index.mjs +1 -3
- package/dist/predicate/isJSONValue.d.mts +30 -1
- package/dist/predicate/isJSONValue.d.ts +30 -1
- package/dist/predicate/isJSONValue.mjs +25 -3
- package/package.json +1 -1
- package/dist/predicate/isJSONArray.d.mts +0 -17
- package/dist/predicate/isJSONArray.d.ts +0 -17
- package/dist/predicate/isJSONArray.mjs +0 -10
- package/dist/predicate/isJSONObject.d.mts +0 -16
- package/dist/predicate/isJSONObject.d.ts +0 -16
- package/dist/predicate/isJSONObject.mjs +0 -22
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @template T - The type of elements within the array.
|
|
5
5
|
* @template D - The depth to which the array should be flattened.
|
|
6
|
-
* @param {T
|
|
6
|
+
* @param {ArrayLike<T> | null | undefined} value - The object to flatten.
|
|
7
7
|
* @param {D} depth - The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.
|
|
8
8
|
* @returns {Array<FlatArray<T[], D>> | []} A new array that has been flattened.
|
|
9
9
|
*
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
* const arr = flatten([1, [2, 3], [4, [5, 6]]], 2);
|
|
15
15
|
* // Returns: [1, 2, 3, 4, 5, 6]
|
|
16
16
|
*/
|
|
17
|
-
declare function flatten<T, D extends number = 1>(value:
|
|
17
|
+
declare function flatten<T, D extends number = 1>(value: ArrayLike<T> | null | undefined, depth?: D): Array<FlatArray<T[], D>> | [];
|
|
18
18
|
|
|
19
19
|
export { flatten };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @template T - The type of elements within the array.
|
|
5
5
|
* @template D - The depth to which the array should be flattened.
|
|
6
|
-
* @param {T
|
|
6
|
+
* @param {ArrayLike<T> | null | undefined} value - The object to flatten.
|
|
7
7
|
* @param {D} depth - The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.
|
|
8
8
|
* @returns {Array<FlatArray<T[], D>> | []} A new array that has been flattened.
|
|
9
9
|
*
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
* const arr = flatten([1, [2, 3], [4, [5, 6]]], 2);
|
|
15
15
|
* // Returns: [1, 2, 3, 4, 5, 6]
|
|
16
16
|
*/
|
|
17
|
-
declare function flatten<T, D extends number = 1>(value:
|
|
17
|
+
declare function flatten<T, D extends number = 1>(value: ArrayLike<T> | null | undefined, depth?: D): Array<FlatArray<T[], D>> | [];
|
|
18
18
|
|
|
19
19
|
export { flatten };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
2
|
+
|
|
1
3
|
function flatten(value, depth = 1) {
|
|
2
4
|
const result = [];
|
|
3
5
|
const flooredDepth = Math.floor(depth);
|
|
4
|
-
if (!
|
|
6
|
+
if (!isArrayLike(value)) {
|
|
5
7
|
return result;
|
|
6
8
|
}
|
|
7
9
|
const recursive = (arr, currentDepth) => {
|
|
@@ -23,7 +25,7 @@ function flatten(value, depth = 1) {
|
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
};
|
|
26
|
-
recursive(value, 0);
|
|
28
|
+
recursive(Array.from(value), 0);
|
|
27
29
|
return result;
|
|
28
30
|
}
|
|
29
31
|
|
|
@@ -13,13 +13,13 @@ type ExtractNestedArrayType<T> = T extends ReadonlyArray<infer U> ? ExtractNeste
|
|
|
13
13
|
* Flattens all depths of a nested array.
|
|
14
14
|
*
|
|
15
15
|
* @template T - The type of elements within the array.
|
|
16
|
-
* @param {T
|
|
16
|
+
* @param {ArrayLike<T>} value - The value to flatten.
|
|
17
17
|
* @returns {Array<ExtractNestedArrayType<T>> | []} A new array that has been flattened.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* const value = flattenDeep([1, [2, [3]], [4, [5, 6]]]);
|
|
21
21
|
* // Returns: [1, 2, 3, 4, 5, 6]
|
|
22
22
|
*/
|
|
23
|
-
declare function flattenDeep<T>(value:
|
|
23
|
+
declare function flattenDeep<T>(value: ArrayLike<T> | null | undefined): Array<ExtractNestedArrayType<T>> | [];
|
|
24
24
|
|
|
25
25
|
export { flattenDeep };
|
|
@@ -13,13 +13,13 @@ type ExtractNestedArrayType<T> = T extends ReadonlyArray<infer U> ? ExtractNeste
|
|
|
13
13
|
* Flattens all depths of a nested array.
|
|
14
14
|
*
|
|
15
15
|
* @template T - The type of elements within the array.
|
|
16
|
-
* @param {T
|
|
16
|
+
* @param {ArrayLike<T>} value - The value to flatten.
|
|
17
17
|
* @returns {Array<ExtractNestedArrayType<T>> | []} A new array that has been flattened.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* const value = flattenDeep([1, [2, [3]], [4, [5, 6]]]);
|
|
21
21
|
* // Returns: [1, 2, 3, 4, 5, 6]
|
|
22
22
|
*/
|
|
23
|
-
declare function flattenDeep<T>(value:
|
|
23
|
+
declare function flattenDeep<T>(value: ArrayLike<T> | null | undefined): Array<ExtractNestedArrayType<T>> | [];
|
|
24
24
|
|
|
25
25
|
export { flattenDeep };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @template T - The type of elements within the array.
|
|
5
5
|
* @template D - The depth to which the array should be flattened.
|
|
6
|
-
* @param {T
|
|
6
|
+
* @param {ArrayLike<T> | null | undefined} value - The value to flatten.
|
|
7
7
|
* @param {D} depth - The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.
|
|
8
8
|
* @returns {Array<FlatArray<T[], D>> | []} A new array that has been flattened.
|
|
9
9
|
*
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
* const arr = flatten([1, [2, 3], [4, [5, 6]]], 2);
|
|
15
15
|
* // Returns: [1, 2, 3, 4, 5, 6]
|
|
16
16
|
*/
|
|
17
|
-
declare function flattenDepth<T, D extends number = 1>(value:
|
|
17
|
+
declare function flattenDepth<T, D extends number = 1>(value: ArrayLike<T> | null | undefined, depth?: D): Array<FlatArray<T[], D>> | [];
|
|
18
18
|
|
|
19
19
|
export { flattenDepth };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @template T - The type of elements within the array.
|
|
5
5
|
* @template D - The depth to which the array should be flattened.
|
|
6
|
-
* @param {T
|
|
6
|
+
* @param {ArrayLike<T> | null | undefined} value - The value to flatten.
|
|
7
7
|
* @param {D} depth - The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.
|
|
8
8
|
* @returns {Array<FlatArray<T[], D>> | []} A new array that has been flattened.
|
|
9
9
|
*
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
* const arr = flatten([1, [2, 3], [4, [5, 6]]], 2);
|
|
15
15
|
* // Returns: [1, 2, 3, 4, 5, 6]
|
|
16
16
|
*/
|
|
17
|
-
declare function flattenDepth<T, D extends number = 1>(value:
|
|
17
|
+
declare function flattenDepth<T, D extends number = 1>(value: ArrayLike<T> | null | undefined, depth?: D): Array<FlatArray<T[], D>> | [];
|
|
18
18
|
|
|
19
19
|
export { flattenDepth };
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* It does not return a dense array for sparse arrays unlike the native `Array.prototype.slice`.
|
|
5
5
|
*
|
|
6
6
|
* @template T - The type of the array elements.
|
|
7
|
-
* @param {T
|
|
7
|
+
* @param {ArrayLike<T> | null | undefined} array - The array to slice.
|
|
8
8
|
* @param {number} [start=0] - The start position.
|
|
9
9
|
* @param {number} [end=array.length] - The end position.
|
|
10
10
|
* @returns {T[]} - Returns the slice of `array`.
|
|
@@ -13,6 +13,6 @@
|
|
|
13
13
|
* slice([1, 2, 3], 1, 2); // => [2]
|
|
14
14
|
* slice(new Array(3)); // => [undefined, undefined, undefined]
|
|
15
15
|
*/
|
|
16
|
-
declare function slice<T>(array:
|
|
16
|
+
declare function slice<T>(array: ArrayLike<T> | null | undefined, start?: number, end?: number): T[];
|
|
17
17
|
|
|
18
18
|
export { slice };
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* It does not return a dense array for sparse arrays unlike the native `Array.prototype.slice`.
|
|
5
5
|
*
|
|
6
6
|
* @template T - The type of the array elements.
|
|
7
|
-
* @param {T
|
|
7
|
+
* @param {ArrayLike<T> | null | undefined} array - The array to slice.
|
|
8
8
|
* @param {number} [start=0] - The start position.
|
|
9
9
|
* @param {number} [end=array.length] - The end position.
|
|
10
10
|
* @returns {T[]} - Returns the slice of `array`.
|
|
@@ -13,6 +13,6 @@
|
|
|
13
13
|
* slice([1, 2, 3], 1, 2); // => [2]
|
|
14
14
|
* slice(new Array(3)); // => [undefined, undefined, undefined]
|
|
15
15
|
*/
|
|
16
|
-
declare function slice<T>(array:
|
|
16
|
+
declare function slice<T>(array: ArrayLike<T> | null | undefined, start?: number, end?: number): T[];
|
|
17
17
|
|
|
18
18
|
export { slice };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { isIterateeCall } from '../_internal/isIterateeCall.mjs';
|
|
2
|
+
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
2
3
|
import { toInteger } from '../util/toInteger.mjs';
|
|
3
4
|
|
|
4
5
|
function slice(array, start, end) {
|
|
5
|
-
if (array
|
|
6
|
+
if (!isArrayLike(array)) {
|
|
6
7
|
return [];
|
|
7
8
|
}
|
|
8
9
|
const length = array.length;
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @template P - The type of property paths.
|
|
11
11
|
* @template V - The type of values corresponding to the property paths.
|
|
12
|
-
* @param {P
|
|
13
|
-
* @param {V
|
|
14
|
-
* @returns {
|
|
12
|
+
* @param {ArrayLike<P | P[]>} keys - An array of property paths, each path can be a dot-separated string or an array of property names.
|
|
13
|
+
* @param {ArrayLike<V>} values - An array of values corresponding to the property paths.
|
|
14
|
+
* @returns {{ [K in P]: V }} A new object composed of the given property paths and values.
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* const paths = ['a.b.c', 'd.e.f'];
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* const result = zipObjectDeep(paths, values);
|
|
32
32
|
* // result will be { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
|
|
33
33
|
*/
|
|
34
|
-
declare function zipObjectDeep<P extends PropertyKey, V>(keys:
|
|
34
|
+
declare function zipObjectDeep<P extends PropertyKey, V>(keys: ArrayLike<P | P[]>, values: ArrayLike<V>): {
|
|
35
35
|
[K in P]: V;
|
|
36
36
|
};
|
|
37
37
|
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @template P - The type of property paths.
|
|
11
11
|
* @template V - The type of values corresponding to the property paths.
|
|
12
|
-
* @param {P
|
|
13
|
-
* @param {V
|
|
14
|
-
* @returns {
|
|
12
|
+
* @param {ArrayLike<P | P[]>} keys - An array of property paths, each path can be a dot-separated string or an array of property names.
|
|
13
|
+
* @param {ArrayLike<V>} values - An array of values corresponding to the property paths.
|
|
14
|
+
* @returns {{ [K in P]: V }} A new object composed of the given property paths and values.
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* const paths = ['a.b.c', 'd.e.f'];
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* const result = zipObjectDeep(paths, values);
|
|
32
32
|
* // result will be { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
|
|
33
33
|
*/
|
|
34
|
-
declare function zipObjectDeep<P extends PropertyKey, V>(keys:
|
|
34
|
+
declare function zipObjectDeep<P extends PropertyKey, V>(keys: ArrayLike<P | P[]>, values: ArrayLike<V>): {
|
|
35
35
|
[K in P]: V;
|
|
36
36
|
};
|
|
37
37
|
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { zip } from '../../array/zip.mjs';
|
|
2
2
|
import { set } from '../object/set.mjs';
|
|
3
|
+
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
|
|
4
5
|
function zipObjectDeep(keys, values) {
|
|
5
6
|
const result = {};
|
|
6
|
-
|
|
7
|
+
if (!isArrayLike(keys)) {
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
if (!isArrayLike(values)) {
|
|
11
|
+
values = [];
|
|
12
|
+
}
|
|
13
|
+
const zipped = zip(Array.from(keys), Array.from(values));
|
|
7
14
|
for (let i = 0; i < zipped.length; i++) {
|
|
8
15
|
const [key, value] = zipped[i];
|
|
9
16
|
if (key != null) {
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -60,9 +60,7 @@ export { isBlob } from '../predicate/isBlob.mjs';
|
|
|
60
60
|
export { isEqual } from '../predicate/isEqual.mjs';
|
|
61
61
|
export { isFile } from '../predicate/isFile.mjs';
|
|
62
62
|
export { isFunction } from '../predicate/isFunction.mjs';
|
|
63
|
-
export { isJSONArray } from '../predicate/
|
|
64
|
-
export { isJSONObject } from '../predicate/isJSONObject.mjs';
|
|
65
|
-
export { isJSONValue } from '../predicate/isJSONValue.mjs';
|
|
63
|
+
export { isJSONArray, isJSONObject, isJSONValue } from '../predicate/isJSONValue.mjs';
|
|
66
64
|
export { isLength } from '../predicate/isLength.mjs';
|
|
67
65
|
export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
68
66
|
export { isNull } from '../predicate/isNull.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -60,9 +60,7 @@ export { isBlob } from '../predicate/isBlob.js';
|
|
|
60
60
|
export { isEqual } from '../predicate/isEqual.js';
|
|
61
61
|
export { isFile } from '../predicate/isFile.js';
|
|
62
62
|
export { isFunction } from '../predicate/isFunction.js';
|
|
63
|
-
export { isJSONArray } from '../predicate/
|
|
64
|
-
export { isJSONObject } from '../predicate/isJSONObject.js';
|
|
65
|
-
export { isJSONValue } from '../predicate/isJSONValue.js';
|
|
63
|
+
export { isJSONArray, isJSONObject, isJSONValue } from '../predicate/isJSONValue.js';
|
|
66
64
|
export { isLength } from '../predicate/isLength.js';
|
|
67
65
|
export { isNotNil } from '../predicate/isNotNil.js';
|
|
68
66
|
export { isNull } from '../predicate/isNull.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const sumBy = require('../_chunk/sumBy-BkErWJ.js');
|
|
|
10
10
|
const randomInt = require('../_chunk/randomInt-CF7bZK.js');
|
|
11
11
|
const toMerged = require('../_chunk/toMerged-BLnW4M.js');
|
|
12
12
|
const isPlainObject$1 = require('../_chunk/isPlainObject-octpoD.js');
|
|
13
|
-
const isWeakSet$1 = require('../_chunk/isWeakSet-
|
|
13
|
+
const isWeakSet$1 = require('../_chunk/isWeakSet-D8h8bS.js');
|
|
14
14
|
const upperFirst = require('../_chunk/upperFirst-BUECmK.js');
|
|
15
15
|
|
|
16
16
|
function castArray(value) {
|
|
@@ -666,7 +666,7 @@ function findLastIndex(arr, doesMatch, fromIndex = arr ? arr.length - 1 : 0) {
|
|
|
666
666
|
function flatten(value, depth = 1) {
|
|
667
667
|
const result = [];
|
|
668
668
|
const flooredDepth = Math.floor(depth);
|
|
669
|
-
if (!
|
|
669
|
+
if (!isArrayLike(value)) {
|
|
670
670
|
return result;
|
|
671
671
|
}
|
|
672
672
|
const recursive = (arr, currentDepth) => {
|
|
@@ -688,7 +688,7 @@ function flatten(value, depth = 1) {
|
|
|
688
688
|
}
|
|
689
689
|
}
|
|
690
690
|
};
|
|
691
|
-
recursive(value, 0);
|
|
691
|
+
recursive(Array.from(value), 0);
|
|
692
692
|
return result;
|
|
693
693
|
}
|
|
694
694
|
|
|
@@ -971,7 +971,7 @@ function isIterateeCall(value, index, object) {
|
|
|
971
971
|
}
|
|
972
972
|
|
|
973
973
|
function slice(array, start, end) {
|
|
974
|
-
if (array
|
|
974
|
+
if (!isArrayLike(array)) {
|
|
975
975
|
return [];
|
|
976
976
|
}
|
|
977
977
|
const length = array.length;
|
|
@@ -1091,7 +1091,13 @@ function set(obj, path, value) {
|
|
|
1091
1091
|
|
|
1092
1092
|
function zipObjectDeep(keys, values) {
|
|
1093
1093
|
const result = {};
|
|
1094
|
-
|
|
1094
|
+
if (!isArrayLike(keys)) {
|
|
1095
|
+
return result;
|
|
1096
|
+
}
|
|
1097
|
+
if (!isArrayLike(values)) {
|
|
1098
|
+
values = [];
|
|
1099
|
+
}
|
|
1100
|
+
const zipped = zipWith.zip(Array.from(keys), Array.from(values));
|
|
1095
1101
|
for (let i = 0; i < zipped.length; i++) {
|
|
1096
1102
|
const [key, value] = zipped[i];
|
|
1097
1103
|
if (key != null) {
|
package/dist/compat/index.mjs
CHANGED
|
@@ -63,9 +63,7 @@ export { isEqual } from '../predicate/isEqual.mjs';
|
|
|
63
63
|
export { eq } from './util/eq.mjs';
|
|
64
64
|
export { isFile } from '../predicate/isFile.mjs';
|
|
65
65
|
export { isFunction } from '../predicate/isFunction.mjs';
|
|
66
|
-
export { isJSONArray } from '../predicate/
|
|
67
|
-
export { isJSONObject } from '../predicate/isJSONObject.mjs';
|
|
68
|
-
export { isJSONValue } from '../predicate/isJSONValue.mjs';
|
|
66
|
+
export { isJSONArray, isJSONObject, isJSONValue } from '../predicate/isJSONValue.mjs';
|
|
69
67
|
export { isLength } from '../predicate/isLength.mjs';
|
|
70
68
|
export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
71
69
|
export { isNull } from '../predicate/isNull.mjs';
|
package/dist/index.d.mts
CHANGED
|
@@ -107,9 +107,7 @@ export { isEqualWith } from './predicate/isEqualWith.mjs';
|
|
|
107
107
|
export { isError } from './predicate/isError.mjs';
|
|
108
108
|
export { isFile } from './predicate/isFile.mjs';
|
|
109
109
|
export { isFunction } from './predicate/isFunction.mjs';
|
|
110
|
-
export { isJSONArray } from './predicate/
|
|
111
|
-
export { isJSONObject } from './predicate/isJSONObject.mjs';
|
|
112
|
-
export { isJSONValue } from './predicate/isJSONValue.mjs';
|
|
110
|
+
export { isJSONArray, isJSONObject, isJSONValue } from './predicate/isJSONValue.mjs';
|
|
113
111
|
export { isLength } from './predicate/isLength.mjs';
|
|
114
112
|
export { isMap } from './predicate/isMap.mjs';
|
|
115
113
|
export { isNil } from './predicate/isNil.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -107,9 +107,7 @@ export { isEqualWith } from './predicate/isEqualWith.js';
|
|
|
107
107
|
export { isError } from './predicate/isError.js';
|
|
108
108
|
export { isFile } from './predicate/isFile.js';
|
|
109
109
|
export { isFunction } from './predicate/isFunction.js';
|
|
110
|
-
export { isJSONArray } from './predicate/
|
|
111
|
-
export { isJSONObject } from './predicate/isJSONObject.js';
|
|
112
|
-
export { isJSONValue } from './predicate/isJSONValue.js';
|
|
110
|
+
export { isJSONArray, isJSONObject, isJSONValue } from './predicate/isJSONValue.js';
|
|
113
111
|
export { isLength } from './predicate/isLength.js';
|
|
114
112
|
export { isMap } from './predicate/isMap.js';
|
|
115
113
|
export { isNil } from './predicate/isNil.js';
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ const randomInt = require('./_chunk/randomInt-CF7bZK.js');
|
|
|
13
13
|
const math_index = require('./math/index.js');
|
|
14
14
|
const toMerged = require('./_chunk/toMerged-BLnW4M.js');
|
|
15
15
|
const object_index = require('./object/index.js');
|
|
16
|
-
const isWeakSet = require('./_chunk/isWeakSet-
|
|
16
|
+
const isWeakSet = require('./_chunk/isWeakSet-D8h8bS.js');
|
|
17
17
|
const predicate_index = require('./predicate/index.js');
|
|
18
18
|
const isPlainObject = require('./_chunk/isPlainObject-octpoD.js');
|
|
19
19
|
const upperFirst = require('./_chunk/upperFirst-BUECmK.js');
|
package/dist/index.mjs
CHANGED
|
@@ -107,9 +107,7 @@ export { isEqualWith } from './predicate/isEqualWith.mjs';
|
|
|
107
107
|
export { isError } from './predicate/isError.mjs';
|
|
108
108
|
export { isFile } from './predicate/isFile.mjs';
|
|
109
109
|
export { isFunction } from './predicate/isFunction.mjs';
|
|
110
|
-
export { isJSONArray } from './predicate/
|
|
111
|
-
export { isJSONObject } from './predicate/isJSONObject.mjs';
|
|
112
|
-
export { isJSONValue } from './predicate/isJSONValue.mjs';
|
|
110
|
+
export { isJSONArray, isJSONObject, isJSONValue } from './predicate/isJSONValue.mjs';
|
|
113
111
|
export { isLength } from './predicate/isLength.mjs';
|
|
114
112
|
export { isMap } from './predicate/isMap.mjs';
|
|
115
113
|
export { isNil } from './predicate/isNil.mjs';
|
|
@@ -7,9 +7,7 @@ export { isEqualWith } from './isEqualWith.mjs';
|
|
|
7
7
|
export { isError } from './isError.mjs';
|
|
8
8
|
export { isFile } from './isFile.mjs';
|
|
9
9
|
export { isFunction } from './isFunction.mjs';
|
|
10
|
-
export { isJSONArray } from './
|
|
11
|
-
export { isJSONObject } from './isJSONObject.mjs';
|
|
12
|
-
export { isJSONValue } from './isJSONValue.mjs';
|
|
10
|
+
export { isJSONArray, isJSONObject, isJSONValue } from './isJSONValue.mjs';
|
|
13
11
|
export { isLength } from './isLength.mjs';
|
|
14
12
|
export { isMap } from './isMap.mjs';
|
|
15
13
|
export { isNil } from './isNil.mjs';
|
|
@@ -7,9 +7,7 @@ export { isEqualWith } from './isEqualWith.js';
|
|
|
7
7
|
export { isError } from './isError.js';
|
|
8
8
|
export { isFile } from './isFile.js';
|
|
9
9
|
export { isFunction } from './isFunction.js';
|
|
10
|
-
export { isJSONArray } from './
|
|
11
|
-
export { isJSONObject } from './isJSONObject.js';
|
|
12
|
-
export { isJSONValue } from './isJSONValue.js';
|
|
10
|
+
export { isJSONArray, isJSONObject, isJSONValue } from './isJSONValue.js';
|
|
13
11
|
export { isLength } from './isLength.js';
|
|
14
12
|
export { isMap } from './isMap.js';
|
|
15
13
|
export { isNil } from './isNil.js';
|
package/dist/predicate/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const isWeakSet = require('../_chunk/isWeakSet-
|
|
5
|
+
const isWeakSet = require('../_chunk/isWeakSet-D8h8bS.js');
|
|
6
6
|
const isPlainObject = require('../_chunk/isPlainObject-octpoD.js');
|
|
7
7
|
|
|
8
8
|
function isBoolean(x) {
|
package/dist/predicate/index.mjs
CHANGED
|
@@ -7,9 +7,7 @@ export { isEqualWith } from './isEqualWith.mjs';
|
|
|
7
7
|
export { isError } from './isError.mjs';
|
|
8
8
|
export { isFile } from './isFile.mjs';
|
|
9
9
|
export { isFunction } from './isFunction.mjs';
|
|
10
|
-
export { isJSONArray } from './
|
|
11
|
-
export { isJSONObject } from './isJSONObject.mjs';
|
|
12
|
-
export { isJSONValue } from './isJSONValue.mjs';
|
|
10
|
+
export { isJSONArray, isJSONObject, isJSONValue } from './isJSONValue.mjs';
|
|
13
11
|
export { isLength } from './isLength.mjs';
|
|
14
12
|
export { isMap } from './isMap.mjs';
|
|
15
13
|
export { isNil } from './isNil.mjs';
|
|
@@ -23,5 +23,34 @@
|
|
|
23
23
|
* console.log(isJSONValue(() => {})); // false
|
|
24
24
|
*/
|
|
25
25
|
declare function isJSONValue(value: unknown): value is Record<string, any> | any[] | string | number | boolean | null;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a given value is a valid JSON array.
|
|
28
|
+
*
|
|
29
|
+
* A valid JSON array is defined as an array where all items are valid JSON values.
|
|
30
|
+
*
|
|
31
|
+
* @param {unknown} value - The value to check.
|
|
32
|
+
* @returns {value is any[]} - True if the value is a valid JSON array, otherwise false.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* console.log(isJSONArray([1, 2, 3])); // true
|
|
36
|
+
* console.log(isJSONArray(["string", null, true])); // true
|
|
37
|
+
* console.log(isJSONArray([1, 2, () => {}])); // false
|
|
38
|
+
* console.log(isJSONArray("not an array")); // false
|
|
39
|
+
*/
|
|
40
|
+
declare function isJSONArray(value: unknown): value is any[];
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a value is a JSON object.
|
|
43
|
+
*
|
|
44
|
+
* A valid JSON object is defined as an object with string keys and valid JSON values.
|
|
45
|
+
*
|
|
46
|
+
* @param {unknown} obj The value to check.
|
|
47
|
+
* @returns {obj is Record<string, any>} True if `obj` is a JSON object, false otherwise.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* isJSONObject({ nested: { boolean: true, array: [1, 2, 3], string: 'test', null: null } }); // true
|
|
51
|
+
* isJSONObject({ regexp: /test/ }); // false
|
|
52
|
+
* isJSONObject(123); // false
|
|
53
|
+
*/
|
|
54
|
+
declare function isJSONObject(obj: unknown): obj is Record<string, any>;
|
|
26
55
|
|
|
27
|
-
export { isJSONValue };
|
|
56
|
+
export { isJSONArray, isJSONObject, isJSONValue };
|
|
@@ -23,5 +23,34 @@
|
|
|
23
23
|
* console.log(isJSONValue(() => {})); // false
|
|
24
24
|
*/
|
|
25
25
|
declare function isJSONValue(value: unknown): value is Record<string, any> | any[] | string | number | boolean | null;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a given value is a valid JSON array.
|
|
28
|
+
*
|
|
29
|
+
* A valid JSON array is defined as an array where all items are valid JSON values.
|
|
30
|
+
*
|
|
31
|
+
* @param {unknown} value - The value to check.
|
|
32
|
+
* @returns {value is any[]} - True if the value is a valid JSON array, otherwise false.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* console.log(isJSONArray([1, 2, 3])); // true
|
|
36
|
+
* console.log(isJSONArray(["string", null, true])); // true
|
|
37
|
+
* console.log(isJSONArray([1, 2, () => {}])); // false
|
|
38
|
+
* console.log(isJSONArray("not an array")); // false
|
|
39
|
+
*/
|
|
40
|
+
declare function isJSONArray(value: unknown): value is any[];
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a value is a JSON object.
|
|
43
|
+
*
|
|
44
|
+
* A valid JSON object is defined as an object with string keys and valid JSON values.
|
|
45
|
+
*
|
|
46
|
+
* @param {unknown} obj The value to check.
|
|
47
|
+
* @returns {obj is Record<string, any>} True if `obj` is a JSON object, false otherwise.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* isJSONObject({ nested: { boolean: true, array: [1, 2, 3], string: 'test', null: null } }); // true
|
|
51
|
+
* isJSONObject({ regexp: /test/ }); // false
|
|
52
|
+
* isJSONObject(123); // false
|
|
53
|
+
*/
|
|
54
|
+
declare function isJSONObject(obj: unknown): obj is Record<string, any>;
|
|
26
55
|
|
|
27
|
-
export { isJSONValue };
|
|
56
|
+
export { isJSONArray, isJSONObject, isJSONValue };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isJSONObject } from './isJSONObject.mjs';
|
|
1
|
+
import { isPlainObject } from './isPlainObject.mjs';
|
|
3
2
|
|
|
4
3
|
function isJSONValue(value) {
|
|
5
4
|
switch (typeof value) {
|
|
@@ -16,5 +15,28 @@ function isJSONValue(value) {
|
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
}
|
|
18
|
+
function isJSONArray(value) {
|
|
19
|
+
if (!Array.isArray(value)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return value.every(item => isJSONValue(item));
|
|
23
|
+
}
|
|
24
|
+
function isJSONObject(obj) {
|
|
25
|
+
if (!isPlainObject(obj)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const keys = Reflect.ownKeys(obj);
|
|
29
|
+
for (let i = 0; i < keys.length; i++) {
|
|
30
|
+
const key = keys[i];
|
|
31
|
+
const value = obj[key];
|
|
32
|
+
if (typeof key !== 'string') {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (!isJSONValue(value)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
19
41
|
|
|
20
|
-
export { isJSONValue };
|
|
42
|
+
export { isJSONArray, isJSONObject, isJSONValue };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
3
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
4
|
-
"version": "1.25.1-dev.
|
|
4
|
+
"version": "1.25.1-dev.798+61f5bfd7",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a given value is a valid JSON array.
|
|
3
|
-
*
|
|
4
|
-
* A valid JSON array is defined as an array where all items are valid JSON values.
|
|
5
|
-
*
|
|
6
|
-
* @param {unknown} value - The value to check.
|
|
7
|
-
* @returns {value is any[]} - True if the value is a valid JSON array, otherwise false.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* console.log(isJSONArray([1, 2, 3])); // true
|
|
11
|
-
* console.log(isJSONArray(["string", null, true])); // true
|
|
12
|
-
* console.log(isJSONArray([1, 2, () => {}])); // false
|
|
13
|
-
* console.log(isJSONArray("not an array")); // false
|
|
14
|
-
*/
|
|
15
|
-
declare function isJSONArray(value: unknown): value is any[];
|
|
16
|
-
|
|
17
|
-
export { isJSONArray };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a given value is a valid JSON array.
|
|
3
|
-
*
|
|
4
|
-
* A valid JSON array is defined as an array where all items are valid JSON values.
|
|
5
|
-
*
|
|
6
|
-
* @param {unknown} value - The value to check.
|
|
7
|
-
* @returns {value is any[]} - True if the value is a valid JSON array, otherwise false.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* console.log(isJSONArray([1, 2, 3])); // true
|
|
11
|
-
* console.log(isJSONArray(["string", null, true])); // true
|
|
12
|
-
* console.log(isJSONArray([1, 2, () => {}])); // false
|
|
13
|
-
* console.log(isJSONArray("not an array")); // false
|
|
14
|
-
*/
|
|
15
|
-
declare function isJSONArray(value: unknown): value is any[];
|
|
16
|
-
|
|
17
|
-
export { isJSONArray };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a value is a JSON object.
|
|
3
|
-
*
|
|
4
|
-
* A valid JSON object is defined as an object with string keys and valid JSON values.
|
|
5
|
-
*
|
|
6
|
-
* @param {unknown} obj The value to check.
|
|
7
|
-
* @returns {obj is Record<string, any>} True if `obj` is a JSON object, false otherwise.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* isJSONObject({ nested: { boolean: true, array: [1, 2, 3], string: 'test', null: null } }); // true
|
|
11
|
-
* isJSONObject({ regexp: /test/ }); // false
|
|
12
|
-
* isJSONObject(123); // false
|
|
13
|
-
*/
|
|
14
|
-
declare function isJSONObject(obj: unknown): obj is Record<string, any>;
|
|
15
|
-
|
|
16
|
-
export { isJSONObject };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a value is a JSON object.
|
|
3
|
-
*
|
|
4
|
-
* A valid JSON object is defined as an object with string keys and valid JSON values.
|
|
5
|
-
*
|
|
6
|
-
* @param {unknown} obj The value to check.
|
|
7
|
-
* @returns {obj is Record<string, any>} True if `obj` is a JSON object, false otherwise.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* isJSONObject({ nested: { boolean: true, array: [1, 2, 3], string: 'test', null: null } }); // true
|
|
11
|
-
* isJSONObject({ regexp: /test/ }); // false
|
|
12
|
-
* isJSONObject(123); // false
|
|
13
|
-
*/
|
|
14
|
-
declare function isJSONObject(obj: unknown): obj is Record<string, any>;
|
|
15
|
-
|
|
16
|
-
export { isJSONObject };
|