@dozerg/condition
v1.0.8
Published
Preconditions utility for TypeScript and JavaScript.
Downloads
7,920
Maintainers
Readme
Condition
Utilities for preconditions and assertions for TypeScript and JavaScript.
Install
npm i @dozerg/condition
Usage
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[]
// ...
}
APIs
- assertIsBigint
- assertIsBoolean
- assertIsClass
- assertIsNumber
- assertIsString
- assertNonNull
- assertTrue
- assertIsObject
- isBigint
- isBoolean
- isClass
- isNonNull
- isNumber
- isString
- isObject
License
MIT © Zhao DAI [email protected]