@bitty/pipe
A pipe function to perform function composition in LTR (Left-To-Right) direction.
Installation
This library is published in the NPM registry and can be installed using any compatible package manager.
npm install @bitty/pipe --save
yarn add @bitty/pipe
Installation from CDN
This module has a UMD bundle available through JSDelivr and Unpkg CDNs.
<script src="https://unpkg.com/@bitty/pipe"></script>
<script src="https://cdn.jsdelivr.net/npm/@bitty/pipe"></script>
<script>
console.log(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');
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']);
License
Released under MIT License.