Class

PhoneFmt

PhoneFmt(options)

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.

Some regions have more than one style of formatting, and the style parameter selects which style the user prefers. An array of style names that this locale supports can be found by calling PhoneFmt.getAvailableStyles. Example phone numbers can be retrieved for each style by calling PhoneFmt.getStyleExample.

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.

Constructor

# new PhoneFmt(options)

Parameters:
Name Type Description
options Object

properties that control how this formatter behaves

View Source PhoneFmt.js, line 74

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

View Source PhoneFmt.js, line 388

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.

View Source PhoneFmt.js, line 432

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

View Source PhoneFmt.js, line 455

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