formatValue()function

formatValue(value: unknown, options?: FormatOptions, caller: AnyCaller = formatValue): string
ParamType
valueunknown
Unknown value to format. required
optionsFormatOptions
Formatting options passed through to the underlying formatter.
    .localeIntl.Locale
Override the locale for formatting (defaults to detected locale). readonly
callerAnyCaller
Function to attribute a thrown error to (defaults to formatValue itself). Defaults to formatValue
Return
string
User-facing string representation of value.

Convert any unknown value into a friendly string for user-facing use.

  • Strings return the string.
  • Booleans return "Yes" or "No"
  • Numbers return formatted number with commas etc (e.g. formatNumber()).
  • Dates return formatted datetime (e.g. formatDateTime()).
  • Arrays return the array items converted to string (with toTitle()), and joined with a comma.
  • Objects return...
    1. object.name if it exists, or
      1. object.title if it exists.
  • Falsy values like null and undefined return "None"
  • Everything else returns "Unknown"

Examples

formatValue(1234) // "1,234"