What is @stdlib/assert-is-plain-object?
@stdlib/assert-is-plain-object is a utility package that provides a function to check if a value is a plain object. A plain object is an object created by the Object constructor or with an object literal.
What are @stdlib/assert-is-plain-object's main functionalities?
Check if a value is a plain object
This feature allows you to check if a given value is a plain object. In the code sample, the function `isPlainObject` is used to check if `obj` is a plain object, which returns `true`.
const isPlainObject = require('@stdlib/assert-is-plain-object');
const obj = { 'a': 1, 'b': 2 };
const result = isPlainObject(obj);
console.log(result); // true
Check if a non-object value is a plain object
This feature allows you to check if a non-object value is a plain object. In the code sample, the function `isPlainObject` is used to check if `notAnObject` is a plain object, which returns `false`.
const isPlainObject = require('@stdlib/assert-is-plain-object');
const notAnObject = 42;
const result = isPlainObject(notAnObject);
console.log(result); // false
Check if an array is a plain object
This feature allows you to check if an array is a plain object. In the code sample, the function `isPlainObject` is used to check if `arr` is a plain object, which returns `false`.
const isPlainObject = require('@stdlib/assert-is-plain-object');
const arr = [1, 2, 3];
const result = isPlainObject(arr);
console.log(result); // false
Other packages similar to @stdlib/assert-is-plain-object
lodash.isplainobject
The `lodash.isplainobject` package is a utility from the Lodash library that checks if a value is a plain object. It is similar to `@stdlib/assert-is-plain-object` in functionality but is part of the larger Lodash utility library, which provides a wide range of utility functions for JavaScript.
is-plain-object
The `is-plain-object` package is a standalone utility that checks if a value is a plain object. It is similar to `@stdlib/assert-is-plain-object` in that it focuses solely on determining if a value is a plain object, but it is a smaller, more focused package.
isobject
The `isobject` package is a utility that checks if a value is an object and not an array or null. While it is broader in scope than `@stdlib/assert-is-plain-object`, it can be used to achieve similar functionality by further checking if the object is a plain object.
isPlainObject
Test if a value is a plain object.
Installation
npm install @stdlib/assert-is-plain-object
Usage
var isPlainObject = require( '@stdlib/assert-is-plain-object' );
isPlainObject( value )
Tests if a value
is a plain object
.
var bool = isPlainObject( {} );
bool = isPlainObject( null );
Examples
var isPlainObject = require( '@stdlib/assert-is-plain-object' );
var bool = isPlainObject( {} );
bool = isPlainObject( Object.create( null ) );
bool = isPlainObject( [] );
bool = isPlainObject( null );
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
License
See LICENSE.
Copyright
Copyright © 2016-2021. The Stdlib Authors.
0.0.3 (2021-06-16)
No changes reported for this release.
</section>
<!-- /.release -->
<section class="release" id="v0.0.2">