es-toolkit 1.24.0-dev.770 → 1.24.0-dev.773
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-DgrsU7.js → isPlainObject-DOleKH.js} +7 -13
- package/dist/_chunk/{isWeakSet-Bd6nry.js → isWeakSet-C2MqJE.js} +1 -1
- package/dist/_chunk/{toMerged-DDLv0D.js → toMerged-Bq5j0V.js} +1 -1
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/index.js +3 -3
- package/dist/index.js +3 -3
- package/dist/object/index.js +1 -1
- package/dist/predicate/index.js +2 -2
- package/dist/predicate/isPlainObject.d.mts +34 -5
- package/dist/predicate/isPlainObject.d.ts +34 -5
- package/dist/predicate/isPlainObject.mjs +7 -13
- package/package.json +1 -1
package/dist/compat/index.js
CHANGED
|
@@ -8,9 +8,9 @@ const unary = require('../_chunk/unary-BZ5Ixo.js');
|
|
|
8
8
|
const noop = require('../_chunk/noop-2IwLUk.js');
|
|
9
9
|
const sumBy = require('../_chunk/sumBy-BkErWJ.js');
|
|
10
10
|
const randomInt = require('../_chunk/randomInt-CF7bZK.js');
|
|
11
|
-
const toMerged = require('../_chunk/toMerged-
|
|
12
|
-
const isPlainObject$1 = require('../_chunk/isPlainObject-
|
|
13
|
-
const isWeakSet$1 = require('../_chunk/isWeakSet-
|
|
11
|
+
const toMerged = require('../_chunk/toMerged-Bq5j0V.js');
|
|
12
|
+
const isPlainObject$1 = require('../_chunk/isPlainObject-DOleKH.js');
|
|
13
|
+
const isWeakSet$1 = require('../_chunk/isWeakSet-C2MqJE.js');
|
|
14
14
|
const upperFirst = require('../_chunk/upperFirst-BUECmK.js');
|
|
15
15
|
|
|
16
16
|
function castArray(value) {
|
package/dist/index.js
CHANGED
|
@@ -11,11 +11,11 @@ const noop = require('./_chunk/noop-2IwLUk.js');
|
|
|
11
11
|
const sumBy = require('./_chunk/sumBy-BkErWJ.js');
|
|
12
12
|
const randomInt = require('./_chunk/randomInt-CF7bZK.js');
|
|
13
13
|
const math_index = require('./math/index.js');
|
|
14
|
-
const toMerged = require('./_chunk/toMerged-
|
|
14
|
+
const toMerged = require('./_chunk/toMerged-Bq5j0V.js');
|
|
15
15
|
const object_index = require('./object/index.js');
|
|
16
|
-
const isWeakSet = require('./_chunk/isWeakSet-
|
|
16
|
+
const isWeakSet = require('./_chunk/isWeakSet-C2MqJE.js');
|
|
17
17
|
const predicate_index = require('./predicate/index.js');
|
|
18
|
-
const isPlainObject = require('./_chunk/isPlainObject-
|
|
18
|
+
const isPlainObject = require('./_chunk/isPlainObject-DOleKH.js');
|
|
19
19
|
const upperFirst = require('./_chunk/upperFirst-BUECmK.js');
|
|
20
20
|
const string_index = require('./string/index.js');
|
|
21
21
|
|
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-Bq5j0V.js');
|
|
6
6
|
|
|
7
7
|
function mergeWith(target, source, merge) {
|
|
8
8
|
const sourceKeys = Object.keys(source);
|
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-C2MqJE.js');
|
|
6
|
+
const isPlainObject = require('../_chunk/isPlainObject-DOleKH.js');
|
|
7
7
|
|
|
8
8
|
function isBoolean(x) {
|
|
9
9
|
return typeof x === 'boolean';
|
|
@@ -5,11 +5,40 @@
|
|
|
5
5
|
* @returns {value is Record<PropertyKey, any>} - True if the value is a plain object, otherwise false.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // ✅👇 True
|
|
10
|
+
*
|
|
11
|
+
* isPlainObject({ }); // ✅
|
|
12
|
+
* isPlainObject({ key: 'value' }); // ✅
|
|
13
|
+
* isPlainObject({ key: new Date() }); // ✅
|
|
14
|
+
* isPlainObject(new Object()); // ✅
|
|
15
|
+
* isPlainObject(Object.create(null)); // ✅
|
|
16
|
+
* isPlainObject({ nested: { key: true} }); // ✅
|
|
17
|
+
* isPlainObject(new Proxy({}, {})); // ✅
|
|
18
|
+
* isPlainObject({ [Symbol('tag')]: 'A' }); // ✅
|
|
19
|
+
*
|
|
20
|
+
* // ✅👇 (cross-realms, node context, workers, ...)
|
|
21
|
+
* const runInNewContext = await import('node:vm').then(
|
|
22
|
+
* (mod) => mod.runInNewContext
|
|
23
|
+
* );
|
|
24
|
+
* isPlainObject(runInNewContext('({})')); // ✅
|
|
25
|
+
*
|
|
26
|
+
* // ❌👇 False
|
|
27
|
+
*
|
|
28
|
+
* class Test { };
|
|
29
|
+
* isPlainObject(new Test()) // ❌
|
|
30
|
+
* isPlainObject(10); // ❌
|
|
31
|
+
* isPlainObject(null); // ❌
|
|
32
|
+
* isPlainObject('hello'); // ❌
|
|
33
|
+
* isPlainObject([]); // ❌
|
|
34
|
+
* isPlainObject(new Date()); // ❌
|
|
35
|
+
* isPlainObject(new Uint8Array([1])); // ❌
|
|
36
|
+
* isPlainObject(Buffer.from('ABC')); // ❌
|
|
37
|
+
* isPlainObject(Promise.resolve({})); // ❌
|
|
38
|
+
* isPlainObject(Object.create({})); // ❌
|
|
39
|
+
* isPlainObject(new (class Cls {})); // ❌
|
|
40
|
+
* isPlainObject(globalThis); // ❌,
|
|
41
|
+
* ```
|
|
13
42
|
*/
|
|
14
43
|
declare function isPlainObject(value: unknown): value is Record<PropertyKey, any>;
|
|
15
44
|
|
|
@@ -5,11 +5,40 @@
|
|
|
5
5
|
* @returns {value is Record<PropertyKey, any>} - True if the value is a plain object, otherwise false.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // ✅👇 True
|
|
10
|
+
*
|
|
11
|
+
* isPlainObject({ }); // ✅
|
|
12
|
+
* isPlainObject({ key: 'value' }); // ✅
|
|
13
|
+
* isPlainObject({ key: new Date() }); // ✅
|
|
14
|
+
* isPlainObject(new Object()); // ✅
|
|
15
|
+
* isPlainObject(Object.create(null)); // ✅
|
|
16
|
+
* isPlainObject({ nested: { key: true} }); // ✅
|
|
17
|
+
* isPlainObject(new Proxy({}, {})); // ✅
|
|
18
|
+
* isPlainObject({ [Symbol('tag')]: 'A' }); // ✅
|
|
19
|
+
*
|
|
20
|
+
* // ✅👇 (cross-realms, node context, workers, ...)
|
|
21
|
+
* const runInNewContext = await import('node:vm').then(
|
|
22
|
+
* (mod) => mod.runInNewContext
|
|
23
|
+
* );
|
|
24
|
+
* isPlainObject(runInNewContext('({})')); // ✅
|
|
25
|
+
*
|
|
26
|
+
* // ❌👇 False
|
|
27
|
+
*
|
|
28
|
+
* class Test { };
|
|
29
|
+
* isPlainObject(new Test()) // ❌
|
|
30
|
+
* isPlainObject(10); // ❌
|
|
31
|
+
* isPlainObject(null); // ❌
|
|
32
|
+
* isPlainObject('hello'); // ❌
|
|
33
|
+
* isPlainObject([]); // ❌
|
|
34
|
+
* isPlainObject(new Date()); // ❌
|
|
35
|
+
* isPlainObject(new Uint8Array([1])); // ❌
|
|
36
|
+
* isPlainObject(Buffer.from('ABC')); // ❌
|
|
37
|
+
* isPlainObject(Promise.resolve({})); // ❌
|
|
38
|
+
* isPlainObject(Object.create({})); // ❌
|
|
39
|
+
* isPlainObject(new (class Cls {})); // ❌
|
|
40
|
+
* isPlainObject(globalThis); // ❌,
|
|
41
|
+
* ```
|
|
13
42
|
*/
|
|
14
43
|
declare function isPlainObject(value: unknown): value is Record<PropertyKey, any>;
|
|
15
44
|
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
function isPlainObject(value) {
|
|
2
|
-
if (typeof value !== 'object') {
|
|
2
|
+
if (!value || typeof value !== 'object') {
|
|
3
3
|
return false;
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
const proto = Object.getPrototypeOf(value);
|
|
6
|
+
const hasObjectPrototype = proto === null ||
|
|
7
|
+
proto === Object.prototype ||
|
|
8
|
+
Object.getPrototypeOf(proto) === null;
|
|
9
|
+
if (!hasObjectPrototype) {
|
|
6
10
|
return false;
|
|
7
11
|
}
|
|
8
|
-
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
if (value.toString() !== '[object Object]') {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
let proto = value;
|
|
15
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
16
|
-
proto = Object.getPrototypeOf(proto);
|
|
17
|
-
}
|
|
18
|
-
return Object.getPrototypeOf(value) === proto;
|
|
12
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
|
19
13
|
}
|
|
20
14
|
|
|
21
15
|
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.24.0-dev.
|
|
4
|
+
"version": "1.24.0-dev.773+27403452",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|