https://github.com/causaly/aint
https://github.com/causaly/aint
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/causaly/aint
- Owner: causaly
- License: mit
- Created: 2021-12-21T13:31:09.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-10T15:26:02.000Z (over 1 year ago)
- Last Synced: 2025-06-03T07:19:31.595Z (about 1 year ago)
- Language: TypeScript
- Size: 430 KB
- Stars: 10
- Watchers: 11
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# aint
A collection of common runtime predicates that TypeScript actually understands.
[](https://github.com/causaly/aint/actions/workflows/ci.yml) [](https://www.npmjs.com/package/aint)
#### Features
- Simple API;
- Extensive tests;
- Isomorphic library, works on the browser or Node.js.
## Installation
```bash
npm install aint
```
#### Requirements
- Node.js v.14+
## Quick start
```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
```
## API
- [isNotEmptyArray](./lib/isNotEmptyArray.ts)
- [isNotEmptyString](./lib/isNotEmptyString.ts)
- [isNotNull](./lib/isNotNull.ts)
- [isNotUndefined](./lib/isNotUndefined.ts)
- [isNotNullish](./lib/isNotNullish.ts)
## Motivation
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](https://www.typescriptlang.org/play?#code/MYewdgzgLgBAhgJwXAnjAvDA2gRgDQwBMBYArgDbkC6AdAGYCW5UApggBQBCII5LcYAJQBuIA)]. 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_.
## Contribute
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/.
## License
MIT