diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:38:50 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:40:43 +0200 |
commit | 7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch) | |
tree | 6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/create-error-class | |
parent | 963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff) |
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/create-error-class')
-rw-r--r-- | node_modules/create-error-class/index.js | 44 | ||||
-rw-r--r-- | node_modules/create-error-class/license | 21 | ||||
-rw-r--r-- | node_modules/create-error-class/package.json | 30 | ||||
-rw-r--r-- | node_modules/create-error-class/readme.md | 54 |
4 files changed, 149 insertions, 0 deletions
diff --git a/node_modules/create-error-class/index.js b/node_modules/create-error-class/index.js new file mode 100644 index 000000000..e415aa7ed --- /dev/null +++ b/node_modules/create-error-class/index.js @@ -0,0 +1,44 @@ +'use strict'; +var captureStackTrace = require('capture-stack-trace'); + +function inherits(ctor, superCtor) { + ctor.super_ = superCtor; + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); +} + +module.exports = function createErrorClass(className, setup) { + if (typeof className !== 'string') { + throw new TypeError('Expected className to be a string'); + } + + if (/[^0-9a-zA-Z_$]/.test(className)) { + throw new Error('className contains invalid characters'); + } + + setup = setup || function (message) { + this.message = message; + }; + + var ErrorClass = function () { + Object.defineProperty(this, 'name', { + configurable: true, + value: className, + writable: true + }); + + captureStackTrace(this, this.constructor); + + setup.apply(this, arguments); + }; + + inherits(ErrorClass, Error); + + return ErrorClass; +}; diff --git a/node_modules/create-error-class/license b/node_modules/create-error-class/license new file mode 100644 index 000000000..1aeb74fd2 --- /dev/null +++ b/node_modules/create-error-class/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Vsevolod Strukchinsky <floatdrop@gmail.com> (github.com/floatdrop) + +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. diff --git a/node_modules/create-error-class/package.json b/node_modules/create-error-class/package.json new file mode 100644 index 000000000..b304012c4 --- /dev/null +++ b/node_modules/create-error-class/package.json @@ -0,0 +1,30 @@ +{ + "name": "create-error-class", + "version": "3.0.2", + "description": "Create Error classes", + "license": "MIT", + "repository": "floatdrop/create-error-class", + "author": { + "name": "Vsevolod Strukchinsky", + "email": "floatdrop@gmail.com", + "url": "github.com/floatdrop" + }, + "engines": { + "node": ">=0.10.0" + }, + "scripts": { + "test": "mocha" + }, + "files": [ + "index.js" + ], + "keywords": [ + "" + ], + "dependencies": { + "capture-stack-trace": "^1.0.0" + }, + "devDependencies": { + "mocha": "*" + } +} diff --git a/node_modules/create-error-class/readme.md b/node_modules/create-error-class/readme.md new file mode 100644 index 000000000..d993cea37 --- /dev/null +++ b/node_modules/create-error-class/readme.md @@ -0,0 +1,54 @@ +# create-error-class [](https://travis-ci.org/floatdrop/create-error-class) + +> Create error class + + +## Install + +``` +$ npm install --save create-error-class +``` + + +## Usage + +```js +var createErrorClass = require('create-error-class'); + +var HTTPError = createErrorClass('HTTPError', function (props) { + this.message = 'Status code is ' + props.statusCode; +}); + +throw new HTTPError({statusCode: 404}); +``` + + +## API + +### createErrorClass(className, [setup]) + +Return constructor of Errors with `className`. + +#### className + +*Required* +Type: `string` + +Class name of Error Object. Should contain characters from `[0-9a-zA-Z_$]` range. + +#### setup +Type: `function` + +Setup function, that will be called after each Error object is created from constructor with context of Error object. + +By default `setup` function sets `this.message` as first argument: + +```js +var MyError = createErrorClass('MyError'); + +new MyError('Something gone wrong!').message; // => 'Something gone wrong!' +``` + +## License + +MIT © [Vsevolod Strukchinsky](http://github.com/floatdrop) |