From 45cae31f4d7311d8ae1250558e710594acff7d01 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Tue, 21 Jun 2022 14:05:40 +0200 Subject: [PATCH] Improve `plainObject()` (#169) --- source/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/index.ts b/source/index.ts index 4a3df85..3e68b19 100644 --- a/source/index.ts +++ b/source/index.ts @@ -286,14 +286,14 @@ is.safeInteger = (value: unknown): value is number => Number.isSafeInteger(value is.plainObject = (value: unknown): value is Record => { // From: https://github.com/sindresorhus/is-plain-obj/blob/main/index.js - if (toString.call(value) !== '[object Object]') { + if (typeof value !== 'object' || value === null) { return false; } // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const prototype = Object.getPrototypeOf(value); - return prototype === null || prototype === Object.getPrototypeOf({}); + return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value); }; is.typedArray = (value: unknown): value is TypedArray => isTypedArrayName(getObjectType(value));