An open API service indexing awesome lists of open source software.

https://github.com/korkje/match

Alternative to the switch statement
https://github.com/korkje/match

deno switch typescript

Last synced: about 2 months ago
JSON representation

Alternative to the switch statement

Awesome Lists containing this project

README

          

# match [![JSR](https://jsr.io/badges/@korkje/match)](https://jsr.io/@korkje/match)

Alternative to the `switch` statement in JS/TS.

```ts
import match from "@korkje/match";

const inRange = (lo: number, hi: number) => (n: number) => n >= lo && n < hi;

const result = match(Math.random())
.on(inRange(0, 0.5), "[0, 0.5)")
.on(inRange(0.5, 1), "[0.5, 1)")
.default("Throw away your computer")
.result();

console.log(result);
```