Socket
Book a DemoInstallSign in
Socket

aint

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aint

A collection of common runtime predicates that TypeScript actually understands.

0.7.1
latest
Source
npmnpm
Version published
Weekly downloads
190
36.69%
Maintainers
0
Weekly downloads
 
Created
Source

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

Keywords

typescript

FAQs

Package last updated on 22 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.