Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-rudeshko committed Jul 22, 2014
0 parents commit 41344c6
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .gitignore
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
42 changes: 42 additions & 0 deletions README.md
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
11 changes: 11 additions & 0 deletions index.js
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));
};
21 changes: 21 additions & 0 deletions package.json
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"
}

0 comments on commit 41344c6

Please sign in to comment.