forked from anton-rudeshko/node-throw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 41344c6
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.idea/ | ||
*.iml | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# Commenting this out is preferred by some people, see | ||
# https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git | ||
node_modules | ||
|
||
# Users Environment Variables | ||
.lock-wscript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# throw | ||
|
||
You can't use `throw` statement in expressions in JavaScript: | ||
|
||
```js | ||
arg = arg || throw new Error('arg is required'); | ||
// => SyntaxError: Unexpected token throw | ||
``` | ||
|
||
This tiny library is wrapping `throw` in a function: | ||
|
||
```js | ||
var thr = require('throw'); | ||
|
||
// ... | ||
|
||
arg = arg || thr('arg is required'); | ||
``` | ||
|
||
Messages can contain `printf`-like placeholders: | ||
|
||
```js | ||
arg = arg || thr('"%s" is required', argName); | ||
``` | ||
|
||
## Installation | ||
|
||
```bash | ||
$ npm install --save throw | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
var thr = require('throw'); | ||
|
||
var parsed = parse(str) || thr('Could not parse "%s"', str); | ||
``` | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var format = require('util').format; | ||
|
||
/** | ||
* Function wrapper for throw statement. | ||
* Throw an error with formatted message. | ||
* @param {String} errorMessage | ||
* @throws | ||
*/ | ||
module.exports = function(errorMessage) { | ||
throw new Error(format.apply(null, arguments)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "throw", | ||
"version": "0.0.0", | ||
"description": "A simple utility that helps throw exceptions.", | ||
"author": "Anton Rudeshko <anton@rudeshko.com> (http://www.rudeshko.com)", | ||
"homepage": "https://github.com/anton-rudeshko/node-throw", | ||
"main": "index.js", | ||
"keywords": [ | ||
"throw", | ||
"error", | ||
"exception" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:anton-rudeshko/node-throw.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/anton-rudeshko/node-throw/issues" | ||
}, | ||
"license": "MIT" | ||
} |