README
Ternary Function
use the result if it's truthy of falsy
Usage
import ternary from 'ternary-function';
var result = ternary(10+5, t => t*2, f => f+10) // will return "30", because 10+5 (15) is "truthy"
var result = ternary(
localStorage.getItem('abc'), // if it returns a truthy value...
t => JSON.parse(t), // the returned value will be JSON parsed,...
null // but it it's falsy, it will return null.
)
/**
* Ternary function will automatically return undefined if no falsy value is set
*/
var result = ternary(10-10, t => t*2); // will return "undefined", becauset 10-10 (0) is "falsy"
var result = ternary(
localStorage.getItem('xyz'), // if it returns a truthy value...
t => JSON.parse(t) // the returned value will be JSON parsed,...
) // but it it's falsy, it will return undefined.
Installation
- Install it using npm or yarn
npm install --save ternary-function
yarn add ternary-function
- Import it
import ternary from 'ternary-function'
- Use it 😄