Comparing version 0.1.0 to 0.2.0
42
index.js
@@ -21,8 +21,8 @@ /*! | ||
* @param {Function} `init` Function to call when creating new Error | ||
* @param {Boolean} `capture` Optional parameter to determine if the stack trace should be captured or not. (Defaults to `true`) | ||
* @return {Function} new Error Class | ||
* @api public | ||
* @name errorBase | ||
*/ | ||
module.exports = function errorBase (name, init) { | ||
module.exports = function errorBase (name, init, capture) { | ||
if (typeof name !== 'string') { | ||
@@ -35,15 +35,16 @@ throw new TypeError('expected `name` to be a string.'); | ||
} | ||
capture = typeof capture === 'boolean' ? capture : true; | ||
function Type () { | ||
if (!Error.captureStackTrace) { | ||
this.stack = (new Error()).stack; | ||
if (capture) { | ||
if (!Error.captureStackTrace) { | ||
define(this, 'stack', (new Error()).stack); | ||
} else { | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
} | ||
else { | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
init.apply(this, arguments); | ||
} | ||
Type.prototype = new Error(); | ||
Type.prototype = Object.create(Error.prototype); | ||
Type.prototype.name = name; | ||
@@ -55,4 +56,27 @@ Type.prototype.constructor = Type; | ||
/** | ||
* Default identity function used to just set the `message` property when another | ||
* `init` function is not passed in. | ||
* | ||
* @param {String} `message` Message to set. | ||
*/ | ||
function identity (message) { | ||
this.message = message; | ||
} | ||
/** | ||
* Define a non-enumerable property on an object. | ||
* | ||
* @param {Object} `obj` Object to define property on. | ||
* @param {String} `prop` Property name. | ||
* @param {*} `val` Value to define on the property. | ||
*/ | ||
function define(obj, prop, val) { | ||
Object.defineProperty(obj, prop, { | ||
enumerable: false, | ||
configurable: true, | ||
value: val | ||
}); | ||
} |
{ | ||
"name": "error-base", | ||
"description": "Create custom Error classes.", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/doowb/error-base", | ||
@@ -23,5 +23,15 @@ "author": "Brian Woodward (https://github.com/doowb)", | ||
"devDependencies": { | ||
"gulp": "^3.9.1", | ||
"gulp-eslint": "^1.1.1", | ||
"gulp-format-md": "^0.1.5", | ||
"gulp-istanbul": "^0.10.3", | ||
"gulp-mocha": "^2.2.0", | ||
"mocha": "*", | ||
"should": "^7.1.0" | ||
"should": "*" | ||
}, | ||
"verb": { | ||
"plugins": [ | ||
"gulp-format-md" | ||
] | ||
} | ||
} |
@@ -1,6 +0,6 @@ | ||
# error-base [![NPM version](https://badge.fury.io/js/error-base.svg)](http://badge.fury.io/js/error-base) [![Build Status](https://travis-ci.org/doowb/error-base.svg)](https://travis-ci.org/doowb/error-base) | ||
# error-base [![NPM version](https://img.shields.io/npm/v/error-base.svg)](https://www.npmjs.com/package/error-base) [![Build Status](https://img.shields.io/travis/doowb/error-base.svg)](https://travis-ci.org/doowb/error-base) | ||
> Create custom Error classes. | ||
Install with [npm](https://www.npmjs.com/) | ||
Install with [npm](https://www.npmjs.com/): | ||
@@ -47,2 +47,3 @@ ```sh | ||
* `init` **{Function}**: Function to call when creating new Error | ||
* `capture` **{Boolean}**: Optional parameter to determine if the stack trace should be captured or not. (Defaults to `true`) | ||
* `returns` **{Function}**: new Error Class | ||
@@ -74,8 +75,8 @@ | ||
+ [github/doowb](https://github.com/doowb) | ||
+ [twitter/doowb](http://twitter.com/doowb) | ||
* [github/doowb](https://github.com/doowb) | ||
* [twitter/doowb](http://twitter.com/doowb) | ||
## License | ||
Copyright © 2015 Brian Woodward | ||
Copyright © 2016 [Brian Woodward](https://github.com/doowb) | ||
Released under the MIT license. | ||
@@ -85,2 +86,2 @@ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 22, 2015._ | ||
_This file was generated by [verb](https://github.com/verbose/verb) on February 10, 2016._ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5696
68
84
7