Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@stdlib/assert-is-plain-object
Advanced tools
@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.
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
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.
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.
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.
Test if a value is a plain object.
npm install @stdlib/assert-is-plain-object
var isPlainObject = require( '@stdlib/assert-is-plain-object' );
Tests if a value
is a plain object
.
var bool = isPlainObject( {} );
// returns true
bool = isPlainObject( null );
// returns false
var isPlainObject = require( '@stdlib/assert-is-plain-object' );
var bool = isPlainObject( {} );
// returns true
bool = isPlainObject( Object.create( null ) );
// returns true
bool = isPlainObject( [] );
// returns false
bool = isPlainObject( null );
// returns false
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.
See LICENSE.
Copyright © 2016-2021. The Stdlib Authors.
FAQs
Test if a value is a plain object.
We found that @stdlib/assert-is-plain-object demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.