1.1.3 ā€¢ Published 6 years ago

compose-tiny v1.1.3

Weekly downloads
774
License
MIT
Repository
github
Last release
6 years ago

CircleCI Codecov npm bundle size code style: prettier

Function composition is an act or mechanism to combine simple functions to build more complicated ones.

compose-tiny aims to provide a simple function for composition at the smallest possible size and the fasted possible speed. It's typescript friendly too!

Installation

npm install compose-tiny

Usage

const compose = require('compose-tiny');

const add = x => x + 2;
const sqr = x => x ** 2;

const blastOff = compose(
  x => `šŸš€ ${x} šŸš€`
  sqr,
  add2
);

blastOff(2);

Output:

šŸš€ 16 šŸš€

Multiple Arguments

The first function in the composition can take multiple arguments.

const compose = require('compose-tiny');

const add = x => x + 2;
const sqr = x => x ** 2;

const blastOff = compose(
  sqr,
  add2,
  (x, y, z) => (x + y) * z
);

blastOff(1, 2, 4);

Performance

NOTE: bundlephobia includes all files in package

NAMEOPS/SECRELATIVE MARGIN OF ERRORSAMPLE SIZEBUNDLE SIZE
compose-tiny1108,413Ā± 0.72%187(112B)https://bundlephobia.com/result?p=compose-tiny
squad105,070Ā± 0.62%185(517B)https://bundlephobia.com/result?p=squad
just-compose46,964Ā± 1.88%181(334B)https://bundlephobia.com/result?p=just-compose
chain-function22,556Ā± 0.50%187(341B)https://bundlephobia.com/result?p=chain-function
compose-function20,817Ā± 0.49%186(1.2kB)https://bundlephobia.com/result?p=compose-function
fj-compose8,581Ā± 0.61%184(334B)https://bundlephobia.com/result?p=fj-compose
compose-funcs356Ā± 1.58%176(594B)https://bundlephobia.com/result?p=compose-funcs

To rerun this benchmark

node benchmark
1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago