Class NumberParserBase<TOptions>Abstract

Abstract class for creating parsers that intake strings containing a number and return that number, after stripping out esthetics like thousands separators, formatting characters, etc.

It always accepts decimal numbers and negative numbers. If you don't want those, use a validator to reject the number formed by this parser.

Expect to register multiple instances of its subclasses with DataTypeParsersServer, to cover each configuration for the cultures you support. new NumberParser('Number', ['en-US', 'en-CA']...); new NumberParser('Number', ['en-GB']...);

Type Parameters

Hierarchy (view full)

Constructors

Properties

badNumberMessage: "Expecting a number" = 'Expecting a number'

Accessors

  • get supportedCultures(): string[]
  • All cultureIds that support the order and separator. Note that if there is language-specific culture and one that is not language specific but has the same local, you can define just the one for the local because the DataTypeParser service will search both language specific and language agnostic when the CultureService is setup with fallbacks.

    Returns string[]

  • get stripTheseStrings(): string | string[]
  • Any special formatting strings that are meaningful to the user but can be discarded during parsing. Consider the currency symbol and percent symbol. Don't use this for negative character as once identified as negative, the all negative symbols are stripped prior to parsing and the resolved number is still negated.

    Returns string | string[]

  • set stripTheseStrings(value): void
  • Parameters

    • value: string | string[]

    Returns void

Methods

  • In addition to matching by dataTypeLookupKey, it also requires the text to match a regular expression. The expression reflects the one or very few patterns that parse() expects to work with. By the time parse() is called, it knows the expression has the pattern and can simply work within the regexp results.

    Parameters

    • dataTypeLookupKey: string
    • cultureId: string
    • text: string

    Returns boolean

  • Responsible for anything that cannot be a number and number patterns that conform to the current options, like have a currencysymbol only when its setup. When its a number that cannot work with the options, reject it so another registered number parser can deal with it. That way, the NumberParser doesn't try to handle what was intended for CurrencyParser or PercentageParser.

    Parameters

    • dataTypeLookupKey: string
    • cultureId: string
    • text: string

    Returns boolean

  • Expects the string to be: optional minus (in group named "neg") 1 or more digits, allowing for lead zeros (in group named "whole") optional period if period, optional 1 or more digits allowing for trailing zeros (in group named "decimal"). This resulting pattern should completely cover the text except for lead and trailing whitespace. After whitespace trimming, we should be able to use parseFloat or parseInt on the text.

    Parameters

    • dataTypeLookupKey: string
    • cultureId: string

    Returns RegExp

Generated using TypeDoc v0.25.12