UNPKG

ultrax

Version:

UltraX Package is a unique package that allows you to create cool things using simple functions and events.

24 lines (20 loc) 435 B
const kCode = Symbol('code'); function createError(Base) { return class err extends Base { constructor(key, ...args) { super(...args); this[kCode] = key; if (Error.captureStackTrace) Error.captureStackTrace(this, err); } get name() { return `${super.name} [${this[kCode]}]`; } get code() { return this[kCode]; } }; } module.exports = { Error: createError(Error), TypeError: createError(TypeError), };