vybor
v0.1.0
Published
Function to choose comparing with a value. Like `switch`, but you don't need an IIFE
Downloads
2
Readme
vybor - выбор
Function to choose comparing with a value. Like switch
, but you don't need an IIFE.
npm add vybor
import выбор from 'vybor'
console.log(выбор('jupiter')(
'mars', 'red',
'jupiter', 'green',
'saturn', 'purple'
)) // => 'green'
If you want to set a fallback option if none match, you can just set a fallback value as a second argument of the first function:
выбор('pluto', 'probably not a planet')(
'mars', 'red',
'jupiter', 'green',
'saturn', 'purple'
) // => 'probably not a planet'
Mind that this means that if the selected is explicitly set to be undefined
, it will return the fallback option:
выбор('mars', 'probably not a planet')(
'mars', undefined,
'jupiter', 'green',
'saturn', 'purple'
) // => 'probably not a planet'