README
What is this ?
Small package for handling nested ternary statements, allowing you to read your code better
Installation
npm i nested-ternary
Basic Usage
const nt = require('nested-ternary');
// or import nt from 'nested-ternary'
// lets model a simple number guessing game
const num = Math.ceil(Math.random() * 100); // 1 - 100
const guess = someUser.input;
// checks condition using key:cond in the object passed in
// returns key:t if true, key:f if false
// t/f can be objects themselves with keys cond,t & f
nt({
cond: guess === num,
t: 'winner',
f: {
cond: guess < num,
t: 'too low',
f: 'too high',
},
});
Advanced Usage (Lazy Loading)
sometimes you need to lazy load your values so that the complier does not compile them and return an error because of some missing attribute or function
const nt = require('nested-ternary');
//lets model an array of values coming from a stock exchange api
//lets assume that there will always be a name but value, prefix, suffix and format will be dynamic
const data = [
{
name: 'icorp'
value: 4,
prefix: '