Install with npm or yarn via
yarn add cond-flow
npm i cond-flow
const value =// value === 'true'
You can disable strict checking by passing options as the second argument:
const value =// value === 'truthy'
Also works nicely with React components as you can have the values lazily evaluated by wrapping it in a function:
import cond from 'cond-flow'const Component = isDisabled isNew isLoading<></>
As all predicates have to be evaluated before the right branch can be chosen, it can have a negative performance impact if you rely on heavy computations here. It's best have simple booleans and resort to
_.cond for complex use cases.
If you find this useful or would like to add features, feel free to clone the repository and open a PR.