UNPKG

765 BJavaScriptView Raw
1'use strict';
2
3var isObject = require('./object');
4
5/**
6 * Checks whether a value is a plain object.
7 * Plain object is an object which prototype is Object.prototype or null
8 *
9 * @function plainObject
10 *
11 * @example
12 * var is = require('predicates');
13 *
14 * is.plainObject({property: 'value'}); // true
15 * is.plainObject(new Object); // true
16 * is.plainObject(Object.create(null)); // true
17 * is.plainObject(new String('test')); // false
18 *
19 * var Foo = function() {};
20 * is.plainObject(new Foo); // false
21 *
22 * @param {*} value
23 * @returns {boolean}
24 */
25module.exports = function isPlainObject(value) {
26 if (!isObject(value)) {
27 return false;
28 }
29 var proto = Object.getPrototypeOf(value);
30 return proto === Object.prototype || proto === null;
31};
\No newline at end of file