Socket
Socket
Sign inDemoInstall

@bitty/falsy

Package Overview
Dependencies
0
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @bitty/falsy

Falsy helper functions and types for TypeScript.


Version published
Weekly downloads
12
decreased by-14.29%
Maintainers
2
Install size
15.7 kB
Created
Weekly downloads
 

Readme

Source

@bitty/falsy

Bundle minified size Bundle minified and gzipped size

Falsy helper functions and types for TypeScript.

  • 📦 Distributions in ESM, CommonJS, UMD and UMD minified formats.

  • ⚡ Lightweight:

    • Weighs less than 0.2KB (min + gzip).
    • Tree-shakeable.
    • Side-effects free.
  • 🔋 Bateries included:

    • No dependencies.
    • Its not based on newer browser's APIs or es2015+ features.
  • 🏷 Safe:

    • JSDocs and type declarations for IDEs and editor's autocomplete/intellisense.
    • Made with TypeScript as strict as possible.
    • Unit tests with AVA.

Installation

This library is published in the NPM registry and can be installed using any compatible package manager.

npm install @bitty/falsy --save

# For Yarn, use the command below.
yarn add @bitty/falsy

Installation from CDN

This module has a UMD bundle available through JSDelivr and Unpkg CDNs.

<!-- For UNPKG use the code below. -->
<script src="https://unpkg.com/@bitty/falsy"></script>

<!-- For JSDelivr use the code below. -->
<script src="https://cdn.jsdelivr.net/npm/@bitty/falsy"></script>

<script>
  // UMD module is exposed through the "isFalsy" global function.
  console.log(isFalsy);
  //=> "[Function: isFalsy]"

  console.log(isFalsy(null));
  //=> true
</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);
//=> true

isFalsy('Not empty.');
//=> false

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;
    //=> throws "Type '1' is not assignable to type 'Falsy'.".
    
  • 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;
    //=> throws "Type '0' is not assignable to type '1 | 2'.".
    

License

Released under MIT License.

Keywords

FAQs

Last updated on 09 Jan 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc