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.
About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
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-2023. The Stdlib Authors.
0.1.0 (2023-09-22)
<section class="features">
Features
5200ce2
- update minimum TypeScript version196225d
- use type predicates for narrowing
</section>
<!-- /.features -->
<section class="breaking-changes">
BREAKING CHANGES
</section>
<!-- /.breaking-changes -->
<section class="commits">
Commits
<details>
5200ce2
- feat: update minimum TypeScript version (by Philipp Burckhardt)3f60609
- test: use strictEqual checks (by Philipp Burckhardt)196225d
- feat: use type predicates for narrowing (by Philipp Burckhardt)
</details>
</section>
<!-- /.commits -->
<section class="contributors">
Contributors
A total of 1 person contributed to this release. Thank you to this contributor:
</section>
<!-- /.contributors -->
</section>
<!-- /.release -->
<section class="release" id="v0.0.7">