throw
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.1
    254
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.1
    254
  • 1.1.0
    344
  • 1.0.0
    178
  • 0.0.0
    0

Package Sidebar

Install

npm i throw

Weekly Downloads

655

Version

1.1.1

License

MIT

Unpacked Size

2.27 kB

Total Files

4

Last publish

Collaborators

  • anton-rudeshko