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

    Class RegexParser

    Regex parser for scalar and unit expressions without parenthesized grouping. Receives the numeric adapter explicitly; importing this engine does not load Decimal. Powers bind first, then dot products; * / and whitespace evaluate left to right.

    Index
    • Create a parser with optional cache limits. Omitted options share the default configuration. Separately supplied option objects isolate retention; passing an already resolved configuration reuses it.

      Parameters

      Returns RegexParser

      const parser = new RegexParser({ cache: { maxEntries: 128 } });
      parser.config.cache.maxEntries; // 128
    • Rebuild shared unit patterns and clear unit caches across all Regex parser configurations. Called automatically on first construction; ordinary parsing does not require this method.

      Returns void

    • Parse a scalar and counted units without expanding powers.

      Type Parameters

      • T

      Parameters

      • val: string

        Expression such as "2 kg*m/s^2", "m", or "2".

      • Numeric: ArithmeticAdapter<T>

        Adapter used to evaluate the scalar.

      • Optionalscope: CacheScope

        Optional Quantity cache scope; wrappers should forward it unchanged.

      • Optionalscalar: T

        Optional replacement scalar. The parser validates the units and skips scalar evaluation.

      Returns QuantityDefinition<T>

      A definition accepted by Quantity. Empty sides represent unity.

      If syntax, unit tokens, or rational exponents are invalid.

      Grouped expressions and scalar arithmetic require Nearley or Pratt. Absolute-zero validation occurs when a Quantity is constructed from the definition.

      import { Quantity } from '@neutrium/quantity/number';
      const parsed = new RegexParser().parse('2 m/s', new Quantity(1).numeric);
      parsed.scalar; // 2
      new Quantity(parsed).units(); // "m/s"