Error Class
This module provides typed errors that closely emulate the native Error
class to a pedantic degree.
$ npm install error-class
Usage
The default export is a function that accepts only one argument, the name of the typed error.
const errorClass = const SpecialError = const instance = 'foobar'instancemessage // 'foobar'
Details
const errorClass = const HumanError = const hungryError = 'I\'m hungry!'hungryErrormessage // 'I'm hungry!'hungryErrorstack // Platform-specific error stack trace.hungryError // falsehungryError // truehungryError // true // Just like native errors, it doesn't require using `new`.const thirstyError = Objectlength === 0 // True, all properties are non-enumerable.Objectlength === 0 // Prototype non-enumerable.thirstyErrorconstructor === HumanError // True.thirstyError instanceof Error // True, errors inherit from native `Error` class.thirstyError instanceof HumanError // Also true, of course.
License
This software is licensed under the MIT License.