@xylabs/assert
TypeScript icon, indicating that this package has built-in type declarations

3.1.8 • Public • Published

logo

@xylabs/assert

npm-badge npm-downloads-badge jsdelivr-badge npm-license-badge socket-badge

XY Labs generalized Javascript library

Table of Contents

Description

Common Javascript code that is used throughout XYO projects that use React.

Install

Using npm:

npm i --save @xylabs/assert

Using yarn:

yarn add @xylabs/assert

Usage

The assertEx function is a utility function for simple null/undefined checks for variables. It evaluates an expression for truthiness and throws an error if the expression is false.

Here are some examples of how to use assertEx in different scenarios:

  • Basic usage:

    import { assertEx } from '@xylabs/assert';
    
    const value = getValue(); // This is a function that may return null or undefined
    assertEx(value); // Throws an AssertExError with a default message if value is null or undefined
  • Using with a custom error message:

    import { assertEx } from '@xylabs/assert';
    
    const value = getValue(); // This function may return null or undefined
    assertEx(value, () => 'Dynamic error message based on some conditions'); // Throws an AssertExError with a dynamic message if value is null or undefined

Maintainers

License

See the LICENSE file for license details

Credits

Made with 🔥and ❄️ by XY Labs

Package Sidebar

Install

npm i @xylabs/assert

Homepage

xylabs.com

Weekly Downloads

12,879

Version

3.1.8

License

LGPL-3.0-only

Unpacked Size

33 kB

Total Files

24

Last publish

Collaborators

  • donaldparkerxy
  • jonesmac
  • joelbcarter
  • xyo
  • jordantrouw
  • rphansen91
  • ricardo.alcazar