Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
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
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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.