1.1.2 • Published 7 months ago

@blackglory/errors v1.1.2

Weekly downloads
399
License
MIT
Repository
github
Last release
7 months ago

errors

Common errors.

Install

npm install --save @blackglory/errors
# or
yarn add @blackglory/errors

API

Interfaces

type CustomErrorConstructor<T extends CustomError = CustomError> = new (message?: string) => T

interface SerializableError {
  name: string
  message: string
  stack: string | null
}

CustomError

class CustomError extends Error {}

ExpectedError

class ExpectedError extends CustomError {}

AssertionError

class AssertionError extends CustomError {}

normalize

function normalize(err: Error): SerializableError

assert

/**
 * @throws {AssertionError}
 */
function assert(condition: unknown, message?: string): asserts condition

refute

/**
 * @throws {ExpectedError}
 */
function refute(condition: unknown, message?: string): void

A negative assertion, expects the condition to be falsy.