@ag1/return_switch
Version:
a switch condition that return result
52 lines (37 loc) • 839 B
Markdown

Control Statement that can return result is cool. It can reduce ugly code. Some other libs have done this but they are too complicated for our need.
at least ES2015
```bash
yarn add @ag1/return_switch
```
```ts
import { returnSwitch } from '@ag1/return_switch';
```
```ts
const foo = returnSwitch<string>('foo')([
['foo', 'foo'], // matched
[],
]);
console.log(foo); // foo
```
```ts
const bar = returnSwitch<string>('bar')([
['foo', 'foo'],
[], // default
]);
console.log(bar); // bar
```
```ts
const lorem = returnSwitch<string>('lorem')([
['foo', 'foo'],
['bar', 'bar'],
]); // NO_MATCH, throw error
```
```bash
yarn test
```