Socket
Socket
Sign inDemoInstall

better-assert

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-assert

Better assertions for node, reporting the expr, filename, lineno etc


Version published
Weekly downloads
735K
decreased by-0.59%
Maintainers
2
Weekly downloads
 
Created

What is better-assert?

The better-assert npm package is a simple assertion library for Node.js. It allows developers to write assertions in their code to ensure that certain conditions hold true. If an assertion fails, it throws an error with a detailed message, making it easier to debug issues.

What are better-assert's main functionalities?

Basic Assertion

This feature allows you to assert that a condition is true. If the condition is false, an error is thrown. In this example, the assertion checks if the variable `x` is equal to 5.

const assert = require('better-assert');
let x = 5;
assert(x === 5);

Assertion with Error Message

This feature allows you to provide a custom error message that will be displayed if the assertion fails. In this example, the assertion checks if the variable `y` is equal to 5, and if not, it throws an error with the message 'y should be 5'.

const assert = require('better-assert');
let y = 10;
assert(y === 5, 'y should be 5');

Complex Assertions

This feature allows you to perform more complex assertions involving multiple conditions. In this example, the assertion checks if the properties `a` and `b` of the object `obj` have the values 1 and 2, respectively.

const assert = require('better-assert');
let obj = { a: 1, b: 2 };
assert(obj.a === 1 && obj.b === 2);

Other packages similar to better-assert

Keywords

FAQs

Package last updated on 21 Nov 2014

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