Skip to content

Commit

Permalink
refactor: make isPlainObject logic more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jan 5, 2024
1 parent e5a48d3 commit e458b63
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions 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 <sindresorhus@gmail.com> (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;
}

0 comments on commit e458b63

Please sign in to comment.