Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bitty/predicate

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bitty/predicate

Predicate helper functions and types for TypeScript.

  • 0.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-16.67%
Maintainers
1
Weekly downloads
 
Created
Source

@bitty/predicate

Bundle minified size Bundle minified and gzipped size

Predicate and Refinement types for TypeScript.

  • 🏷 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/predicate --save

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

Getting Stated

It exports Predicate and Refinement types.

  • Predicate is a function that receives a value and returns a boolean.

    import type { Predicate } from '@bitty/predicate';
    
    function checkAll<T = unknown>(predicates: Predicate<T>[]): Predicate<T> {
      return (value) => predicates.every((predicate) => predicate(value));
    }
    
  • Refinement is similar to Predicate, but uses TypeScript is type guard.

    import { Refinement } from '@bitty/predicate';
    
    const isNumber: Refinement<unknown, number> = (value) =>
      Number.isFinite(value);
    //=> Was typed as `(value: unknown) => value is number`.
    
    const value: number | string = Math.random() > 0.5 ? 100 : 'A text.';
    
    if (isNumber(value)) {
      console.log(value.toFixed(2));
      //=> Okay, because type of `value` was refined to `number`.
    }
    console.log(value.toFixed(2));
    //=> Property 'toFixed' does not exist on type 'string | number'.
    //     Property 'toFixed' does not exist on type 'string'.
    

License

Released under MIT License.

Keywords

FAQs

Package last updated on 14 Jul 2020

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc