A collection of common runtime predicates that TypeScript actually understands.
npm install aintA collection of common runtime predicates that TypeScript actually understands.
 
#### Features
- Simple API;
- Extensive tests;
- Isomorphic library, works on the browser or Node.js.
``bash`
npm install aint
#### Requirements
- Node.js v.14+
`typescript
import { isNotNull } from 'aint';
// given an array containing null and number values
const array = [1, 2, null]; // ts infers Array
// ...remove null values by using isNotNull
const arrayWithoutNull = array.filter(isNotNull); // ts infers Array
`
- isNotEmptyArray
- isNotEmptyString
- isNotNull
- isNotUndefined
- isNotNullish
It's easy to perform a check using lodash or vanilla JavaScript, e.g.
`javascript`
const array = [1, 2, null].filter(Boolean);
The example above will filter out the null value as expected (because null is considered to be faulty).
However, TypeScript will NOT _infer_ the correct type [playground link]. It will _understand_ the type of array as being Array instead of Array.
aint` provides a simple API to test for predicates, while making TypeScript _understand_.
Source code contributions are most welcome, as long as the linter is satisfied.
#### We are hiring
Causaly is building the world's largest biomedical knowledge platform, using technologies such as TypeScript, React and Node.js. Find out more about our openings at https://apply.workable.com/causaly/.
MIT