GitXplorerGitXplorer
k

if-chain

public
7 stars
0 forks
3 issues

Commits

List of commits on branch master.
Verified
b39a6dd00ad6ff9889e880eb706ec272ac77a78c

Update README.md

kkomarnitskyi committed 5 years ago
Unverified
2ed8be5848cbdceb2728caaf6d7eb9109b2220d1

Update README

kkomarnitskyi committed 5 years ago
Unverified
e0a88dec47f05cad34863676ad1425cba8581a4a

Merge branch 'master' of https://github.com/komarnitskyi/if-chain

kkomarnitskyi committed 5 years ago
Unverified
76075f6e9c30ac1fd94ac44141ea07a12e9ae216

Add travis file

kkomarnitskyi committed 5 years ago
Unverified
e3d11509c9943b6f7ca501e94345082ed473b4eb

Add travis file

kkomarnitskyi committed 5 years ago
Unverified
de93039943c0f7fd045bbd07ecb77f4d7c941d55

Changed README, add test npm script

kkomarnitskyi committed 5 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)