Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
is-plain-obj
Advanced tools
The is-plain-obj package is a simple and lightweight npm package used to check if a given object is a plain object, that is, an object created by the Object constructor or one with a null prototype.
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 all other types of objects, such as instances of custom classes or built-in JavaScript objects like Map.
const isPlainObj = require('is-plain-obj');
console.log(isPlainObj({foo: 'bar'})); // true
console.log(isPlainObj(new Map())); // false
Similar to is-plain-obj, is-plain-object checks if a given value is a plain object. However, it might have slightly different internal implementations or dependencies, potentially affecting its performance or compatibility in certain environments.
Part of the Lodash library, lodash.isplainobject offers similar functionality to is-plain-obj. Lodash is a more extensive utility library, so using this function might bring in more dependencies than needed if you're only interested in checking for plain objects.
Check if a value is a plain object
An object is plain if it's created by either {}
, new Object()
, or Object.create(null)
.
$ npm install is-plain-obj
import isPlainObject from 'is-plain-obj';
import {runInNewContext} from 'node:vm';
isPlainObject({foo: 'bar'});
//=> true
isPlainObject(new Object());
//=> true
isPlainObject(Object.create(null));
//=> true
// This works across realms
isPlainObject(runInNewContext('({})'));
//=> true
isPlainObject([1, 2, 3]);
//=> false
class Unicorn {}
isPlainObject(new Unicorn());
//=> false
isPlainObject(Math);
//=> false
FAQs
Check if a value is a plain object
The npm package is-plain-obj receives a total of 35,186,274 weekly downloads. As such, is-plain-obj popularity was classified as popular.
We found that is-plain-obj demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.