# add dist

This commit is contained in:
Mario Romano
2016-04-21 11:56:31 +01:00
parent 5914688467
commit 07807e7bc3
13499 changed files with 1808930 additions and 5 deletions

View File

@@ -0,0 +1,125 @@
# make-error
[![Build Status](https://img.shields.io/travis/julien-f/js-make-error/master.svg)](http://travis-ci.org/julien-f/js-make-error)
[![Dependency Status](https://david-dm.org/julien-f/js-make-error/status.svg?theme=shields.io)](https://david-dm.org/julien-f/js-make-error)
[![devDependency Status](https://david-dm.org/julien-f/js-make-error/dev-status.svg?theme=shields.io)](https://david-dm.org/julien-f/js-make-error#info=devDependencies)
> Make your own error types!
## Features
- Compatible Node & browsers
- `instanceof` support
- `error.name` & `error.stack` support
- compatible with [CSP](https://en.wikipedia.org/wiki/Content_Security_Policy) (i.e. no `eval()`)
## Installation
### Node & Browserify
Installation of the [npm package](https://npmjs.org/package/make-error):
```
> npm install --save make-error
```
Then require the package:
```javascript
var makeError = require('make-error');
```
### Browser
Clone the git repository and compile the browser version of the
library:
```
> git clone https://github.com/julien-f/js-make-error.git
> npm install
> npm run browserify
```
Then import the script `make-error.js` which has been compiled in the
`dist/` directory:
```html
<script src="make-error.js"></script>
```
## Usage
### Basic named error
```javascript
var CustomError = makeError('CustomError')
// Parameters are forwarded to the super class (here Error).
throw new CustomError('a message')
```
### Advanced error class
```javascript
function CustomError (customValue) {
CustomError.super.call(this, 'custom error message')
this.customValue = customValue
}
makeError(CustomError)
// Feel free to extend the prototype.
CustomError.prototype.myMethod = function CustomError$myMethod () {
console.log('CustomError.myMethod (%s, %s)', this.code, this.message)
}
//-----
try {
throw new CustomError(42)
} catch (error) {
error.myMethod()
}
```
### Specialized error
```javascript
var SpecializedError = makeError('SpecializedError', CustomError);
throw new SpecializedError(42);
```
### Inheritance
> Best for ES6.
```javascript
import {BaseError} from 'make-error'
class CustomError extends BaseError {
constructor () {
super('custom error message')
}
}
```
## Related
- [make-error-cause](https://www.npmjs.com/package/make-error-cause): Make your own error types, with a cause!
## Contributions
Contributions are *very* welcomed, either on the documentation or on
the code.
You may:
- report any [issue](https://github.com/julien-f/js-make-error/issues)
you've encountered;
- fork and create a pull request.
## License
ISC © [Julien Fontanet](http://julien.isonoe.net)

View File

@@ -0,0 +1,120 @@
// ISC @ Julien Fontanet
'use strict'
// ===================================================================
var defineProperty = Object.defineProperty
// -------------------------------------------------------------------
var isString = (function (toS) {
var ref = toS.call('')
return function isString (val) {
return toS.call(val) === ref
}
})(Object.prototype.toString)
// -------------------------------------------------------------------
var captureStackTrace
if (Error.captureStackTrace) {
captureStackTrace = Error.captureStackTrace
} else {
captureStackTrace = function captureStackTrace (error) {
var container = new Error()
defineProperty(error, 'stack', {
configurable: true,
get: function getStack () {
var stack = container.stack
// Replace property with value for faster future accesses.
defineProperty(this, 'stack', {
value: stack
})
return stack
},
set: function setStack (stack) {
defineProperty(error, 'stack', {
configurable: true,
value: stack,
writable: true
})
}
})
}
}
// -------------------------------------------------------------------
function BaseError (message) {
if (message) {
defineProperty(this, 'message', {
configurable: true,
value: message,
writable: true
})
}
var cname = this.constructor.name
if (
cname &&
cname !== this.name
) {
defineProperty(this, 'name', {
configurable: true,
value: cname,
writable: true
})
}
captureStackTrace(this, this.constructor)
}
BaseError.prototype = Object.create(Error.prototype, {
// See: https://github.com/julien-f/js-make-error/issues/4
constructor: {
configurable: true,
value: BaseError,
writable: true
}
})
// -------------------------------------------------------------------
function makeError (constructor, super_) {
if (!super_ || super_ === Error) {
super_ = BaseError
}
var name
if (isString(constructor)) {
name = constructor
constructor = function () { super_.apply(this, arguments) }
} else {
name = constructor.name
}
// Also register the super constructor also as `constructor.super_` just
// like Node's `util.inherits()`.
constructor.super_ = constructor['super'] = super_
constructor.prototype = Object.create(super_.prototype, {
constructor: {
configurable: true,
value: constructor,
writable: true
},
name: {
configurable: true,
value: name,
writable: true
}
})
return constructor
}
exports = module.exports = makeError
exports.BaseError = BaseError

View File

@@ -0,0 +1,107 @@
{
"_args": [
[
"make-error@^1.1.1",
"/Users/mromano/dev/dev-platform-webcomponents/ng2-components/ng2-alfresco-documentslist/node_modules/make-error-cause"
]
],
"_from": "make-error@>=1.1.1 <2.0.0",
"_id": "make-error@1.1.1",
"_inCache": true,
"_installable": true,
"_location": "/make-error",
"_nodeVersion": "4.2.4",
"_npmOperationalInternal": {
"host": "packages-5-east.internal.npmjs.com",
"tmp": "tmp/make-error-1.1.1.tgz_1455010194765_0.6916712960228324"
},
"_npmUser": {
"email": "julien.fontanet@isonoe.net",
"name": "julien-f"
},
"_npmVersion": "3.7.1",
"_phantomChildren": {},
"_requested": {
"name": "make-error",
"raw": "make-error@^1.1.1",
"rawSpec": "^1.1.1",
"scope": null,
"spec": ">=1.1.1 <2.0.0",
"type": "range"
},
"_requiredBy": [
"/make-error-cause"
],
"_resolved": "https://registry.npmjs.org/make-error/-/make-error-1.1.1.tgz",
"_shasum": "5ed667566c5d80e8406865c91f157bac67fdad51",
"_shrinkwrap": null,
"_spec": "make-error@^1.1.1",
"_where": "/Users/mromano/dev/dev-platform-webcomponents/ng2-components/ng2-alfresco-documentslist/node_modules/make-error-cause",
"author": {
"email": "julien.fontanet@isonoe.net",
"name": "Julien Fontanet"
},
"bugs": {
"url": "https://github.com/julien-f/js-make-error/issues"
},
"dependencies": {},
"description": "Make your own error types!",
"devDependencies": {
"browserify": "^13.0.0",
"chai": "^3.3.0",
"mocha": "^2.2.4",
"standard": "*",
"testling": "^1.7.1",
"uglify-js": "^2.4.19"
},
"directories": {},
"dist": {
"shasum": "5ed667566c5d80e8406865c91f157bac67fdad51",
"tarball": "http://registry.npmjs.org/make-error/-/make-error-1.1.1.tgz"
},
"files": [
"index.js"
],
"gitHead": "85ecdd11d9760be732c96ad49b3a50c4c014cdfd",
"homepage": "https://github.com/julien-f/js-make-error",
"keywords": [
"custom",
"derive",
"Error",
"extend",
"inherit"
],
"license": "ISC",
"maintainers": [
{
"email": "julien.fontanet@isonoe.net",
"name": "julien-f"
},
{
"email": "marsaud.fabrice@neuf.fr",
"name": "marsaud"
}
],
"name": "make-error",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git://github.com/julien-f/js-make-error.git"
},
"scripts": {
"browserify": "mkdir -p dist && browserify -s makeError index.js | uglifyjs -c > dist/make-error.js",
"test": "standard && mocha index.spec.js",
"test-browser": "testling -u"
},
"testling": {
"browsers": [
"ie/8..Latest",
"chrome/latest",
"firefox/latest"
],
"files": "index.spec.js",
"harness": "mocha-bdd"
},
"version": "1.1.1"
}