@bitty/nullish
Nullish helper functions and types for TypeScript.
Installation
This library is published in the NPM registry and can be installed using any compatible package manager.
npm install @bitty/nullish --save
yarn add @bitty/nullish
Installation from CDN
This module has a UMD bundle available through JSDelivr and Unpkg CDNs.
<script src="https://unpkg.com/@bitty/nullish"></script>
<script src="https://cdn.jsdelivr.net/npm/@bitty/nullish"></script>
<script>
console.log(isNullish);
console.log(isNullish(null));
</script>
Getting Stated
This module default exports isNullish
, which is a predicate function that checks if value is nullish.
import isNullish from '@bitty/pipe';
isNullish(null);
isNullish(undefined);
isNullish(undefined as void);
isNullish(NaN);
We also exports NonNullish
and Nullish
types.
-
Nullish
is simply an union of null
, void
and undefined
types.
import { Nullish } from '@bitty/nullish';
let nullish: Nullish;
nullish = null;
nullish = undefined;
nullish = undefined as void;
nullish = false;
-
NonNullish<T>
is a type helper that removes nullish types.
import { NonNullish } from '@bitty/nullish';
type Value = string | null | undefined;
const value: NonNullish<Value> = null;
License
Released under MIT License.