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

    Function createQuantityClass

    • Create a Quantity class with a chosen numeric backend and parser.

      Type Parameters

      Parameters

      • options: {
            config?: QuantityConfigInput<NoInfer<NumericOptions<A>>>;
            numeric: A;
            parser: (config: ParserConfig) => Parser<NoInfer<ReturnType<A["from"]>>>;
        }

        Adapter instance, parser factory, and optional Quantity configuration. The parser factory receives resolved parser-cache settings. Its parser must evaluate scalars with the adapter supplied to parse; wrappers should forward its cache scope and optional replacement scalar.

        • Optionalconfig?: QuantityConfigInput<NoInfer<NumericOptions<A>>>

          Optional numeric overrides and Quantity cache policies, using the withConfig shape.

        • numeric: A

          Immutable backend instance used for this class's scalar representation and arithmetic.

        • parser: (config: ParserConfig) => Parser<NoInfer<ReturnType<A["from"]>>>

          Create a parser from the resolved Quantity parser-cache settings.

      Returns NumericQuantityConstructor<
          ReturnType<A["from"]>,
          NumericOptions<A>,
          NumericSettings<A>,
      >

      A class whose instances, clones and calculated results retain this configuration.

      TypeError for unknown options, an invalid parser factory, or an adapter missing the arithmetic capabilities required by Quantity.

      import { createQuantityClass } from '@neutrium/quantity/factory';
      import { RegexParser } from '@neutrium/quantity/parsers/regex';
      import { NumberAdapter } from '@neutrium/math/adapters/number';

      const NativeQuantity = createQuantityClass({
      numeric: new NumberAdapter(),
      parser: config => new RegexParser(config),
      config: { cache: false },
      });
      new NativeQuantity('2 km').to('m').scalar; // 2000