0.0.7 ā¢ Published 1 year ago
@omgimalexis/switch-case v0.0.7
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!