is-plain-obj
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -9,2 +9,3 @@ /** | ||
import isPlainObject from 'is-plain-obj'; | ||
import {runInNewContext} from 'node:vm'; | ||
@@ -20,2 +21,6 @@ isPlainObject({foo: 'bar'}); | ||
// This works across realms | ||
isPlainObject(runInNewContext('({})')); | ||
//=> true | ||
isPlainObject([1, 2, 3]); | ||
@@ -27,4 +32,7 @@ //=> false | ||
//=> false | ||
isPlainObject(Math); | ||
//=> false | ||
``` | ||
*/ | ||
export default function isPlainObject<Value>(value: unknown): value is Record<string | number | symbol, Value>; | ||
export default function isPlainObject<Value>(value: unknown): value is Record<PropertyKey, Value>; |
export default function isPlainObject(value) { | ||
if (Object.prototype.toString.call(value) !== '[object Object]') { | ||
if (typeof value !== 'object' || value === null) { | ||
return false; | ||
@@ -7,3 +7,3 @@ } | ||
const prototype = Object.getPrototypeOf(value); | ||
return prototype === null || prototype === Object.prototype; | ||
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value); | ||
} |
{ | ||
"name": "is-plain-obj", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Check if a value is a plain object", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -17,2 +17,3 @@ # is-plain-obj | ||
import isPlainObject from 'is-plain-obj'; | ||
import {runInNewContext} from 'node:vm'; | ||
@@ -28,2 +29,6 @@ isPlainObject({foo: 'bar'}); | ||
// This works across realms | ||
isPlainObject(runInNewContext('({})')); | ||
//=> true | ||
isPlainObject([1, 2, 3]); | ||
@@ -35,2 +40,5 @@ //=> false | ||
//=> false | ||
isPlainObject(Math); | ||
//=> false | ||
``` | ||
@@ -37,0 +45,0 @@ |
4080
33
59