Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/isPlainObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
* @returns {boolean} True if the argument appears to be a plain object.
*/
export default function isPlainObject(value: unknown): value is object {
if (typeof value !== 'object' || value === null) return false

let proto = value
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto)
}

return Object.getPrototypeOf(value) === proto
return (
typeof value === 'object' &&
value !== null &&
Object.getPrototypeOf(Object.getPrototypeOf(value) || 0) === null
Copy link
Author

@WebReflection WebReflection May 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P.S. the 0 could be just a literal {} instead, it'd work exactly the same (but it'd be 1 extra char).

)
}