You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 3, 2026. It is now read-only.
Match against literals, primitives, and shallow objects
Eager (case(pattern, result)) and lazy (case(pattern, () => result)) matching
Fallback methods: or, orElse, orThrow
Examples
import{match}from"@monstermann/match"// Match primitives:match(value).case(1,2).case(2,3).orElse(v=>v+1)// Match object shapes:match.shape({value: foo}).case({value: 1},2).case({value: 2},3).or(0)// Match with predicates:match.shape({value: foo}).cond(v=>v.value>0,"positive").cond(v=>v.value<0,"negative").or("zero")
Unplugin
The unplugin can optimize your code to be as fast as hand-written if/else statements, with the help of the Oxidation Compiler, for example:
import{match}from"@monstermann/match";// Match a literal or primitive:match(value);// Or match an object:match.shape(value);// Optionally set a strict return type:.returnType<Type>()// Match against a pattern:.case(value,result).onCase(value,(match)=>result)// Or match against a predicate:.cond((unmatched)=>boolean,result).onCond((unmatched)=>boolean,(match)=>result)// Handle result:.or(fallback).orElse((unmatched)=>fallback).orThrow()