2 * lodash (Custom Build) <https://lodash.com/>
3 * Build: `lodash modularize exports="npm" -o ./`
4 * Copyright jQuery Foundation and other contributors <https://jquery.org/>
5 * Released under MIT license <https://lodash.com/license>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
10 /** `Object#toString` result references. */
11 var objectTag = '[object Object]';
14 * Checks if `value` is a host object in IE < 9.
17 * @param {*} value The value to check.
18 * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
20 function isHostObject(value) {
21 // Many host objects are `Object` objects that can coerce to strings
22 // despite having improperly defined `toString` methods.
24 if (value != null && typeof value.toString != 'function') {
26 result = !!(value + '');
33 * Creates a unary function that invokes `func` with its argument transformed.
36 * @param {Function} func The function to wrap.
37 * @param {Function} transform The argument transform.
38 * @returns {Function} Returns the new function.
40 function overArg(func, transform) {
41 return function(arg) {
42 return func(transform(arg));
46 /** Used for built-in method references. */
47 var funcProto = Function.prototype,
48 objectProto = Object.prototype;
50 /** Used to resolve the decompiled source of functions. */
51 var funcToString = funcProto.toString;
53 /** Used to check objects for own properties. */
54 var hasOwnProperty = objectProto.hasOwnProperty;
56 /** Used to infer the `Object` constructor. */
57 var objectCtorString = funcToString.call(Object);
61 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
64 var objectToString = objectProto.toString;
66 /** Built-in value references. */
67 var getPrototype = overArg(Object.getPrototypeOf, Object);
70 * Checks if `value` is object-like. A value is object-like if it's not `null`
71 * and has a `typeof` result of "object".
77 * @param {*} value The value to check.
78 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
84 * _.isObjectLike([1, 2, 3]);
87 * _.isObjectLike(_.noop);
90 * _.isObjectLike(null);
93 function isObjectLike(value) {
94 return !!value && typeof value == 'object';
98 * Checks if `value` is a plain object, that is, an object created by the
99 * `Object` constructor or one with a `[[Prototype]]` of `null`.
105 * @param {*} value The value to check.
106 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
113 * _.isPlainObject(new Foo);
116 * _.isPlainObject([1, 2, 3]);
119 * _.isPlainObject({ 'x': 0, 'y': 0 });
122 * _.isPlainObject(Object.create(null));
125 function isPlainObject(value) {
126 if (!isObjectLike(value) ||
127 objectToString.call(value) != objectTag || isHostObject(value)) {
130 var proto = getPrototype(value);
131 if (proto === null) {
134 var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
135 return (typeof Ctor == 'function' &&
136 Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
139 module.exports = isPlainObject;