@neutrium/quantity - v5.0.0
    Preparing search index...

    Interface Parser<Result>

    Structural contract for a parser supplied to the Quantity constructor.

    Import this interface from @neutrium/quantity/core. A compatible parse method is sufficient; an explicit implements Parser declaration is unnecessary.

    interface Parser<Result> {
        config?: ParserConfig;
        parse(val: string, decimal?: ScientificDecimalConstructor): Result;
    }

    Type Parameters

    • Result

      Parsed output; Quantity requires a QuantityDefinition shape.

    Implemented by

    Index
    config?: ParserConfig

    Effective settings, when the implementation supports configurable parser caches.

    • Parse a scalar and unit expression.

      Parameters

      • val: string

        Expression supplied by the constructor. With a separate scalar, only the unit expression is passed and the returned scalar is replaced.

      • Optionaldecimal: ScientificDecimalConstructor

        Optional arithmetic constructor; use it to preserve isolated Quantity settings.

      Returns Result

      A complete result containing a Decimal scalar and normalized unit arrays.

      Implementations should throw when input is invalid or incomplete.