@ag1/return_switch
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Return Switch

Node.js CI

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.

Support

at least ES2015

Install

yarn add @ag1/return_switch

Usage

import { returnSwitch } from '@ag1/return_switch';
const foo = returnSwitch<string>('foo')([
    ['foo', 'foo'], // matched
    [true, 'bar'],
]);

console.log(foo); // foo
const bar = returnSwitch<string>('bar')([
    ['foo', 'foo'],
    [true, 'bar'], // default
]);

console.log(bar); // bar
const lorem = returnSwitch<string>('lorem')([
    ['foo', 'foo'],
    ['bar', 'bar'],
]); // NO_MATCH, throw error

Test

yarn test

Package Sidebar

Install

npm i @ag1/return_switch

Weekly Downloads

2

Version

1.1.1

License

MIT

Unpacked Size

8.57 kB

Total Files

15

Last publish

Collaborators

  • worasitipon
  • kpping