0.0.0-dev.0 • Published 2 years ago
@yaupon/match v0.0.0-dev.0
Pattern Matcher
Pattern matching is a technique used in programming to check if data (like text, numbers, or structures) conforms to a certain structure or pattern. Think of it like a mold – if the data fits the mold (the pattern), it's considered a match.
Library is just short re-module of ts-pattern library,
for more information please refer to the ts-pattern documentation.
In future this package will be contained under @yaupon/std and will be used across all packages,
currently this is treated as optional syntax sugar that developer can use.
import { match } from '@yaupon/match';
type Permission = 'editor' | 'viewer';
type Plan = 'basic' | 'pro';
const fn = (org: Plan, user: Permission) =>
match([org, user])
.with(['basic', 'viewer'], () => {})
.with(['basic', 'editor'], () => {})
.with(['pro', 'viewer'], () => {})
.with(['pro', 'editor'], () => {})
.exhaustive();0.0.0-dev.0
2 years ago