@neutrium/quantity - v7.1.0
    Preparing search index...

    Interface Parser<T>

    Custom parser contract for quantities with scalar type T. Return a definition using the adapter passed to parse; Quantity then validates its scalar, units and absolute-temperature rules. A custom parser need not implement the bundled expression syntax or structured errors.

    import type { Parser } from '@neutrium/quantity/factory';
    const scalarOnly: Parser<number> = {
    parse: (text, numeric) => ({
    scalar: numeric.from(text), numerator: [], denominator: [],
    }),
    };
    interface Parser<T> {
        config?: ParserConfig;
        parse(
            text: string,
            numeric: ArithmeticAdapter<T>,
            scope?: CacheScope,
            scalar?: T,
        ): QuantityDefinition<T>;
    }

    Type Parameters

    • T
    Index
    config?: ParserConfig

    Effective parser settings, when supported.

    • Return a definition whose scalar is evaluated in the supplied adapter's context.

      Parameters

      • text: string

        Caller-supplied expression.

      • numeric: ArithmeticAdapter<T>

        Destination backend; do not capture a different adapter in the parser.

      • Optionalscope: CacheScope

        Quantity's optional cache scope. Forward it unchanged when delegating to a bundled parser so disabled-cache settings are respected.

      • Optionalscalar: T

        When supplied, only the units are needed. A parser can use this scalar directly and skip evaluating the scalar expression.

      Returns QuantityDefinition<T>