From e458b63653f9d70d7ae99a8c0e96287d06e8c72e Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 5 Jan 2024 19:20:39 +0100 Subject: [PATCH] refactor: make `isPlainObject` logic more readable --- src/_utils.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/_utils.ts b/src/_utils.ts index 52ac3ed..fd9f2f3 100644 --- a/src/_utils.ts +++ b/src/_utils.ts @@ -1,16 +1,22 @@ -// From sindresorhus/is-plain-obj -// MIT License +// Forked from sindresorhus/is-plain-obj (MIT) // Copyright (c) Sindre Sorhus (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; }