
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
error-class
Advanced tools
This module provides typed errors that closely emulate the native Error
class to a pedantic degree.
$ npm install error-class
The default export is a function that accepts one argument, the name of the typed error.
import errorClass from 'error-class'
const HumanError = errorClass('HumanError')
const hungryError = new HumanError(`I'm hungry!`)
hungryError.name // 'HumanError'
hungryError.message // `I'm hungry!`
hungryError.stack // Platform-specific error stack trace.
hungryError.hasOwnProperty('name') // false (!)
hungryError.hasOwnProperty('message') // true
hungryError.hasOwnProperty('stack') // true
// Just like native errors, it doesn't require using `new`.
const thirstyError = HumanError(`I'm thirsty!`)
Object.keys(thirstyError).length === 0 // True, all properties are non-enumerable.
Object.keys(Object.getPrototypeOf(instance)).length === 0 // Prototype non-enumerable.
thirstyError.constructor === HumanError // True.
thirstyError.constructor.name === 'HumanError' // True.
thirstyError instanceof Error // True, errors inherit from native `Error` class.
thirstyError instanceof HumanError // Also true, of course.
This software is licensed under the MIT License.
FAQs
Typed errors that closely emulate the native Error class.
The npm package error-class receives a total of 1,637 weekly downloads. As such, error-class popularity was classified as popular.
We found that error-class demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.