assert-plus
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Assert-plus is a lightweight library offering enhanced features over Node's assert module. The module brings two extended functionalities, the environment variable NODE_NDEBUG that allows users to disable assertions, and API wrappers such as assert.string(myArg, 'myArg')
that are designed for argument testing, improving the validation process within your code.
Utilizing assert-plus involves straightforward means and requires minimal effort. The first step is to install the package through npm using npm install assert-plus
. You can use it within your JavaScript function like so:
var assert = require('assert-plus');
function fooAccount(options, callback) {
assert.object(options, 'options');
assert.number(options.id, 'options.id');
assert.bool(options.isManager, 'options.isManager');
assert.string(options.name, 'options.name');
assert.arrayOfString(options.email, 'options.email');
assert.func(callback, 'callback');
// Do stuff
callback(null, {});
}
In this code, we're utilizing assert-plus to ensure that the correct types are passed to a function. If the wrong type is passed, an AssertionError will be thrown.
The comprehensive and updated documentation for assert-plus is hosted within the Readme file on the GitHub repository at https://github.com/mcavage/node-assert-plus
. Here you'll find details about the API, installation guides, and code usage examples for each category of assertions provided by this powerful module.