npm

Need private packages and team management tools?Check out npm Orgs. »

c-e

1.0.4 • Public • Published

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 = `${+ 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

Keywords

install

npm i c-e

Downloadsweekly downloads

4

version

1.0.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability