Socket
Socket
Sign inDemoInstall

@causaly/isnt

Package Overview
Dependencies
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@causaly/isnt

A collection of common runtime predicates that TypeScript actually understands.


Version published
Weekly downloads
0
Maintainers
2
Weekly downloads
 
Created
Source

@causaly/isnt

A collection of common runtime predicates that TypeScript actually understands.

Build Status

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

Installation

npm install @causaly/isnt
Requirements
  • Node.js v.14+

Quick start

import { isNotNull } from '@causaly/isnt';

// 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

  • isNotEmptyArray
  • isNotEmptyString
  • isNotNull
  • isNotUndefined

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<null>.

@causaly/isnt 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

FAQs

Package last updated on 24 Dec 2021

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc