Skip to content

Commit

Permalink
0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Mar 3, 2015
0 parents commit 50c5e2d
Show file tree
Hide file tree
Showing 16 changed files with 787 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"env": {
"node": true,
"browser": true
},
"rules": {
"quotes": [2, "single"]
}
}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
*.log
build/
bower_components/
components/
coverage/
node_modules/
build.js
143 changes: 143 additions & 0 deletions .jscs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"plugins": [
"jscs-jsdoc"
],
"jsDoc": {
"checkAnnotations": "jsdoc3",
"checkParamNames": true,
"requireParamTypes": true,
"checkRedundantParams": true,
"checkReturnTypes": true,
"checkRedundantReturns": true,
"requireReturnTypes": true,
"checkTypes": "strictNativeCase",
"checkRedundantAccess": true,
"enforceExistence": true,
"requireHyphenBeforeDescription": true
},
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": true,
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireBlocksOnNewline": true,
"disallowPaddingNewlinesInBlocks": true,
"disallowEmptyBlocks": true,
"disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"requireSpacesInsideObjectBrackets": "all",
"disallowDanglingUnderscores": true,
"disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"requireOperatorBeforeLineBreak": [
"?",
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"requireSpaceBeforeBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!=="
],
"requireSpaceAfterBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!=="
],
"disallowSpaceAfterPrefixUnaryOperators": [
"++",
"--",
"+",
"-",
"~",
"!"
],
"disallowSpaceBeforePostfixUnaryOperators": [
"++",
"--"
],
"disallowImplicitTypeConversion": [
"numeric",
"boolean",
"binary",
"string"
],
"requireCamelCaseOrUpperCaseIdentifiers": true,
"disallowKeywords": [
"with"
],
"disallowMultipleLineStrings": true,
"disallowMultipleLineBreaks": true,
"validateLineBreaks": "LF",
"validateQuoteMarks": "'",
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"disallowKeywordsOnNewLine": [
"else"
],
"requireLineFeedAtFileEnd": true,
"maximumLineLength": 78,
"requireCapitalizedConstructors": true,
"safeContextKeyword": "self",
"requireDotNotation": true,
"disallowYodaConditions": true,
"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
}
}
15 changes: 15 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.*
*.log
bower_components/
build/
components/
coverage/
node_modules/
build.js
example.js
fault.js
fault.min.js
test.js
bower.json
component.json
History.md
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: node_js
script: npm run-script test-travis
node_js:
- '0.10'
- '0.11'
- '0.12'
- iojs
after_script: npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls
deploy:
provider: npm
email: tituswormer@gmail.com
api_key:
secure: JF0cqfVZSrWSEkVU/Acn/qTaCtmmXuQR9B6qu05ogbxjuy9aP652RtrUJTyihP3izeRBfdPhP9px41fvWZNwebQE9VC6aSCkgqTN9sgssNpLYkXCCe0GdDR+w8CLHWYHRQfAab25VWVg2jxT/s377bzU8cpRKcaKXer/HK+rMlY=
on:
repo: wooorm/fault
3 changes: 3 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

0.1.0 / 2015-03-03
==================
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2015 Titus Wormer <tituswormer@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
140 changes: 140 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# fault [![Build Status](https://img.shields.io/travis/wooorm/fault.svg?style=flat)](https://travis-ci.org/wooorm/fault) [![Coverage Status](https://img.shields.io/coveralls/wooorm/fault.svg?style=flat)](https://coveralls.io/r/wooorm/fault?branch=master)

Functional errors with formatted output.

## Installation

[npm](https://docs.npmjs.com/cli/install):

```bash
$ npm install fault
```

[Bower](http://bower.io/#install-packages):

```bash
$ bower install fault
```

[Component.js](https://github.com/componentjs/component):

```bash
$ component install wooorm/fault
```

[Duo](http://duojs.org/#getting-started):

```javascript
var fault = require('wooorm/fault');
```

UMD (globals, AMD, CommonJS) ([uncompressed](fault.js) and [compressed](fault.min.js)):

```html
<script src="path/to/fault.js"></script>
<script>
throw fault('Hello %s!', 'browser'); // throws "Error: Hello browser!"
</script>
```

## Usage

```javascript
var fault = require('fault');
```

Create a normal error and format a string:

```javascript
var error = fault('Hello %s!', 'Eric');
```

When thrown:

```text
Error: Hello Eric!
at ~/fault/index.js:22:16
at Object.<anonymous> (~/fault/example.js-tmp:4:13)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
...
```

Create a type error and format a float:

```javascript
var type = fault.type('Who doesn’t like %f? \ud83c\udf70', Math.PI);
```

When thrown:

```text
TypeError: Who doesn’t like 3.141593? 🍰
at Function.<anonymous> (~/fault/index.js:22:16)
at Object.<anonymous> (~/fault/example.js-tmp:10:18)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
...
```

## API

### fault(format?[, values...])

Creates an error with a printf-like formatted message.

Parameters:

- `format` (`string`, optional);
- `values` (`*`, optional).

Formatters:

- `%s` — String;
- `%b` — Binary;
- `%c` — Character;
- `%d` — Decimal;
- `%f` — Floating point;
- `%o` — Octal;
- `%x` — Lowercase hexadecimal;
- `%X` — Uppercase hexadecimal;
- `%` followed by any other character, prints that character.

See [samsonjs/format](https://github.com/samsonjs/format) for argument parsing.

Returns:

An instance of [Error](https://developer.mozilla.org/JavaScript/Reference/Global_Objects/Error).

#### Other errors

- **[fault](#faultformatvalues).eval(format?[, values...])** — Returns an instance of [EvalError](https://developer.mozilla.org/JavaScript/Reference/Global_Objects/EvalError);
- **[fault](#faultformatvalues).range(format?[, values...])** — Returns an instance of [RangeError](https://developer.mozilla.org/JavaScript/Reference/Global_Objects/RangeError);
- **[fault](#faultformatvalues).reference(format?[, values...])** — Returns an instance of [ReferenceError](https://developer.mozilla.org/JavaScript/Reference/Global_Objects/ReferenceError);
- **[fault](#faultformatvalues).syntax(format?[, values...])** — Returns an instance of [SyntaxError](https://developer.mozilla.org/JavaScript/Reference/Global_Objects/SyntaxError);
- **[fault](#faultformatvalues).type(format?[, values...])** — Returns an instance of [TypeError](https://developer.mozilla.org/JavaScript/Reference/Global_Objects/TypeError);
- **[fault](#faultformatvalues).uri(format?[, values...])** — Returns an instance of [URIError](https://developer.mozilla.org/JavaScript/Reference/Global_Objects/URIError).

#### [fault](#faultformatvalues).create(ErrorConstructor)

Factory to create instances of `ErrorConstructor` with support for formatting. Used internally to wrap the global error constructors, exposed for custom errors.

Parameters:

- `ErrorConstructor` (Function).

Returns:

- `function(format?[, values...])`.

## License

[MIT](LICENSE) @ [Titus Wormer](http://wooorm.com)
Loading

0 comments on commit 50c5e2d

Please sign in to comment.