Assertion functions for basic JS data types. Unopinionated, simple, with no cruft.
npm i assert-functions
Import any single assertion you need. Available assertions are same as the basic JS data types -- assertArray
, assertBigInt
, assertBoolean
, assertFunction
, assertNumber
, assertObject
, assertString
, assertSymbol
, assertUndefined
.
const { assertNumber, AssertionError } = require('assert-functions');
assertNumber(5);
try {
assertNumber("6");
} catch (e) {
if (e instanceof AssertionError) {
console.log('assertion error!');
}
}