GitXplorerGitXplorer
k

if-chain

public
7 stars
0 forks
3 issues

Commits

List of commits on branch master.
Unverified
8c2ad98b0b2ba97fe5987cfaa235a2f4a12c3761

init

kkomarnitskyi committed 6 years ago

README

The README file for this repository.

if-chain Build Status

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)