@xutl/guard
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@xutl/guard

One eXtremely Useful Tool Library to facilitate dealing with Error objects in TypeScript.

Install

npm install --save-dev @xutl/guard

Usage

import { assert, equal, deep } from '@xutl/guard';

import { isError, assertError } from '@xutl/guard';
import { isSystemError, assertSystemError } from '@xutl/guard';
import { isAssertion, assertAssertion } from '@xutl/guard';

API

Assertion Functions

  • function assert(value: any, message?: string, cause?: any) : void
  • function equal(actual: any, expected: any, message?: string, cause?: any) : void
  • function deep(actual: any, expected: any, message?: string, cause?: any) : void

Error Types

  • type SystemError = Error & { code: string }
  • type Assertion = SystemError & { code : 'ERR_ASSERTION' }

Error Guards

  • function isError(value: any) : value is Error
  • function assertError(value: any) : asserts value is Error
  • function isSystemError(value: any) : value is SystemError
  • function assertSystemError(value: any) : asserts value is SystemError
  • function isAssertion(value: any) : value is Assertion
  • function assertAssertion(value: any) : asserts value is Assertion

License

Copyright 2022 xutl.es

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i @xutl/guard

    Homepage

    xutl.es

    Weekly Downloads

    0

    Version

    1.0.1

    License

    ISC

    Unpacked Size

    18.7 kB

    Total Files

    17

    Last publish

    Collaborators

    • pipobscure
    • xutl-dev