format
A method that’s used to format a value.
format(value: any, ...type: string[]): string
Summary
This method is called primarily by LazyString (the result of strf()), for each ‘local’ placeholder in a format string. The implementation of this method should support all types of formats that are necessary for the rest of the application, such as dates or currency values. The format type specified along with the ‘local’ placeholder is passed directly to this method, along with the value to be formatted.
Parameters
- value — The value to be formatted
- type — The type of formatting to be performed, possibly with further options
Example
// Part of an I18nProvider implementation:
format(value: any, ...type: string[]): string {
switch (type[0]) {
case "date":
return this.formatDate(value, type[1] || "short");
// ... other formats
default:
return "???";
}
}
Related
- interface I18nProviderAn interface that can be implemented to support a specific locale.