/deno-assert

Primary LanguageTypeScript

assert

JSR CI

A simple assertion function.

Usage

import assert from '@quentinadam/assert';

assert(true); // doesn't throw

assert(false); // throws an AssertionError

assert(false, 'message'); // throws an AssertionError with a custom error message

assert(false, new Error('message')); // throws a custom Error

const value: string | undefined = 'hello';
assert(value !== undefined); // narrows the type of value to string;
value.toUpperCase(); // works