@longlast/pipe
v0.0.4
Published
Composes functions left-to-right
Readme
@longlast/pipe
Composes functions left-to-right.
Install
Choose your favorite package manager:
npm add @longlast/pipe
pnpm add @longlast/pipe
yarn add @longlast/pipeUse
import {pipe} from "@longlast/pipe";
const split = (pattern) => (str) => str.split(pattern);
const map = (f) => (array) => array.map((elem) => f(elem));
const mapAt = (idx, f) => (array) => array.map((e, i) => i === idx ? f(e) : e);
const join = (delim) => (strs) => strs.join(delim);
const toUpperCase = (s) => s.toUpperCase();
const capitalize = pipe(
split(""),
mapAt(0, toUpperCase),
join(""),
)
const pascalCase = pipe(
split(/\W+/),
map(capitalize),
join(""),
);
pascalCase("chunky-bacon") // => "ChunkyBacon"