npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

error-x

v3.1.2

Published

Create custom Javascript Error objects.

Downloads

301

Readme

error-x

Create custom Javascript Error objects.

module.exports

Want to create your own Error objects, this module will allow you to do just that. It ships with all the standard ErrorConstructor objects already created for you. Why? Well, these offer some improvements over the native versions.

  • They have a toJSON method and so they can be serialised.
  • They have a standardised stack property, using error-stack-parser messages and stacks are parsed and then re-formatted.
  • They have a frames property which is an array of the parsed stack message, so you have easy access to the information.

Kind: Exported member

module.exports.AssertionErrorConstructor ⇐ Error

Kind: static class of module.exports
Extends: Error

new AssertionErrorConstructor_new([message])

Error constructor for test and validation frameworks that implement the standardized AssertionError specification.

| Param | Type | Description | | --------- | ------------------- | -------------------------------- | | [message] | Object | Need to document the properties. |

module.exports.ErrorConstructor ⇐ Error

Kind: static class of module.exports
Extends: Error

new ErrorConstructor([message])

The Error constructor creates an error object.

| Param | Type | Description | | --------- | ------------------- | ---------------------------------------- | | [message] | string | Human-readable description of the error. |

module.exports.EvalErrorConstructor ⇐ EvalError

Kind: static class of module.exports
Extends: EvalError

new EvalErrorConstructor_new([message])

Creates an instance representing an error that occurs regarding the global function eval().

| Param | Type | Description | | --------- | ------------------- | ---------------------------------------- | | [message] | string | Human-readable description of the error. |

module.exports.InternalErrorConstructor ⇐ Error

Kind: static class of module.exports
Extends: Error

new InternalErrorConstructor_new([message])

The InternalError object indicates an error that occurred internally in the JavaScript engine. For example: "InternalErrorConstructor: too much recursion".

| Param | Type | Description | | --------- | ------------------- | ---------------------------------------- | | [message] | string | Human-readable description of the error. |

module.exports.RangeErrorConstructor ⇐ RangeError

Kind: static class of module.exports
Extends: RangeError

new RangeErrorConstructor_new()

Creates an instance representing an error that occurs when a numeric variable or parameter is outside of its valid range.

| Type | Description | | ------------------- | -------------------------------------------------- | | string | [message] Human-readable description of the error. |

module.exports.ReferenceErrorConstructor ⇐ ReferenceError

Kind: static class of module.exports
Extends: ReferenceError

new ReferenceErrorConstructor_new([message])

Creates an instance representing an error that occurs when de-referencing an invalid reference

| Param | Type | Description | | --------- | ------------------- | ---------------------------------------- | | [message] | string | Human-readable description of the error. |

module.exports.SyntaxErrorConstructor ⇐ SyntaError

Kind: static class of module.exports
Extends: SyntaError

new SyntaxErrorConstructor([message])

Creates an instance representing a syntax error that occurs while parsing code in eval().

| Param | Type | Description | | --------- | ------------------- | ---------------------------------------- | | [message] | string | Human-readable description of the error. |

module.exports.TypeErrorConstructor ⇐ TypeError

Kind: static class of module.exports
Extends: TypeError

new TypeErrorConstructor([message])

Creates an instance representing an error that occurs when a variable or parameter is not of a valid type.

| Param | Type | Description | | --------- | ------------------- | ---------------------------------------- | | [message] | string | Human-readable description of the error. |

module.exports.URIErrorConstructor ⇐ URIError

Kind: static class of module.exports
Extends: URIError

new URIErrorConstructor([message])

Creates an instance representing an error that occurs when encodeURI() or decodeURI() are passed invalid parameters.

| Param | Type | Description | | --------- | ------------------- | ---------------------------------------- | | [message] | string | Human-readable description of the error. |

module.exports.supportsAllConstructors : boolean

Indicates if the Javascript engine supports subclassing of all Error types. If true then all are supported, if false (only very old browsers IE6) then only Error is supported.

Kind: static property of module.exports

module.exports.create([name], [ECTR])function

Creates a custom Error constructor. Will use ErrorConstructor if argument is not a valid constructor.

Kind: static method of module.exports
Returns: function - The custom Error constructor.

| Param | Type | Default | Description | | ------ | --------------------- | ------------------------------------------ | ------------------------------ | | [name] | string | "'Error'" | The name for the custom Error. | | [ECTR] | function | Error | Error constructor to be used. |

Example

import * as errorX from 'error-x';

const MyError = errorX.create('MyError'); // Uses `Error` as no constructor
// specified.
const err = new MyError('somethingHappened');

JSON.stringify(err); // => see below.
// A serialised error, showing the custom error object's structure and
// format
// {
//   "name": "MyError",
//   "message": "somethingHappened",
//   "frames": [
//     {
//       "functionName": "Y.x",
//       "fileName": "http://fiddle.jshell.net/2k5x5dj8/183/show/",
//       "lineNumber": 65,
//       "columnNumber": 13,
//       "source": "Y.x (http://fiddle.jshell.net/2k5x5dj8/183/show/:65:13)"
//     },
//     {
//       "functionName": "window.onload",
//       "fileName": "http://fiddle.jshell.net/2k5x5dj8/183/show/",
//       "lineNumber": 73,
//       "columnNumber": 3,
//       "source": "window.onload (http://fiddle.jshell.net/2k5x5dj8/183/show/:73:3)"
//     }
//   ],
//   "stack": "MyError\n    Y.x()@http://fiddle.jshell.net/2k5x5dj8/183/show/:65:13\n    window.onload()@http://fiddle.jshell.net/2k5x5dj8/183/show/:73:3"
// }

module.exports.isErrorConstructor(value)boolean

Determine whether or not a given value is an Error type.

Kind: static method of module.exports
Returns: boolean - Returns true if value is an Error type, else false.

| Param | Type | Description | | ----- | --------------- | ------------------------ | | value | * | The object to be tested. |