0.1.0 • Published 5 years ago

if-chain v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

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)