Skip to content

Commit acbe0f6

Browse files
committed
feat (theme): more concise isPlainObject function
1 parent 2da0c7c commit acbe0f6

File tree

1 file changed

+3
-33
lines changed

1 file changed

+3
-33
lines changed

src/js/utils/isPlainObject.js

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,9 @@
11
/*!
2-
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
2+
* isPlainObject <https://stackoverflow.com/questions/18531624/isplainobject-thing>
33
*
4-
* Copyright (c) 2014-2017, Jon Schlinkert.
5-
* Released under the MIT License.
4+
* Copyright https://stackoverflow.com/users/6023279/trunow.
65
*/
76

8-
function isObject(o) {
9-
return Object.prototype.toString.call(o) === '[object Object]'
10-
}
11-
127
export default function isPlainObject(o) {
13-
let ctor, prot
14-
15-
if (isObject(o) === false) {
16-
return false
17-
}
18-
19-
// If has modified constructor
20-
ctor = o.constructor
21-
if (ctor === undefined) {
22-
return true
23-
}
24-
25-
// If has modified prototype
26-
prot = ctor.prototype
27-
if (isObject(prot) === false) {
28-
return false
29-
}
30-
31-
// If constructor does not have an Object-specific method
32-
// eslint-disable-next-line no-prototype-builtins
33-
if (prot.hasOwnProperty('isPrototypeOf') === false) {
34-
return false
35-
}
36-
37-
// Most likely a plain Object
38-
return true
8+
return o?.constructor === Object || Object.getPrototypeOf(o ?? 0) === null
399
}

0 commit comments

Comments
 (0)