README
Welcome to switch-case 👋
A functional approach to switches
Install
npm install @omgimalexis/switch-case
Usage
const switchCase = require('switch-case').default;
// Returns selected case
{
const case = 'a';
const result = await switchCase({
a: 1,
b: 2,
default: 3
}, case);
// result = 1
}
// Returns default case when selected isn't found
{
const case = 'z';
const result = await switchCase({
a: 1,
b: 2,
default: 3
}, case);
// result = 3
}
// Allows functions
{
const case = 'a';
const result = await switchCase({
a: () => 1,
b: 2,
default: 3
}, case);
// result = 1
}
// Allows async functions
{
const case = 'a';
const result = await switchCase({
a: async () => 1,
b: 2,
default: 3
}, case);
// result = 1
}
Run tests
npm run test
Author
👤 Alexis Tyler xo@wvvw.me (https://wvvw.me/)
- Website: https://wvvw.me
- Twitter: @OmgImAlexis
- Github: @OmgImAlexis
🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!