Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var getNative = require('../internal/getNative'),
2
shimIsPlainObject = require('../internal/shimIsPlainObject');
3
4
/** `Object#toString` result references. */
5
var objectTag = '[object Object]';
6
7
/** Used for native method references. */
8
var objectProto = Object.prototype;
9
10
/**
11
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
12
* of values.
13
*/
14
var objToString = objectProto.toString;
15
16
/** Native method references. */
17
var getPrototypeOf = getNative(Object, 'getPrototypeOf');
18
19
/**
20
* Checks if `value` is a plain object, that is, an object created by the
21
* `Object` constructor or one with a `[[Prototype]]` of `null`.
22
*
23
* **Note:** This method assumes objects created by the `Object` constructor
24
* have no inherited enumerable properties.
25
*
26
* @static
27
* @memberOf _
28
* @category Lang
29
* @param {*} value The value to check.
30
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
31
* @example
32
*
33
* function Foo() {
34
* this.a = 1;
35
* }
36
*
37
* _.isPlainObject(new Foo);
38
* // => false
39
*
40
* _.isPlainObject([1, 2, 3]);
41
* // => false
42
*
43
* _.isPlainObject({ 'x': 0, 'y': 0 });
44
* // => true
45
*
46
* _.isPlainObject(Object.create(null));
47
* // => true
48
*/
49
var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) {
50
if (!(value && objToString.call(value) == objectTag)) {
51
return false;
52
}
53
var valueOf = getNative(value, 'valueOf'),
54
objProto = valueOf && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
55
56
return objProto
57
? (value == objProto || getPrototypeOf(value) == objProto)
58
: shimIsPlainObject(value);
59
};
60
61
module.exports = isPlainObject;
62
63