New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

throw

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

throw

A simple utility that helps throw exceptions.

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
330
decreased by-44.82%
Maintainers
1
Weekly downloads
 
Created
Source

throw

You can't use throw statement in expressions in JavaScript:

arg = arg || throw new Error('arg is required');
// => SyntaxError: Unexpected token throw

This tiny library is wrapping throw in a function:

var thr = require('throw');

// ...

arg = arg || thr('arg is required');

Messages can contain printf-like placeholders:

arg = arg || thr('"%s" is required', argName);

You can specify instance of Error instead of message:

arg = arg || thr(new Error('arg is required'));

Or parametrize error class:

arg = arg || thr(Error, 'arg is required');

Installation

$ npm install --save throw

Usage

var thr = require('throw');

var parsed = parse(str) || thr('Could not parse "%s"', str);

License

MIT

Keywords

FAQs

Package last updated on 10 May 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