Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

assert-plus

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assert-plus

Extra assertions on top of node's assert module

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22M
increased by7.74%
Maintainers
1
Weekly downloads
 
Created

What is assert-plus?

The assert-plus npm package is a library that provides a set of assertion functions for verifying invariants. It is an extension of the built-in assert module in Node.js, offering more specific assertion types and better error messages. It is commonly used to enforce type checking and value validation in JavaScript code, particularly on the server side with Node.js.

What are assert-plus's main functionalities?

Type assertions

Asserts that the given argument is of the expected type. If the argument is not of the specified type, it throws a TypeError with a message indicating the name of the argument and the expected type.

const assert = require('assert-plus');
assert.string('hello', 'argument'); // OK
assert.string(123, 'argument'); // Throws TypeError

Value assertions

Asserts that the given argument is of the expected type or is undefined/null if it is an optional argument. If the argument is provided and is not of the specified type, it throws a TypeError.

const assert = require('assert-plus');
assert.optionalNumber(null, 'optionalArgument'); // OK
assert.optionalNumber('not a number', 'optionalArgument'); // Throws TypeError

Array content assertions

Asserts that the given argument is an array where every element is of the expected type. If any element is not of the specified type, it throws a TypeError.

const assert = require('assert-plus');
assert.arrayOfString(['hello', 'world'], 'stringArray'); // OK
assert.arrayOfString(['hello', 123], 'stringArray'); // Throws TypeError

Other packages similar to assert-plus

FAQs

Package last updated on 11 Sep 2012

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc