What is is-plain-object?
The is-plain-object package is a simple utility that checks if an object is a plain object, that is, an object created by the Object constructor or one with a null prototype.
What are is-plain-object's main functionalities?
Check if an object is a plain object
This feature allows you to verify if a given object is a plain object. It returns true for objects created by the Object constructor or with a null prototype and false for objects created by other constructors.
const isPlainObject = require('is-plain-object');
const obj = { x: 1, y: 2 };
console.log(isPlainObject(obj)); // true
const notPlain = Object.create(null);
console.log(isPlainObject(notPlain)); // true
function Test() { this.a = 1; }
console.log(isPlainObject(new Test())); // false
Other packages similar to is-plain-object
lodash.isplainobject
This package is a part of the Lodash library specifically for checking if a value is a plain object. It is similar to is-plain-object but comes from a well-known utility library, which might be preferable for projects already using Lodash.
isobject
Isobject checks if a value is an object and not null, but it does not check if the object is plain. It is less strict compared to is-plain-object, which specifically checks for plain objects.
is-plain-object
Returns true if an object was created by the Object
constructor.
Use isobject if you only want to check if the value is an object and not an array or null.
Install
Install with npm
$ npm i is-plain-object --save
Usage
var isPlainObject = require('is-plain-object');
true when created by the Object
constructor.
isPlainObject(Object.create({}));
isPlainObject(Object.create(Object.prototype));
isPlainObject({foo: 'bar'});
isPlainObject({});
false when not created by the Object
constructor.
isPlainObject(1);
isPlainObject(['foo', 'bar']);
isPlainObject([]);
isPlainObject(new Foo);
isPlainObject(null);
isPlainObject(Object.create(null));
Related projects
- assign-deep: Deeply assign the enumerable properties of source objects to a destination object.
- extend-shallow: Extend an object with the properties of additional objects. node.js/javascript util.
- for-own: Iterate over the own enumerable properties of an object, and return an object with properties… more
- for-in: Iterate over the own and inherited enumerable properties of an objecte, and return an object… more
- is-plain-object: Returns true if an object was created by the
Object
constructor. - isobject: Returns true if the value is an object and not an array or null.
- kind-of: Get the native type of a value.
- merge-deep: Recursively merge values in a javascript object.
Running tests
Install dev dependencies:
$ npm i -d && npm test
Author
Jon Schlinkert
License
Copyright © 2015 Jon Schlinkert
Released under the MIT license.
This file was generated by verb-cli on May 28, 2015.