Class ilib.PhoneFmt
Create a new phone number formatter object that formats numbers according to the parameters.
The options object can contain zero or more of the following parameters:
- locale locale to use to format this number, or undefined to use the default locale
- style the name of style to use to format numbers, or undefined to use the default style
- mcc the MCC of the country to use if the number is a local number and the country code is not known
- onLoad - a callback function to call when the locale data 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.
If the MCC is given, numbers will be formatted in the manner of the country
specified by the MCC. If it is not given, but the locale is, the manner of
the country in the locale will be used. If neither the locale or MCC are not given,
then the country of the current ilib locale is used.
Defined in: ilib-dyn-full.js.
Constructor Attributes | Constructor Name and Description |
---|---|
ilib.PhoneFmt(options)
|
Method Attributes | Method Name and Description |
---|---|
format(number, options)
Format the parts of a phone number appropriately according to the settings in
this formatter instance.
|
|
Return an array of names of all available styles that can be used with the current
formatter.
|
|
getStyleExample(style)
Return an example phone number formatted with the given style.
|
Class Detail
ilib.PhoneFmt(options)
- Parameters:
- {Object} options
- properties that control how this formatter behaves
Method Detail
{string}
format(number, options)
Format the parts of a phone number appropriately according to the settings in
this formatter instance.
The options can contain zero or more of these properties:
- partial boolean which tells whether or not this phone number represents a partial number or not. The default is false, which means the number represents a whole number.
- style style to use to format the number, if different from the default style or the style specified in the constructor
- locale The locale with which to parse the number. This gives a clue as to which numbering plan to use.
- mcc The mobile carrier code (MCC) associated with the carrier that the phone is currently connected to, if known. This also can give a clue as to which numbering plan to use
- onLoad - a callback function to call when the date format object is fully loaded. When the onLoad option is given, the DateFmt 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.
Example: a subscriber number of "48773" in the US would get formatted as:
- partial: 487-73 (perhaps the user is in the process of typing a whole phone number such as 487-7379)
- whole: 48773 (this is the entire SMS short code)
- Parameters:
- {!ilib.PhoneNumber} number
- object containing the phone number to format
- {{ partial:boolean|style:string|mcc:string|locale:(string|ilib.Locale)|sync:boolean|loadParams:Object|onLoad:function(string) }} options
- Parameters which control how to format the number
- Returns:
- {string} Returns the formatted phone number as a string.
{Array.<string>}
getAvailableStyles()
Return an array of names of all available styles that can be used with the current
formatter.
- Returns:
- {Array.<string>} an array of names of styles that are supported by this formatter
{string|undefined}
getStyleExample(style)
Return an example phone number formatted with the given style.
- Parameters:
- {string|undefined} style
- style to get an example of, or undefined to use the current default style for this formatter
- Returns:
- {string|undefined} an example phone number formatted according to the given style, or undefined if the style is not recognized or does not have an example