formatValue()function
formatValue(value: unknown, options?: FormatOptions, caller: AnyCaller = formatValue): string
| Param | Type | |
|---|---|---|
value | unknown | Unknown value to format. required |
options | FormatOptions | Formatting options passed through to the underlying formatter. |
.locale | Intl.Locale | Override the locale for formatting (defaults to detected locale). readonly |
caller | AnyCaller | 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...
object.nameif it exists, orobject.titleif it exists.
- Falsy values like
nullandundefinedreturn"None" - Everything else returns
"Unknown"
Examples
formatValue(1234) // "1,234"