1.0.1 • Published 3 years ago

@ysuzuki19/match.ts v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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',
  }
);