if-chain

0.1.0 • Public • Published

if-chain

Write conditions in functional style 👍

Examples:

const chain = require('if-chain');

const data = [1, 2, 3, 4, 5, 6];

const condition = true;

const thenFn = (data) => data.filter(el => el % 2)
const elseFn = (data) => data;
// if no then or else provided, data will be returned


chain(data)
    .if(condition, thenFn, elseFn)
    .chain((data) => data.map(n => n * 2)) // chains additional transformation
    .end() // returns result

You can use function as a condition as well:

chain(data)
    .if((data) => isArray(data), thenFn, elseFn)

Readme

Keywords

Package Sidebar

Install

npm i if-chain

Weekly Downloads

2

Version

0.1.0

License

ISC

Unpacked Size

17.7 kB

Total Files

10

Last publish

Collaborators

  • komarnitskyi