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

Readme

Keywords

Package Sidebar

Install

npm i c-e

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

4.37 kB

Total Files

8

Last publish

Collaborators

  • astur