Interface: localizerInterface

localizerInterface

Implemented by instances of NumberFormatter and DateFormatter. Note however that it not a requirement that a custom localizer implementation be created from such a factory object; it only needs to implement the required methods described below (i.e., format and parse).

Members

expectation :string

A string to use when no validation error message is available.

Implementation of this property is optional.

This string should describe the syntax and semantics of the expected value. Typically it begins with "Expected ..."

If undefined and in the absence of an error message, the user will know only that the value is invalid but nothing else.

Overridden by options.expectation passed to factory constructor (NumberFormatter or DateFormatter).

Type:
  • string

locale :string

Locale for formatting purposes.

A locale value is required as the 2nd parameter (locale) to a factory constructor (NumberFormatter or DateFormatter).

Type:
  • string

name :string

Name to use for registering the localizer.

Implementation of this property is optional. If undefined, a name will need to be supplied at registration time.

Type:
  • string

Methods

format(value) → {string}

Transform a primitive value into a human-friendly string representation.

Implementation of this method is required.

Parameters:
Name Type Description
value *
Returns:
Type
string

invalid() → {boolean|string}

Tests string representation for invalidity.

Implementation of this method is optional.

Return an error message here only if you can describe what precisely caused the syntax error. If all you know is that there was a syntax error, return true. In such a case it would be helpful to also define expectation, which is appended to all error messages, and should contain a general description of the expected syntax.

Overridden by options.invalid passed to a factory constructor (NumberFormatter or DateFormatter).

Throws:

May throw an error on syntax failure as an alternative to returning truthy. Define the error's message field as an alternative to returning string.

Type
Error
Returns:

Truthy value means invalid. If a string, this will be an error message. If not a string, it merely indicates a generic invalid result.

Type
boolean | string

parse(editedValue) → {null|*}

Transform a formatted string representation back into a primitive typed value.

Implementation of this method is required.

Parameters:
Name Type Description
editedValue string
Throws:

Throws an error on parse failure. If the error's message is defined, the message will eventually be displayed (every feedbackCountth attempt).

Type
boolean | string | Error
Returns:

Primitive typed value.

Type
null | *