-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make
isPlainObject
logic more readable
- Loading branch information
Showing
1 changed file
with
15 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
// From sindresorhus/is-plain-obj | ||
// MIT License | ||
// Forked from sindresorhus/is-plain-obj (MIT) | ||
// Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com) | ||
export function isPlainObject(value: unknown): boolean { | ||
if (value === null || typeof value !== "object") { | ||
return false; | ||
} | ||
const prototype = Object.getPrototypeOf(value); | ||
return ( | ||
(prototype === null || | ||
prototype === Object.prototype || | ||
Object.getPrototypeOf(prototype) === null) && | ||
!(Symbol.toStringTag in value) && | ||
!(Symbol.iterator in value) | ||
); | ||
|
||
if ( | ||
prototype !== null && | ||
prototype !== Object.prototype && | ||
Object.getPrototypeOf(prototype) !== null | ||
) { | ||
return false; | ||
} | ||
|
||
if (Symbol.toStringTag in value || Symbol.iterator in value) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |