es-toolkit 1.22.0-dev.695 → 1.22.0-dev.697
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/{isPlainObject-BIekvL.js → isPlainObject-DKBeLp.js} +7 -7
- package/dist/_chunk/{isWeakSet-clQklw.js → isWeakSet-DDVaWr.js} +46 -2
- package/dist/_chunk/{toMerged-2WPeoI.js → toMerged-DD-s3X.js} +3 -3
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/index.d.mts +3 -0
- package/dist/compat/index.d.ts +3 -0
- package/dist/compat/index.js +8 -5
- package/dist/compat/index.mjs +3 -0
- package/dist/compat/object/has.mjs +1 -1
- package/dist/compat/object/pick.mjs +1 -1
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -3
- package/dist/index.mjs +3 -0
- package/dist/object/cloneDeep.mjs +2 -2
- package/dist/object/index.js +2 -2
- package/dist/object/pick.mjs +1 -1
- package/dist/predicate/index.d.mts +3 -0
- package/dist/predicate/index.d.ts +3 -0
- package/dist/predicate/index.js +5 -2
- package/dist/predicate/index.mjs +3 -0
- package/dist/predicate/isEqual.mjs +1 -1
- package/dist/predicate/isJSONArray.d.mts +17 -0
- package/dist/predicate/isJSONArray.d.ts +17 -0
- package/dist/predicate/isJSONArray.mjs +10 -0
- package/dist/predicate/isJSONObject.d.mts +16 -0
- package/dist/predicate/isJSONObject.d.ts +16 -0
- package/dist/predicate/isJSONObject.mjs +22 -0
- package/dist/predicate/isJSONValue.d.mts +27 -0
- package/dist/predicate/isJSONValue.d.ts +27 -0
- package/dist/predicate/isJSONValue.mjs +20 -0
- package/dist/predicate/isPlainObject.d.mts +3 -3
- package/dist/predicate/isPlainObject.d.ts +3 -3
- package/dist/predicate/isPlainObject.mjs +7 -7
- package/package.json +1 -1
package/dist/compat/index.d.mts
CHANGED
|
@@ -79,6 +79,9 @@ export { isUndefined } from '../predicate/isUndefined.mjs';
|
|
|
79
79
|
export { isLength } from '../predicate/isLength.mjs';
|
|
80
80
|
export { isFunction } from '../predicate/isFunction.mjs';
|
|
81
81
|
export { isPrimitive } from '../predicate/isPrimitive.mjs';
|
|
82
|
+
export { isJSONObject } from '../predicate/isJSONObject.mjs';
|
|
83
|
+
export { isJSONValue } from '../predicate/isJSONValue.mjs';
|
|
84
|
+
export { isJSONArray } from '../predicate/isJSONArray.mjs';
|
|
82
85
|
export { isSet } from '../predicate/isSet.mjs';
|
|
83
86
|
export { delay } from '../promise/delay.mjs';
|
|
84
87
|
export { withTimeout } from '../promise/withTimeout.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -79,6 +79,9 @@ export { isUndefined } from '../predicate/isUndefined.js';
|
|
|
79
79
|
export { isLength } from '../predicate/isLength.js';
|
|
80
80
|
export { isFunction } from '../predicate/isFunction.js';
|
|
81
81
|
export { isPrimitive } from '../predicate/isPrimitive.js';
|
|
82
|
+
export { isJSONObject } from '../predicate/isJSONObject.js';
|
|
83
|
+
export { isJSONValue } from '../predicate/isJSONValue.js';
|
|
84
|
+
export { isJSONArray } from '../predicate/isJSONArray.js';
|
|
82
85
|
export { isSet } from '../predicate/isSet.js';
|
|
83
86
|
export { delay } from '../promise/delay.js';
|
|
84
87
|
export { withTimeout } from '../promise/withTimeout.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -7,9 +7,9 @@ const promise_index = require('../_chunk/index-BGZDR9.js');
|
|
|
7
7
|
const flowRight = require('../_chunk/flowRight-BzdOZX.js');
|
|
8
8
|
const range = require('../_chunk/range-BXlMmn.js');
|
|
9
9
|
const randomInt = require('../_chunk/randomInt-CF7bZK.js');
|
|
10
|
-
const toMerged = require('../_chunk/toMerged-
|
|
11
|
-
const isPlainObject$1 = require('../_chunk/isPlainObject-
|
|
12
|
-
const isWeakSet$1 = require('../_chunk/isWeakSet-
|
|
10
|
+
const toMerged = require('../_chunk/toMerged-DD-s3X.js');
|
|
11
|
+
const isPlainObject$1 = require('../_chunk/isPlainObject-DKBeLp.js');
|
|
12
|
+
const isWeakSet$1 = require('../_chunk/isWeakSet-DDVaWr.js');
|
|
13
13
|
const pad$1 = require('../_chunk/pad-Cw2pvt.js');
|
|
14
14
|
|
|
15
15
|
function castArray(value) {
|
|
@@ -338,7 +338,7 @@ function has(object, path) {
|
|
|
338
338
|
let current = object;
|
|
339
339
|
for (let i = 0; i < resolvedPath.length; i++) {
|
|
340
340
|
const key = resolvedPath[i];
|
|
341
|
-
if (current == null || !Object.
|
|
341
|
+
if (current == null || !Object.hasOwn(current, key)) {
|
|
342
342
|
const isSparseIndex = (Array.isArray(current) || isArguments(current)) && isIndex(key) && key < current.length;
|
|
343
343
|
if (!isSparseIndex) {
|
|
344
344
|
return false;
|
|
@@ -1152,7 +1152,7 @@ function pick(obj, ...keysArr) {
|
|
|
1152
1152
|
}
|
|
1153
1153
|
for (const key of keys) {
|
|
1154
1154
|
const value = get(obj, key);
|
|
1155
|
-
if (typeof key === 'string' && Object.
|
|
1155
|
+
if (typeof key === 'string' && Object.hasOwn(obj, key)) {
|
|
1156
1156
|
result[key] = value;
|
|
1157
1157
|
}
|
|
1158
1158
|
else {
|
|
@@ -1873,6 +1873,9 @@ exports.isPrimitive = isPlainObject$1.isPrimitive;
|
|
|
1873
1873
|
exports.isDate = isWeakSet$1.isDate;
|
|
1874
1874
|
exports.isEqual = isWeakSet$1.isEqual;
|
|
1875
1875
|
exports.isFunction = isWeakSet$1.isFunction;
|
|
1876
|
+
exports.isJSONArray = isWeakSet$1.isJSONArray;
|
|
1877
|
+
exports.isJSONObject = isWeakSet$1.isJSONObject;
|
|
1878
|
+
exports.isJSONValue = isWeakSet$1.isJSONValue;
|
|
1876
1879
|
exports.isLength = isWeakSet$1.isLength;
|
|
1877
1880
|
exports.isMap = isWeakSet$1.isMap;
|
|
1878
1881
|
exports.isNotNil = isWeakSet$1.isNotNil;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -80,6 +80,9 @@ export { isNull } from '../predicate/isNull.mjs';
|
|
|
80
80
|
export { isUndefined } from '../predicate/isUndefined.mjs';
|
|
81
81
|
export { isLength } from '../predicate/isLength.mjs';
|
|
82
82
|
export { isFunction } from '../predicate/isFunction.mjs';
|
|
83
|
+
export { isJSONObject } from '../predicate/isJSONObject.mjs';
|
|
84
|
+
export { isJSONValue } from '../predicate/isJSONValue.mjs';
|
|
85
|
+
export { isJSONArray } from '../predicate/isJSONArray.mjs';
|
|
83
86
|
export { isSet } from '../predicate/isSet.mjs';
|
|
84
87
|
export { delay } from '../promise/delay.mjs';
|
|
85
88
|
export { withTimeout } from '../promise/withTimeout.mjs';
|
|
@@ -20,7 +20,7 @@ function has(object, path) {
|
|
|
20
20
|
let current = object;
|
|
21
21
|
for (let i = 0; i < resolvedPath.length; i++) {
|
|
22
22
|
const key = resolvedPath[i];
|
|
23
|
-
if (current == null || !Object.
|
|
23
|
+
if (current == null || !Object.hasOwn(current, key)) {
|
|
24
24
|
const isSparseIndex = (Array.isArray(current) || isArguments(current)) && isIndex(key) && key < current.length;
|
|
25
25
|
if (!isSparseIndex) {
|
|
26
26
|
return false;
|
|
@@ -25,7 +25,7 @@ function pick(obj, ...keysArr) {
|
|
|
25
25
|
}
|
|
26
26
|
for (const key of keys) {
|
|
27
27
|
const value = get(obj, key);
|
|
28
|
-
if (typeof key === 'string' && Object.
|
|
28
|
+
if (typeof key === 'string' && Object.hasOwn(obj, key)) {
|
|
29
29
|
result[key] = value;
|
|
30
30
|
}
|
|
31
31
|
else {
|
package/dist/index.d.mts
CHANGED
|
@@ -113,6 +113,9 @@ export { isRegExp } from './predicate/isRegExp.mjs';
|
|
|
113
113
|
export { isBoolean } from './predicate/isBoolean.mjs';
|
|
114
114
|
export { isSymbol } from './predicate/isSymbol.mjs';
|
|
115
115
|
export { isString } from './predicate/isString.mjs';
|
|
116
|
+
export { isJSONObject } from './predicate/isJSONObject.mjs';
|
|
117
|
+
export { isJSONValue } from './predicate/isJSONValue.mjs';
|
|
118
|
+
export { isJSONArray } from './predicate/isJSONArray.mjs';
|
|
116
119
|
export { isSet } from './predicate/isSet.mjs';
|
|
117
120
|
export { isWeakMap } from './predicate/isWeakMap.mjs';
|
|
118
121
|
export { isWeakSet } from './predicate/isWeakSet.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -113,6 +113,9 @@ export { isRegExp } from './predicate/isRegExp.js';
|
|
|
113
113
|
export { isBoolean } from './predicate/isBoolean.js';
|
|
114
114
|
export { isSymbol } from './predicate/isSymbol.js';
|
|
115
115
|
export { isString } from './predicate/isString.js';
|
|
116
|
+
export { isJSONObject } from './predicate/isJSONObject.js';
|
|
117
|
+
export { isJSONValue } from './predicate/isJSONValue.js';
|
|
118
|
+
export { isJSONArray } from './predicate/isJSONArray.js';
|
|
116
119
|
export { isSet } from './predicate/isSet.js';
|
|
117
120
|
export { isWeakMap } from './predicate/isWeakMap.js';
|
|
118
121
|
export { isWeakSet } from './predicate/isWeakSet.js';
|
package/dist/index.js
CHANGED
|
@@ -11,10 +11,10 @@ const range = require('./_chunk/range-BXlMmn.js');
|
|
|
11
11
|
const randomInt = require('./_chunk/randomInt-CF7bZK.js');
|
|
12
12
|
const math_index = require('./math/index.js');
|
|
13
13
|
const object_index = require('./object/index.js');
|
|
14
|
-
const toMerged = require('./_chunk/toMerged-
|
|
15
|
-
const isWeakSet = require('./_chunk/isWeakSet-
|
|
14
|
+
const toMerged = require('./_chunk/toMerged-DD-s3X.js');
|
|
15
|
+
const isWeakSet = require('./_chunk/isWeakSet-DDVaWr.js');
|
|
16
16
|
const predicate_index = require('./predicate/index.js');
|
|
17
|
-
const isPlainObject = require('./_chunk/isPlainObject-
|
|
17
|
+
const isPlainObject = require('./_chunk/isPlainObject-DKBeLp.js');
|
|
18
18
|
const pad = require('./_chunk/pad-Cw2pvt.js');
|
|
19
19
|
const string_index = require('./string/index.js');
|
|
20
20
|
|
|
@@ -124,6 +124,9 @@ exports.toMerged = toMerged.toMerged;
|
|
|
124
124
|
exports.isDate = isWeakSet.isDate;
|
|
125
125
|
exports.isEqual = isWeakSet.isEqual;
|
|
126
126
|
exports.isFunction = isWeakSet.isFunction;
|
|
127
|
+
exports.isJSONArray = isWeakSet.isJSONArray;
|
|
128
|
+
exports.isJSONObject = isWeakSet.isJSONObject;
|
|
129
|
+
exports.isJSONValue = isWeakSet.isJSONValue;
|
|
127
130
|
exports.isLength = isWeakSet.isLength;
|
|
128
131
|
exports.isMap = isWeakSet.isMap;
|
|
129
132
|
exports.isNil = isWeakSet.isNil;
|
package/dist/index.mjs
CHANGED
|
@@ -113,6 +113,9 @@ export { isRegExp } from './predicate/isRegExp.mjs';
|
|
|
113
113
|
export { isBoolean } from './predicate/isBoolean.mjs';
|
|
114
114
|
export { isSymbol } from './predicate/isSymbol.mjs';
|
|
115
115
|
export { isString } from './predicate/isString.mjs';
|
|
116
|
+
export { isJSONObject } from './predicate/isJSONObject.mjs';
|
|
117
|
+
export { isJSONValue } from './predicate/isJSONValue.mjs';
|
|
118
|
+
export { isJSONArray } from './predicate/isJSONArray.mjs';
|
|
116
119
|
export { isSet } from './predicate/isSet.mjs';
|
|
117
120
|
export { isWeakMap } from './predicate/isWeakMap.mjs';
|
|
118
121
|
export { isWeakSet } from './predicate/isWeakSet.mjs';
|
|
@@ -17,10 +17,10 @@ function cloneDeepImpl(obj, stack = new Map()) {
|
|
|
17
17
|
for (let i = 0; i < obj.length; i++) {
|
|
18
18
|
result[i] = cloneDeepImpl(obj[i], stack);
|
|
19
19
|
}
|
|
20
|
-
if (Object.
|
|
20
|
+
if (Object.hasOwn(obj, 'index')) {
|
|
21
21
|
result.index = obj.index;
|
|
22
22
|
}
|
|
23
|
-
if (Object.
|
|
23
|
+
if (Object.hasOwn(obj, 'input')) {
|
|
24
24
|
result.input = obj.input;
|
|
25
25
|
}
|
|
26
26
|
return result;
|
package/dist/object/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const toMerged = require('../_chunk/toMerged-
|
|
5
|
+
const toMerged = require('../_chunk/toMerged-DD-s3X.js');
|
|
6
6
|
|
|
7
7
|
function omit(obj, keys) {
|
|
8
8
|
const result = { ...obj };
|
|
@@ -17,7 +17,7 @@ function pick(obj, keys) {
|
|
|
17
17
|
const result = {};
|
|
18
18
|
for (let i = 0; i < keys.length; i++) {
|
|
19
19
|
const key = keys[i];
|
|
20
|
-
if (Object.
|
|
20
|
+
if (Object.hasOwn(obj, key)) {
|
|
21
21
|
result[key] = obj[key];
|
|
22
22
|
}
|
|
23
23
|
}
|
package/dist/object/pick.mjs
CHANGED
|
@@ -15,6 +15,9 @@ export { isRegExp } from './isRegExp.mjs';
|
|
|
15
15
|
export { isBoolean } from './isBoolean.mjs';
|
|
16
16
|
export { isSymbol } from './isSymbol.mjs';
|
|
17
17
|
export { isString } from './isString.mjs';
|
|
18
|
+
export { isJSONObject } from './isJSONObject.mjs';
|
|
19
|
+
export { isJSONValue } from './isJSONValue.mjs';
|
|
20
|
+
export { isJSONArray } from './isJSONArray.mjs';
|
|
18
21
|
export { isSet } from './isSet.mjs';
|
|
19
22
|
export { isWeakMap } from './isWeakMap.mjs';
|
|
20
23
|
export { isWeakSet } from './isWeakSet.mjs';
|
|
@@ -15,6 +15,9 @@ export { isRegExp } from './isRegExp.js';
|
|
|
15
15
|
export { isBoolean } from './isBoolean.js';
|
|
16
16
|
export { isSymbol } from './isSymbol.js';
|
|
17
17
|
export { isString } from './isString.js';
|
|
18
|
+
export { isJSONObject } from './isJSONObject.js';
|
|
19
|
+
export { isJSONValue } from './isJSONValue.js';
|
|
20
|
+
export { isJSONArray } from './isJSONArray.js';
|
|
18
21
|
export { isSet } from './isSet.js';
|
|
19
22
|
export { isWeakMap } from './isWeakMap.js';
|
|
20
23
|
export { isWeakSet } from './isWeakSet.js';
|
package/dist/predicate/index.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const isWeakSet = require('../_chunk/isWeakSet-
|
|
6
|
-
const isPlainObject = require('../_chunk/isPlainObject-
|
|
5
|
+
const isWeakSet = require('../_chunk/isWeakSet-DDVaWr.js');
|
|
6
|
+
const isPlainObject = require('../_chunk/isPlainObject-DKBeLp.js');
|
|
7
7
|
|
|
8
8
|
function isError(value) {
|
|
9
9
|
return value instanceof Error;
|
|
@@ -24,6 +24,9 @@ function isString(value) {
|
|
|
24
24
|
exports.isDate = isWeakSet.isDate;
|
|
25
25
|
exports.isEqual = isWeakSet.isEqual;
|
|
26
26
|
exports.isFunction = isWeakSet.isFunction;
|
|
27
|
+
exports.isJSONArray = isWeakSet.isJSONArray;
|
|
28
|
+
exports.isJSONObject = isWeakSet.isJSONObject;
|
|
29
|
+
exports.isJSONValue = isWeakSet.isJSONValue;
|
|
27
30
|
exports.isLength = isWeakSet.isLength;
|
|
28
31
|
exports.isMap = isWeakSet.isMap;
|
|
29
32
|
exports.isNil = isWeakSet.isNil;
|
package/dist/predicate/index.mjs
CHANGED
|
@@ -15,6 +15,9 @@ export { isRegExp } from './isRegExp.mjs';
|
|
|
15
15
|
export { isBoolean } from './isBoolean.mjs';
|
|
16
16
|
export { isSymbol } from './isSymbol.mjs';
|
|
17
17
|
export { isString } from './isString.mjs';
|
|
18
|
+
export { isJSONObject } from './isJSONObject.mjs';
|
|
19
|
+
export { isJSONValue } from './isJSONValue.mjs';
|
|
20
|
+
export { isJSONArray } from './isJSONArray.mjs';
|
|
18
21
|
export { isSet } from './isSet.mjs';
|
|
19
22
|
export { isWeakMap } from './isWeakMap.mjs';
|
|
20
23
|
export { isWeakSet } from './isWeakSet.mjs';
|
|
@@ -152,7 +152,7 @@ function areObjectsEqual(a, b, stack) {
|
|
|
152
152
|
for (let i = 0; i < aKeys.length; i++) {
|
|
153
153
|
const propKey = aKeys[i];
|
|
154
154
|
const aProp = a[propKey];
|
|
155
|
-
if (!Object.
|
|
155
|
+
if (!Object.hasOwn(b, propKey)) {
|
|
156
156
|
return false;
|
|
157
157
|
}
|
|
158
158
|
const bProp = b[propKey];
|
|
@@ -0,0 +1,17 @@
|
|
|
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 };
|
|
@@ -0,0 +1,17 @@
|
|
|
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 };
|
|
@@ -0,0 +1,16 @@
|
|
|
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 };
|
|
@@ -0,0 +1,16 @@
|
|
|
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 };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isJSONValue } from './isJSONValue.mjs';
|
|
2
|
+
import { isPlainObject } from './isPlainObject.mjs';
|
|
3
|
+
|
|
4
|
+
function isJSONObject(obj) {
|
|
5
|
+
if (!isPlainObject(obj)) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
const keys = Reflect.ownKeys(obj);
|
|
9
|
+
for (let i = 0; i < keys.length; i++) {
|
|
10
|
+
const key = keys[i];
|
|
11
|
+
const value = obj[key];
|
|
12
|
+
if (typeof key !== 'string') {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (!isJSONValue(value)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { isJSONObject };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given value is a valid JSON value.
|
|
3
|
+
*
|
|
4
|
+
* A valid JSON value can be:
|
|
5
|
+
* - null
|
|
6
|
+
* - a JSON object (an object with string keys and valid JSON values)
|
|
7
|
+
* - a JSON array (an array of valid JSON values)
|
|
8
|
+
* - a string
|
|
9
|
+
* - a number
|
|
10
|
+
* - a boolean
|
|
11
|
+
*
|
|
12
|
+
* @param {unknown} value - The value to check.
|
|
13
|
+
* @returns {boolean} - True if the value is a valid JSON value, otherwise false.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* console.log(isJSONValue(null)); // true
|
|
17
|
+
* console.log(isJSONValue({ key: "value" })); // true
|
|
18
|
+
* console.log(isJSONValue([1, 2, 3])); // true
|
|
19
|
+
* console.log(isJSONValue("Hello")); // true
|
|
20
|
+
* console.log(isJSONValue(42)); // true
|
|
21
|
+
* console.log(isJSONValue(true)); // true
|
|
22
|
+
* console.log(isJSONValue(undefined)); // false
|
|
23
|
+
* console.log(isJSONValue(() => {})); // false
|
|
24
|
+
*/
|
|
25
|
+
declare function isJSONValue(value: unknown): value is Record<string, any> | any[] | string | number | boolean | null;
|
|
26
|
+
|
|
27
|
+
export { isJSONValue };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given value is a valid JSON value.
|
|
3
|
+
*
|
|
4
|
+
* A valid JSON value can be:
|
|
5
|
+
* - null
|
|
6
|
+
* - a JSON object (an object with string keys and valid JSON values)
|
|
7
|
+
* - a JSON array (an array of valid JSON values)
|
|
8
|
+
* - a string
|
|
9
|
+
* - a number
|
|
10
|
+
* - a boolean
|
|
11
|
+
*
|
|
12
|
+
* @param {unknown} value - The value to check.
|
|
13
|
+
* @returns {boolean} - True if the value is a valid JSON value, otherwise false.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* console.log(isJSONValue(null)); // true
|
|
17
|
+
* console.log(isJSONValue({ key: "value" })); // true
|
|
18
|
+
* console.log(isJSONValue([1, 2, 3])); // true
|
|
19
|
+
* console.log(isJSONValue("Hello")); // true
|
|
20
|
+
* console.log(isJSONValue(42)); // true
|
|
21
|
+
* console.log(isJSONValue(true)); // true
|
|
22
|
+
* console.log(isJSONValue(undefined)); // false
|
|
23
|
+
* console.log(isJSONValue(() => {})); // false
|
|
24
|
+
*/
|
|
25
|
+
declare function isJSONValue(value: unknown): value is Record<string, any> | any[] | string | number | boolean | null;
|
|
26
|
+
|
|
27
|
+
export { isJSONValue };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isJSONArray } from './isJSONArray.mjs';
|
|
2
|
+
import { isJSONObject } from './isJSONObject.mjs';
|
|
3
|
+
|
|
4
|
+
function isJSONValue(value) {
|
|
5
|
+
switch (typeof value) {
|
|
6
|
+
case 'object': {
|
|
7
|
+
return value === null || isJSONArray(value) || isJSONObject(value);
|
|
8
|
+
}
|
|
9
|
+
case 'string':
|
|
10
|
+
case 'number':
|
|
11
|
+
case 'boolean': {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
default: {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { isJSONValue };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Checks if a given value is a plain object.
|
|
3
3
|
*
|
|
4
|
-
* @param {object}
|
|
5
|
-
* @returns {
|
|
4
|
+
* @param {object} value - The value to check.
|
|
5
|
+
* @returns {value is Record<PropertyKey, any>} - True if the value is a plain object, otherwise false.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* console.log(isPlainObject({})); // true
|
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
* console.log(isPlainObject(Object.create(null))); // true
|
|
12
12
|
* console.log(Buffer.from('hello, world')); // false
|
|
13
13
|
*/
|
|
14
|
-
declare function isPlainObject(
|
|
14
|
+
declare function isPlainObject(value: unknown): value is Record<PropertyKey, any>;
|
|
15
15
|
|
|
16
16
|
export { isPlainObject };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Checks if a given value is a plain object.
|
|
3
3
|
*
|
|
4
|
-
* @param {object}
|
|
5
|
-
* @returns {
|
|
4
|
+
* @param {object} value - The value to check.
|
|
5
|
+
* @returns {value is Record<PropertyKey, any>} - True if the value is a plain object, otherwise false.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* console.log(isPlainObject({})); // true
|
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
* console.log(isPlainObject(Object.create(null))); // true
|
|
12
12
|
* console.log(Buffer.from('hello, world')); // false
|
|
13
13
|
*/
|
|
14
|
-
declare function isPlainObject(
|
|
14
|
+
declare function isPlainObject(value: unknown): value is Record<PropertyKey, any>;
|
|
15
15
|
|
|
16
16
|
export { isPlainObject };
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
function isPlainObject(
|
|
2
|
-
if (typeof
|
|
1
|
+
function isPlainObject(value) {
|
|
2
|
+
if (typeof value !== 'object') {
|
|
3
3
|
return false;
|
|
4
4
|
}
|
|
5
|
-
if (
|
|
5
|
+
if (value == null) {
|
|
6
6
|
return false;
|
|
7
7
|
}
|
|
8
|
-
if (Object.getPrototypeOf(
|
|
8
|
+
if (Object.getPrototypeOf(value) === null) {
|
|
9
9
|
return true;
|
|
10
10
|
}
|
|
11
|
-
if (
|
|
11
|
+
if (value.toString() !== '[object Object]') {
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
|
-
let proto =
|
|
14
|
+
let proto = value;
|
|
15
15
|
while (Object.getPrototypeOf(proto) !== null) {
|
|
16
16
|
proto = Object.getPrototypeOf(proto);
|
|
17
17
|
}
|
|
18
|
-
return Object.getPrototypeOf(
|
|
18
|
+
return Object.getPrototypeOf(value) === proto;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export { isPlainObject };
|
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.22.0-dev.
|
|
4
|
+
"version": "1.22.0-dev.697+ded56755",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|