-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathis-object.js
40 lines (37 loc) · 1.37 KB
/
is-object.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// MOST Web Framework 2.0 Codename Blueshift BSD-3-Clause license Copyright (c) 2017-2022, THEMOST LP All rights reserved
var {isPlainObject, isObjectLike, isNative} = require('lodash');
var objectToString = Function.prototype.toString.call(Object);
function isObjectDeep(any) {
// check if it is a plain object
var result = isPlainObject(any);
if (result) {
return result;
}
// check if it's object
if (isObjectLike(any) === false) {
return false;
}
// get prototype
var proto = Object.getPrototypeOf(any);
// if prototype exists, try to validate prototype recursively
while(proto != null) {
// get constructor
var Ctor = Object.prototype.hasOwnProperty.call(proto, 'constructor')
&& proto.constructor;
// check if constructor is native object constructor
result = (typeof Ctor == 'function') && (Ctor instanceof Ctor)
&& Function.prototype.toString.call(Ctor) === objectToString;
// if constructor is not object constructor and belongs to a native class
if (result === false && isNative(Ctor) === true) {
// return false
return false;
}
// otherwise. get parent prototype and continue
proto = Object.getPrototypeOf(proto);
}
// finally, return result
return result;
}
module.exports = {
isObjectDeep
}