@bitty/pipe
A pipe function to perform function composition in LTR (Left To Right) direction.
Last updated 5 days ago by vitorluizc .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @bitty/pipe 
SYNC missed versions from official npm registry.

@bitty/pipe

Bundle minified size Bundle minified and gzipped size

A pipe function to perform function composition in LTR (Left-To-Right) direction.

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

  • ⚡ Lightweight:

    • Weighs less than 0.3KB (min + gzip).
    • 3x smaller than ramda.pipe.
    • 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/pipe --save

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

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/pipe"></script>

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

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

Getting Started

Import pipe from package and just compose your functions with it.

import pipe from '@bitty/pipe';

const resolveToNumber = pipe(
  (value: unknown) => typeof value === 'number' ? value : parseFloat(value),
  (value: number) => Number.isNaN(value) ? 0 : value,
);

resolveToNumber('12389');
//=> 12389

The first pipe argument is an arity N function, so you can receive more than one argument in the composition.

import pipe from '@bitty/pipe';

const fromTextToWords = (text: string, wordsToIgnore: string[] = []) =>
  text
    .trim()
    .split(/\s+/)
    .filter((word) => !wordsToIgnore.includes(word));

const formatToInitials = pipe(
  fromTextToWords,
  (words) => words.map((word) => word.charAt(0)),
  (initials) => initials.join('').toUpperCase(),
);

formatToInitials('abraão  william de santana ', ['de']);
//=> "AWS"

License

Released under MIT License.

Current Tags

  • 0.0.7                                ...           latest (5 days ago)
  • 0.0.5                                ...           pnpm-temp (2 months ago)

8 Versions

  • 0.0.7                                ...           5 days ago
  • 0.0.6                                ...           2 months ago
  • 0.0.5                                ...           2 months ago
  • 0.0.4                                ...           6 months ago
  • 0.0.3                                ...           6 months ago
  • 0.0.2                                ...           6 months ago
  • 0.0.1                                ...           6 months ago
  • 0.0.0                                ...           6 months ago
Maintainers (1)
Downloads
Today 9
This Week 22
This Month 22
Last Day 2
Last Week 0
Last Month 14
Dependencies (0)
None
Dev Dependencies (5)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |