@bitty/falsy
Falsy 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/falsy --save
yarn add @bitty/falsy
Installation from CDN
This module has a UMD bundle available through JSDelivr and Unpkg CDNs.
<script src="https://unpkg.com/@bitty/falsy"></script>
<script src="https://cdn.jsdelivr.net/npm/@bitty/falsy"></script>
<script>
console.log(isFalsy);
console.log(isFalsy(null));
</script>
Getting Stated
This module default exports isFalsy
, which is a predicate function that checks if value is falsy.
import isFalsy from '@bitty/pipe';
isFalsy();
isFalsy(null);
isFalsy(undefined);
isFalsy(0);
isFalsy(-0);
isFalsy(0n);
isFalsy(NaN);
isFalsy('');
isFalsy(false);
isFalsy('Not empty.');
We also exports NonFalsy
and Falsy
types.
-
Falsy
is simply an union of false
, void
, ''
, 0
, 0n
, null
and undefined
, types.
import { Falsy } from '@bitty/falsy';
let falsy: Falsy;
falsy = false;
falsy = undefined as void;
falsy = '';
falsy = 0;
falsy = 0n;
falsy = null;
falsy = undefined;
falsy = 1;
-
NonFalsy<T>
is a type helper that removes falsy types.
import { NonFalsy } from '@bitty/falsy';
type Value = 0 | 1 | 2;
const value: NonFalsy<Value> = 0;
License
Released under MIT License.