Class AddressFmt
Create a new formatter object to format physical addresses in a particular way. The options object may contain the following properties, both of which are optional:
- locale - the locale to use to format this address. If not specified, it uses the default locale
- style - the style of this address. The default style for each country usually includes all valid fields for that country.
- onLoad - a callback function to call when the address info for the locale is fully loaded and the address has been parsed. When the onLoad option is given, the address formatter object will attempt to load any missing locale data using the ilib loader callback. When the constructor is done (even if the data is already preassembled), the onLoad function is called with the current instance as a parameter, so this callback can be used with preassembled or dynamic loading or a mix of the two.
- sync - tell whether to load any missing locale data synchronously or asynchronously. If this option is given as "false", then the "onLoad" callback must be given, as the instance returned from this constructor will not be usable for a while.
- loadParams - an object containing parameters to pass to the loader callback function when locale data is missing. The parameters are not interpretted or modified in any way. They are simply passed along. The object may contain any property/value pairs as long as the calling code is in agreement with the loader callback function as to what those parameters mean.
Defined in: ilib-full-dyn.js.
Constructor Attributes | Constructor Name and Description |
---|---|
AddressFmt(options)
|
Method Attributes | Method Name and Description |
---|---|
format(address)
This function formats a physical address (Address instance) for display.
|
Class Detail
AddressFmt(options)
- Parameters:
- {Object} options
- options that configure how this formatter should work Returns a formatter instance that can format multiple addresses.
Method Detail
{string}
format(address)
This function formats a physical address (Address instance) for display.
Whitespace is trimmed from the beginning and end of final resulting string, and
multiple consecutive whitespace characters in the middle of the string are
compressed down to 1 space character.
If the Address instance is for a locale that is different than the locale for this
formatter, then a hybrid address is produced. The country name is located in the
correct spot for the current formatter's locale, but the rest of the fields are
formatted according to the default style of the locale of the actual address.
Example: a mailing address in China, but formatted for the US might produce the words
"People's Republic of China" in English at the last line of the address, and the
Chinese-style address will appear in the first line of the address. In the US, the
country is on the last line, but in China the country is usually on the first line.
- Parameters:
- {Address} address
- Address to format
- Returns:
- {string} Returns a string containing the formatted address