Skip to content

causaly/aint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ad385b5 · Mar 10, 2025

History

71 Commits
Jan 22, 2025
Oct 25, 2024
Jan 22, 2025
May 11, 2023
Dec 21, 2021
Dec 21, 2021
Dec 21, 2021
Dec 21, 2021
Jul 10, 2024
Dec 24, 2021
Dec 24, 2021
Oct 25, 2024
Dec 21, 2021
Jan 22, 2025
Dec 23, 2021
Jun 20, 2022
Jan 22, 2025
Mar 10, 2025
Jan 22, 2025
Oct 25, 2024
Jan 22, 2025

Repository files navigation

aint

A collection of common runtime predicates that TypeScript actually understands.

Build Status npm version

Features

  • Simple API;
  • Extensive tests;
  • Isomorphic library, works on the browser or Node.js.

Installation

npm install aint

Requirements

  • Node.js v.14+

Quick start

import { isNotNull } from 'aint';

// given an array containing null and number values
const array = [1, 2, null]; // ts infers Array<null | number>

// ...remove null values by using isNotNull
const arrayWithoutNull = array.filter(isNotNull); // ts infers Array<number>

API

Motivation

It's easy to perform a check using lodash or vanilla JavaScript, e.g.

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<null | number> instead of Array<number>.

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