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 with npm
npm i is-plain-object --save
Running tests
Install dev dependencies.
npm i -d && npm test
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));
Author
Jon Schlinkert
License
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license
This file was generated by verb on February 25, 2015.