isobject
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The npm package "isobject" is a utility function written in JavaScript that returns true if the provided value is an object, while specifically excluding arrays and null values. This function comes in handy when determining the type of a variable in JavaScript, particularly as the language treats arrays and nulls as typeof 'object'.
To use the isobject npm package, you'll first need to install it. This can be accomplished by running npm install --save isobject
in the command line of your project directory.
After installation, you can import it into your JavaScript file with import isObject from 'isobject';
.
Here are some usage examples:
import isObject from 'isobject';
// this should return true
console.log(isObject({}));
console.log(isObject(Object.create({})));
console.log(isObject(Object.create(Object.prototype)));
console.log(isObject(Object.create(null)));
console.log(isObject(new Foo));
console.log(isObject(/foo/));
// these should return false
console.log(isObject());
console.log(isObject(function () {}));
console.log(isObject(1));
console.log(isObject([]));
console.log(isObject(undefined));
console.log(isObject(null));
In the above examples, isObject
checks if the provided values are objects, but not arrays or null.
The official isobject package documentation can be found on its GitHub page. This documentation shares significant information about how the package works, installation procedures, and examples of how to use the function in your project. More detailed understanding can be gained from the source code, and you can also contribute by creating an issue for bugs and feature requests.