Utilities for preconditions and assertions for TypeScript and JavaScript.
npm i @dozerg/condition
import { isNonNull, assertNonNull } from '@dozerg/condition';
function foo(p?: string) {
assertNonNull(p);
p.length; // OK, p is string
// ...
const a = [1, undefined, 2]; // a is (number | undefined)[]
const b = a.filter(isNonNull); // b is [1, 2], i.e. number[]
// ...
}
- assertIsBigint
- assertIsBoolean
- assertIsClass
- assertIsNumber
- assertIsString
- assertNonNull
- assertTrue
- assertIsObject
- isBigint
- isBoolean
- isClass
- isNonNull
- isNumber
- isString
- isObject
MIT © Zhao DAI [email protected]