Skip to content

Commit e458b63

Browse files
committedJan 5, 2024
refactor: make isPlainObject logic more readable
1 parent e5a48d3 commit e458b63

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed
 

‎src/_utils.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
// From sindresorhus/is-plain-obj
2-
// MIT License
1+
// Forked from sindresorhus/is-plain-obj (MIT)
32
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
43
export function isPlainObject(value: unknown): boolean {
54
if (value === null || typeof value !== "object") {
65
return false;
76
}
87
const prototype = Object.getPrototypeOf(value);
9-
return (
10-
(prototype === null ||
11-
prototype === Object.prototype ||
12-
Object.getPrototypeOf(prototype) === null) &&
13-
!(Symbol.toStringTag in value) &&
14-
!(Symbol.iterator in value)
15-
);
8+
9+
if (
10+
prototype !== null &&
11+
prototype !== Object.prototype &&
12+
Object.getPrototypeOf(prototype) !== null
13+
) {
14+
return false;
15+
}
16+
17+
if (Symbol.toStringTag in value || Symbol.iterator in value) {
18+
return false;
19+
}
20+
21+
return true;
1622
}

0 commit comments

Comments
 (0)