Skip to content

komarnitskyi/if-chain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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)

About

Write conditions in functional style ๐Ÿ‘

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published