Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "geocortex/infrastructure/FormatUtils"

Index

Functions

format

  • format(value: any): string
  • Formats a value for display in the current locale.

    Parameters

    • value: any

      The value to format.

    Returns string

formatBytes

  • formatBytes(size: number): string
  • Format the given number of bytes in human-readable form.

    Parameters

    • size: number

      number

    Returns string

formatDate

  • Formats a date for display in the current locale.

    Parameters

    • date: Date

      The date to format.

    • Optional form: string

      One of the DateFormat constants, or a custom format string. The format string syntax is similar to this: https://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx, with the following exceptions: - "/", and ":" are treated as literal characters. - "y" is treated as "yy", and "yyy" is treated as "yyyy". - "z" and "zz" and "zzz" are treated as the UTC offset - "t" is treated the same as "tt". - "F", "FF", "FFF" etc. will behave the same as "f", "ff", "fff", etc. Additionally, a maximum of 3 digits (milliseconds) is supported. Longer formatters like "fffff" are truncated to 3 digits, rather than padded with zeros. - "g", "gg", and "K" are not supported at all and will be ignored. The default format is DATE_TIME_SHORT.

    • Optional options: DateFormatOptions

      specifying the timezone and display timezone of the data. If the display timezone is specified and z's appear in the format, the UTC offset will be calculated for the display timezone instead of the timezone of the browser.

    Returns string

formatDateFromNow

  • Formats a date for display in the current locale using relative time.

    Parameters

    Returns string

formatNumber

  • formatNumber(num: number, form?: string, options?: object): string
  • Formats a number for display using the application's current locale.

    Parameters

    • num: number

      The number to format.

    • Optional form: string

      One of the NumberFormat constants, or a custom format string. The format string syntax is similar to this: https://msdn.microsoft.com/en-us/library/0c899ak8.aspx, with the following exceptions: - The per-mille placeholder (‰) is not supported. - Exponential notation is not supported. - Literal characters appearing in the middle of a number will not work properly (e.g "00ABC0.##").

    • Optional options: object

      Additional options that further control how numbers are formatted. These only apply when using one of the pre-defined constants, NOT for custom formats. Options are: - currency: The 3-letter ISO 4217 currency code (e.g "USD", "CAD"). Required when formatting a number using NumberFormat.CURRENCY or NumberFormat.ACCOUNTING. - fractionalDigits: The number of digits to show after the decimal point. If unspecified, an appropriate value is determined based on the locale and currency.

      • Optional currency?: string
      • Optional fractionalDigits?: number

    Returns string

parseDate

  • parseDate(input: any, form?: string | string[]): Date
  • Parses a value into a Date object, using the application's current locale. The input is assumed to be in local time. See also {@link parseUtcDate()}.

    Parameters

    • input: any

      The input to parse. Numbers are treated as UNIX timestamps (always UTC).

    • Optional form: string | string[]

    Returns Date

    A Date object corresponding to the input, which might be an Invalid Date (i.e. getTime() will be NaN).

parseNumber

  • parseNumber(input: any, form?: string | string[]): number
  • Parses a value into a number, using the application's current locale.

    Parameters

    • input: any

      The input to parse.

    • Optional form: string | string[]

      The format that string input is expected to be in. Can be either a single format, or one of several possible formats. Formats are either one of the NumberFormat constants, or custom format strings (as per {@link formatNumber()}).

    Returns number

parseUtcDate

  • parseUtcDate(input: any, form?: string | string[]): Date
  • Parses a value into a Date object, using the application's current locale. The input is assumed to be in UTC. See also {@link parseDate()}.

    Parameters

    • input: any

      The input to parse. Numbers are treated as UNIX timestamps.

    • Optional form: string | string[]

      The format that string input is expected to be in. Can be either a single format, or one of several possible formats. Formats are either one of the DateFormat constants, or custom format strings (as per {@link formatDate()}).

    Returns Date

    A Date object corresponding to the input, which might be an Invalid Date (i.e. getTime() will be NaN).