# new PhoneFmt(options)
Parameters:
Name | Type | Description |
---|---|---|
options |
Object
|
properties that control how this formatter behaves |
Members
Methods
# format(numbernon-null, options) → {string}
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.
The partial parameter specifies whether or not the phone number contains a partial phone number or if it is a whole phone number. A partial number is usually a number as the user is entering it with a dial pad. The reason is that certain types of phone numbers should be formatted differently depending on whether or not it represents a whole number. Specifically, SMS short codes are formatted differently.
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)
Any place in the UI where the user types in phone numbers, such as the keypad in the phone app, should pass in partial: true to this formatting routine. All other places, such as the call log in the phone app, should pass in partial: false, or leave the partial flag out of the parameters entirely.
Parameters:
Name | Type | Description |
---|---|---|
number |
PhoneNumber
|
object containing the phone number to format |
options |
Object
|
Parameters which control how to format the number |
Returns the formatted phone number as a string.
string
# getAvailableStyles() → {Array.<string>}
Return an array of names of all available styles that can be used with the current formatter.
an array of names of styles that are supported by this formatter
Array.<string>
# getStyleExample(style) → {string|undefined}
Return an example phone number formatted with the given style.
Parameters:
Name | Type | Description |
---|---|---|
style |
string
|
undefined
|
style to get an example of, or undefined to use the current default style for this formatter |
an example phone number formatted according to the given style, or undefined if the style is not recognized or does not have an example
string
|
undefined