1d68332c04813e1758ebd6831cdde7cc112e71e6
[yaffs-website] / node_modules / grunt-legacy-log-utils / node_modules / lodash / isPlainObject.js
1 var isHostObject = require('./_isHostObject'),
2     isObjectLike = require('./isObjectLike');
3
4 /** `Object#toString` result references. */
5 var objectTag = '[object Object]';
6
7 /** Used for built-in method references. */
8 var objectProto = Object.prototype;
9
10 /** Used to resolve the decompiled source of functions. */
11 var funcToString = Function.prototype.toString;
12
13 /** Used to infer the `Object` constructor. */
14 var objectCtorString = funcToString.call(Object);
15
16 /**
17  * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
18  * of values.
19  */
20 var objectToString = objectProto.toString;
21
22 /** Built-in value references. */
23 var getPrototypeOf = Object.getPrototypeOf;
24
25 /**
26  * Checks if `value` is a plain object, that is, an object created by the
27  * `Object` constructor or one with a `[[Prototype]]` of `null`.
28  *
29  * @static
30  * @memberOf _
31  * @category Lang
32  * @param {*} value The value to check.
33  * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
34  * @example
35  *
36  * function Foo() {
37  *   this.a = 1;
38  * }
39  *
40  * _.isPlainObject(new Foo);
41  * // => false
42  *
43  * _.isPlainObject([1, 2, 3]);
44  * // => false
45  *
46  * _.isPlainObject({ 'x': 0, 'y': 0 });
47  * // => true
48  *
49  * _.isPlainObject(Object.create(null));
50  * // => true
51  */
52 function isPlainObject(value) {
53   if (!isObjectLike(value) || objectToString.call(value) != objectTag || isHostObject(value)) {
54     return false;
55   }
56   var proto = objectProto;
57   if (typeof value.constructor == 'function') {
58     proto = getPrototypeOf(value);
59   }
60   if (proto === null) {
61     return true;
62   }
63   var Ctor = proto.constructor;
64   return (typeof Ctor == 'function' &&
65     Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
66 }
67
68 module.exports = isPlainObject;