Fallback when a value is not Function
.
Via NPM:
npm install fnvl
Via Yarn:
yarn add fnvl
const fnvl = require('fnvl');
function someFn() {
// ...
}
// When a value is not Function, it will return fallback value.
let a = fnvl(10, 'x'); // a = 'x'
let b = fnvl([1, 2, 3], console.log); // b = console.log
// When a value is Function, it will return that value.
let c = fnvl(console.error, 1); // c = console.error
let d = fnvl(someFn, () => {}); // d = someFn
A main value.
A fallback value.