Socket
Socket
Sign inDemoInstall

lazy-ass

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazy-ass

Lazy assertions without performance penalty


Version published
Weekly downloads
5.3M
decreased by-3.39%
Maintainers
1
Weekly downloads
 
Created

What is lazy-ass?

The lazy-ass npm package is a utility for making assertions with lazy evaluation. It allows developers to write assertions that are only evaluated if the assertion condition is false. This can be useful for performance reasons, as the assertion message, which might include string concatenation or other computations, is only calculated if the assertion fails.

What are lazy-ass's main functionalities?

Lazy assertions

This feature allows you to make assertions that are only evaluated if the condition is false. In the code sample, `lazyAss` checks if 'foo' is a string, and if it's not, it will throw an error with the message 'expected a string'.

var lazyAss = require('lazy-ass');
var is = require('check-more-types');
lazyAss(is.string('foo'), 'expected a string');

Lazy assertions with callback

This feature allows you to provide a callback function for the assertion message. The callback is only called if the assertion fails, which can save performance for expensive computations that are only needed for the error message.

var lazyAss = require('lazy-ass');
var is = require('check-more-types');
function expensiveComputation() {
  // some expensive computation here
  return 'computed value';
}
lazyAss(is.number(expensiveComputation), function () {
  return 'expected a number, got ' + expensiveComputation();
});

Other packages similar to lazy-ass

Keywords

FAQs

Package last updated on 18 Oct 2021

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