0.0.0-dev.0 • Published 1 year ago

@yaupon/match v0.0.0-dev.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

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

1 year ago