Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

normalize-exception

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

normalize-exception - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

39

build/src/main.d.ts
/**
* Normalize exception/error.
*
* In JavaScript, one can `throw` any value including strings, objects (like
* `{ message: "..." }`) or even `undefined`. This normalizes any exception
* to an `Error` instance.
*
* It also fixes any missing or invalid error properties: `name`, `message`,
* `stack`, `cause`, `errors`.
*
* @example
* ```js
* import normalizeException from 'normalize-exception'
*
* try {
* throw null
* } catch (error) {
* const normalizedError = normalizeException(error)
* console.log(normalizedError) // Error: null
* // Without `normalizeException()`, this would throw
* console.log(normalizedError.name)
* }
*
* console.log(normalizeException('message')) // Error: message
*
* console.log(normalizeException({ name: 'TypeError', message: 'message' })) // TypeError: message
*
* const error = new TypeError('message')
* console.log(error.stack) // TypeError: message
*
* // `error.stack` is cached, so it does not update
* error.message += ' otherMessage'
* console.log(error.stack) // TypeError: message
*
* const normalizedError = normalizeException(error)
* console.log(normalizedError.stack) // TypeError: message otherMessage
*
* const error = new Error('message', { cause: 'innerError' })
* console.log(error.cause instanceof Error) // false
*
* const normalizedError = normalizeException(error)
* console.log(normalizedError.cause instanceof Error) // true
* console.log(normalizedError.cause) // Error: innerError
* ```
*/
export default function normalizeException(error: any): Error

2

package.json
{
"name": "normalize-exception",
"version": "1.0.0",
"version": "1.0.1",
"type": "module",

@@ -5,0 +5,0 @@ "exports": "./build/src/main.js",

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