jif

1.0.1 • Public • Published

jif NPM version Downloads

Information

  • Dead simple ternary or if/else replacement.
  • All arguments (conditions, ifTrue, and ifFalse) can be either a value or a function which returns a value.
  • Super useful for cleaning up JSX, which doesn't allow use of if/else.

Install

npm install jif --save

jif(condition[, ifTrue, ifFalse])

ES6

import jif from 'jif'
 
const truthy = true
const falsey = false
 
// lets get started with some primitives...
jif(truthy, 123, 456) // 123
jif(falsey, 123, 456) // 456
 
// and now some functions!
jif(truthy, () => 123) // 123
jif(falsey, () => 123) // undefined

ES5

var jif = require('jif');
 
var truthy = true;
var falsey = false;
 
// lets get started with some primitives...
jif(truthy, 123, 456); // 123
jif(falsey, 123, 456); // 456
 
// and now some functions!
jif(truthy, function(){
  return 123;
}); // 123
jif(falsey, function(){
  return 123;
}); // undefined

Package Sidebar

Install

npm i jif

Weekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • fractal
  • yocontra