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
- Host: GitHub
- URL: https://github.com/korkje/match
- Owner: korkje
- License: mit
- Created: 2019-06-06T10:59:04.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-06-09T22:51:47.000Z (about 2 years ago)
- Last Synced: 2025-03-05T09:48:54.683Z (over 1 year ago)
- Topics: deno, switch, typescript
- Language: TypeScript
- Homepage:
- Size: 11.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# 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);
```