This package has been deprecated

Author message:

see builtin modules

@kingjs/assert

1.0.11 • Public • Published

@kingjs/assert

Throw an exception if a condition fails.

Usage

Assert a condition in your code or test like this:

var assert = require('@kingjs/assert');

assert(0 == 1);

throws:

"An assertion failed."

Simply fail all the time like this:

var assert = require('@kingjs/assert');

assert();

throws:

"An assertion failed."

Provide a more descriptive error message like this:

var assert = require('@kingjs/assert');

var expected = 0;
var actual = 1;

assert(
  actual == expected,
  "Expected '" + expected + "' but actually got '" + actual + "'."
);

throws:

"Expected '0' but actually got '1'."

API

declare function assert(condition?: boolean, message?: string);

Parameters

condition: If false (or omitted), throws an exception.

message: Message to throw if condition fails, else will throw "An assertion failed.".

Install

With npm installed, run

$ npm install @kingjs/assert

Acknowledgments

assert is old as dirt and just as underappreciated.

License

MIT

Analytics

/@kingjs/assert/

    Package Sidebar

    Install

    npm i @kingjs/assert

    Weekly Downloads

    17

    Version

    1.0.11

    License

    MIT

    Unpacked Size

    2.96 kB

    Total Files

    4

    Last publish

    Collaborators

    • kingces95