/** @packageDocumentation * @module Quantity */ import { Format } from "./Formatter/Format"; import { AlternateUnitLabelsProvider, PotentialParseUnit, QuantityProps, UnitConversionSpec, UnitProps, UnitsProvider } from "./Interfaces"; import { ParserSpec } from "./ParserSpec"; /** Possible parser errors * @beta */ export declare enum ParseError { UnableToGenerateParseTokens = 1, NoValueOrUnitFoundInString = 2, UnitLabelSuppliedButNotMatched = 3, UnknownUnit = 4, UnableToConvertParseTokensToQuantity = 5, InvalidParserSpec = 6, BearingPrefixOrSuffixMissing = 7, MathematicOperationFoundButIsNotAllowed = 8, BearingAngleOutOfRange = 9, InvalidMathResult = 10 } /** Parse error result from [[Parser.parseToQuantityValue]] or [[Parser.parseToQuantityValue]]. * @beta */ export interface ParseQuantityError { /** Union discriminator for [[QuantityParseResult]]. */ ok: false; /** The specific error that occurred during parsing. */ error: ParseError; } /** Successful result from [[Parser.parseToQuantityValue]] or [[Parser.parseToQuantityValue]]. * @beta */ export interface ParsedQuantity { /** Union discriminator for [[QuantityParseResult]]. */ ok: true; /** The magnitude of the parsed quantity. */ value: number; } declare enum Operator { addition = "+", subtraction = "-", multiplication = "*",// unsupported but we recognize it during parsing division = "/" } /** * Defines Results of parsing a string input by a user into its desired value type * @beta */ export type QuantityParseResult = ParsedQuantity | ParseQuantityError; /** A ParseToken holds either a numeric or string token extracted from a string that represents a quantity value. * @beta */ declare class ParseToken { value: number | string | Operator; isOperator: boolean; constructor(value: string | number | Operator); get isString(): boolean; get isNumber(): boolean; get isSpecialCharacter(): boolean; } /** A Parser class that is used to break a string that represents a quantity value into tokens. * @beta */ export declare class Parser { private static _log; static isParsedQuantity(item: QuantityParseResult): item is ParsedQuantity; static isParseError(item: QuantityParseResult): item is ParseQuantityError; private static checkForScientificNotation; private static checkForFractions; private static isDigit; private static isDigitOrDecimalSeparator; /** Parse the quantity string and return and array of ParseTokens that represent the component invariant values and unit labels. * @param quantitySpecification The quantity string to ba parsed. */ static parseQuantitySpecification(quantitySpecification: string, format: Format): ParseToken[]; private static isMathematicOperation; private static lookupUnitByLabel; /** * Get the output unit and all the conversion specs required to parse a given list of tokens. */ private static getRequiredUnitsConversionsToParseTokens; /** * Get the units information asynchronously, then convert the tokens into quantity using the synchronous tokens -> value. */ private static createQuantityFromParseTokens; /** Async method to generate a Quantity given a string that represents a quantity value and likely a unit label. * @param inString A string that contains text represent a quantity. * @param format Defines the likely format of inString. * @param unitsProvider required to look up units that may be specified in inString */ static parseIntoQuantity(inString: string, format: Format, unitsProvider: UnitsProvider, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise; /** method to get the Unit Conversion given a unit label */ private static tryFindUnitConversion; /** * Get what the unit conversion is for a unitless value. */ private static getDefaultUnitConversion; private static getNextTokenPair; /** * Accumulate the given list of tokens into a single quantity value. Formatting the tokens along the way. */ private static getQuantityValueFromParseTokens; /** Method to generate a Quantity given a string that represents a quantity value. * @param inString A string that contains text represent a quantity. * @param parserSpec unit label if not explicitly defined by user. Must have matching entry in supplied array of unitsConversions. */ static parseQuantityString(inString: string, parserSpec: ParserSpec): QuantityParseResult; /** Method to generate a Quantity given a string that represents a quantity value and likely a unit label. * @param inString A string that contains text represent a quantity. * @param format Defines the likely format of inString. Primary unit serves as a default unit if no unit label found in string. * @param unitsConversions dictionary of conversions used to convert from unit used in inString to output quantity * @deprecated in 4.10 - might be removed in next major version. Check [[Parser.parseQuantityString]] for replacements. */ static parseToQuantityValue(inString: string, format: Format, unitsConversions: UnitConversionSpec[]): QuantityParseResult; /** The value of special direction is always in degrees, try to find the unit conversion for that. */ private static processSpecialBearingDirection; private static parseBearingFormat; private static parseAzimuthFormat; /** * Parse a ratio part string (numerator or denominator) to extract the numeric value and optional unit label. * This method processes tokens without applying unit conversions, allowing the ratio format * handler to manage conversions at the ratio level. * * * @note Fractions are already handled by parseQuantitySpecification, which converts them to * single numeric tokens (e.g., "1/2" becomes 0.5). * * @param partStr The string to parse, which may contain a number, fraction, or mixed fraction with optional unit label. * @param format The format specification used for token parsing. * @returns An object containing the parsed numeric value and optional unit label. Returns NaN for value if no number is found. */ private static parseRatioPart; private static parseRatioFormat; private static normalizeAngle; private static getRevolution; private static parseAndProcessTokens; /** Async Method used to create an array of UnitConversionSpec entries that can be used in synchronous calls to parse units. */ static createUnitConversionSpecsForUnit(unitsProvider: UnitsProvider, outUnit: UnitProps, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise; /** Async Method used to create an array of UnitConversionSpec entries that can be used in synchronous calls to parse units. */ static createUnitConversionSpecs(unitsProvider: UnitsProvider, outUnitName: string, potentialParseUnits: PotentialParseUnit[], altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise; } export {}; //# sourceMappingURL=Parser.d.ts.map