What is is-obj?
The is-obj package is a simple utility that allows you to check if a value is a non-null object. It is useful when you want to ensure that a value is an object type (excluding null, arrays, and other non-plain objects) before performing operations that are specific to objects.
What are is-obj's main functionalities?
Check if a value is a non-null object
This feature allows you to verify if a given value is a non-null object. It returns true for plain objects and false for null, arrays, functions, and other non-object types.
const isObj = require('is-obj');
console.log(isObj({})); // true
console.log(isObj(null)); // false
console.log(isObj([])); // false
console.log(isObj('hello')); // false
Other packages similar to is-obj
is-plain-object
is-plain-object is a package that checks if an object is a plain object, that is, an object created by the Object constructor or one with a null prototype. It is similar to is-obj but also checks if the object is created by the Object constructor, which is-obj does not do.
isobject
isobject is another npm package that checks if a value is an object and not an array or null. It is similar to is-obj but also returns true for functions, which is-obj does not.
lodash.isplainobject
lodash.isplainobject is a method from the popular Lodash library that checks if a value is a plain object. It is more comprehensive than is-obj as it includes additional checks to determine if the object is plain.
is-obj
Check if a value is an object
Keep in mind that array, function, regexp, etc, are objects in JavaScript.
See is-plain-obj
if you want to check for plain objects.
Install
$ npm install --save is-obj
Usage
const isObj = require('is-obj');
isObj({foo: 'bar'});
isObj([1, 2, 3]);
isObj('foo');
License
MIT © Sindre Sorhus