@ysuzuki19/match.ts
v1.0.1
Published
TypeScript match(switch-case) library inspired by Rust.
Downloads
1
Readme
match.ts
TypeScript match(switch-case) library inspired by Rust.
How to Use
Simple
import match from 'match.ts';
const status = 'ArrowUp';
match(status, {
ArrowUp: () => {
handleUp();
}, // called!!
ArrowDown: () => {
handleDown();
},
_: () => console.log(status),
});
With rewrite
import match from 'match.ts';
const status = 'KeyJ';
match(
status,
{
UP: () => {
handleUp();
},
DOWN: () => handleDown(), // called!!
_: () => console.log(status),
},
{
ArrowDown: 'DOWN',
KeyJ: 'DOWN',
ArrowUp: 'UP',
KeyK: 'UP',
}
);