0.0.7 ā€¢ Published 1 year ago

@omgimalexis/switch-case v0.0.7

Weekly downloads
3
License
MIT
Repository
github
Last release
1 year ago

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/)

šŸ¤ Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page.

Show your support

Give a ā­ļø if this project helped you!

0.0.5

1 year ago

0.0.4

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.3

5 years ago

0.0.2

5 years ago