New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

errate

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

errate

Converts a value into an Error of the specified type.

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2K
decreased by-30.8%
Maintainers
1
Weekly downloads
 
Created
Source

errate

Converts a value into an Error of the specified type.

Installation

Requires Node.js 6.0.0 or above.

npm i errate

API

The module exports a single function.

Parameters

  1. Optional: e (string, Error object, boolean, or null): The error message, or an existing Error object. If null or a boolean, the returned Error will have no message.
  2. Optional: Cls (Error class): The desired class of the returned Error (such as TypeError or RangeError). Defaults to Error.
  3. Optional: Object argument:
    • defaultMessage (string): The first argument that will be provided to the constructor if an Error object is being created (i.e. if e is true or “falsey”).
    • forceClass (boolean): If set to true, instances of other Error classes will be converted to instances of Cls. If set to false, Cls will only be used to wrap string errors. Defaults to true.

Return Value

An Error of the specified class.

Examples

Default Class With Message

const errate = require('errate')

const err = errate('Message')
err instanceof Error // true
err.message // 'Message'

Default Class Without Message

const errate = require('errate')

const err = errate()
err instanceof Error // true
err.message // ''

Error Subclass With Message

const errate = require('errate')

const err = errate('Message', TypeError)
err instanceof TypeError // true
err.message // 'Message'

Error Subclass Without Message

const errate = require('errate')

const err = errate(TypeError)
err instanceof TypeError // true
err.message // ''

Error Class Conversion

const errate = require('errate')

const err = errate(new TypeError('Message'), RangeError)
err instanceof RangeError // true
err.message // 'Message'

Keywords

FAQs

Package last updated on 12 Oct 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc