Skip to content

🔢 Function to choose comparing with a value. Like switch, but you don't need an IIFE.

License

Notifications You must be signed in to change notification settings

batata-frita/vybor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vybor - выбор

Build Status npm version

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'

See also

License

See License

About

🔢 Function to choose comparing with a value. Like switch, but you don't need an IIFE.

Resources

License

Stars

Watchers

Forks

Packages

No packages published