1.0.4 • Published 6 years ago

c-e v1.0.4

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

c-e

Making custom error classes

Build Status NPM version

Install

npm i c-e

Usage

const ce = require('c-e');

const CustomError = ce();
const NestedError = ce('NestedError', CustomError);

CustomError.name === 'CustomError';         // true
NestedError.name === 'NestedError';         // true
new CustomError().name === 'CustomError';   // true
new NestedError().name === 'NestedError';   // true
new NestedError('test').message === 'test'; // true
new NestedError() instanceof Error;         // true
new NestedError() instanceof CustomError;   // true
new NestedError() instanceof NestedError;   // true

const MyError = ce('MyError', Error, function(a, b){
    this.message = `${a + b}`;
    this.a = a;
    this.b = b;
});
new MyError(1, 2).message === '3'; // true
new MyError(1, 2).a === 1;         // true
new MyError(1, 2).b === 2;         // true

License

MIT