@metreeca/core - v0.9.11
    Preparing search index...

    Module status

    Pattern matching for values that can be in one of several exclusive states.

    Use when working with data where exactly one variant is active at a time - like operation results that are either successful or failed, UI states that are loading, ready, or error, or any domain model where alternatives are mutually exclusive.

    The Status function lets you handle each state with a dedicated handler, while TypeScript ensures all states are covered and values are accessed safely. Eliminates verbose conditional logic and prevents bugs from unhandled cases.

    Usage

    import { status, Condition } from '@metreeca/core/status';

    // Define condition patterns for form field state

    type FieldState = {
    unset: void;
    value: string;
    error: Error;
    };

    // Create status matcher (for example, for value condition)

    const matcher = status<FieldState>({
    value: "user@example.com"
    });

    // Pattern match with function handlers

    const message = matcher({
    unset: () => "Enter email",
    value: (email) => `Email: ${email}`,
    error: (err) => `Error: ${err.message}`
    });

    // Use constant handlers

    const isValid = matcher({
    unset: false,
    value: true,
    error: false
    });

    // Use fallback for partial matching

    const display = matcher({
    value: (email) => email
    }, "‹blank›");

    Type Aliases

    Conditions

    Condition patterns.

    Condition

    Condition value.

    Handlers

    Condition handlers.

    Handler

    Condition handler.

    Interfaces

    Status

    Pattern matcher.

    Functions

    Status

    Creates a type-safe pattern matching function for a condition.