Class FormattingUtility

The FormattingUtility class provides utility functions for formatting text.

Constructors

Properties

defaultNumberDigits = 6

The default number of digits to use for formatting numbers and vectors.

emojiMap: Map<string, string>

A map from text based smiley to emoji.

knownEmojis: Set<string>

A set of all emojis registered manually with RSX.

Methods

  • Converts a symbolicName to a string usable for a title in the UI.

    Parameters

    • symbolicName: string

    Returns string

    This essentially splits a PascalCaseString into a human readable title in the format Pascal Case String.

  • Converts text-based smilies to emojis.

    Parameters

    • text: string

    Returns string

    This method whitespace trims the input and end of the string.

  • Decodes the HTML encoded characters.

    Parameters

    • value: string

      The HTML encoded string

    Returns string

    This method only support the XML1/HTML1 standard, not the full range of HTML5 entities.

  • Escapes the HTML characters in text and replaces them with HTML entities.

    Parameters

    • text: string

      The string containing HTML.

    Returns string

    This converts a string in the form <b>Bold</b> to &lt;Bold&gt;.

  • Formats a byte length with "kB", "MB" or "GB" suffixes.

    Parameters

    • length: number

      The length to be formatted

    Returns string

    a string with the formatted byte length

  • Formats the number value using the format, an optional suffix can be appended.

    Parameters

    • format: string

      The format, e.g. ##000.00

    • value: number

      The number to format.

    • Optionalsuffix: string

      The suffix to append.

    Returns string

    the formatted value.

  • Formats the given date object using relative dates.

    The formatting is done using the following logic:

    • If the the in the past:

      • If the date is less then 1 minute ago, it would return "Just now".
      • If in the order of minutes, it should return "X minutes ago"
      • If in the order of hours, it should return "X hours ago"
      • Then the scale goes to days, months and finally up to years.
    • If the the in the future:

      • If in the order of minutes, it should return "In X minutes"
      • If in the order of hours, it should return "In X hours"
      • If above 24h, it retuns a short date string.

    Parameters

    • date: Date

      The date to be formatted.

    • Optionalreference: Date

      The date to use as reference. Optional, and if not set will fallback to the current date.

    • OptionalupperCase: boolean

      True to uppercase the first character.

    Returns string

  • Determines if the text is an emoji.

    Parameters

    • text: string

    Returns boolean

  • Determines if the specified email is a valid email adress in the format name@company.domain.

    Parameters

    • email: string

      The email address to validate

    Returns boolean

  • Removes all HTML tags from the input value.

    Parameters

    • value: string

    Returns string

  • Removes all special characters and white-space from the value and replaces these characters with invalid.

    Parameters

    • value: string
    • Optionalinvalid: string

    Returns string