The Phone class represents a phone number and provides methods to retrieve information about it. It implements the PhoneModel interface.

Implements

Hierarchy

  • Phone

Implements

Constructors

  • The Phone class constructor takes a phone argument of type RawPhoneType and an optional country argument of type RawCountryType. It initializes Phone instance.

    Parameters

    • phone: RawPhoneType

      The phone number to be parsed and validated.

    • Optional country: Country

      The country code of the phone number. If not provided, the country will be guessed based on the phone number.

    Returns Phone

Accessors

  • get e164(): string
  • Returns the E.164 format of the phone number.

    Returns string

    Remarks

    If the phone number is not a valid phone number, the initial phone number which was passed to the constructor is returned.

  • get international(): string
  • Returns the international format of the phone number.

    Returns string

    Remarks

    If the phone number is not a valid phone number, the initial phone number which was passed to the constructor is returned.

  • get mobile(): boolean
  • Returns whether the phone number is a mobile number or not.

    Returns boolean

  • get national(): string
  • Returns the national format of the phone number.

    Returns string

    Remarks

    If the phone number is not a valid phone number, the initial phone number which was passed to the constructor is returned.

  • get raw(): string
  • Returns the raw phone number.

    Returns string

    Remarks

    If the phone number is not a valid phone number, the initial phone number which was passed to the constructor is returned.

  • get valid(): boolean
  • Returns whether the phone number uses a valid format for the parsed country or not.

    Returns boolean

Methods

  • Returns a stringified representation of the phone number.

    Returns string

    • A string representation of the phone number.
  • Serializes the phone object to an obfuscated string which can be used to recreate the phone object from the Phone.deserialize method.

    Returns string

    • The serialized phone object.
  • Returns a JSON representation of the phone number.

    Returns {
        country: CountryOrUnknown;
        e164: string;
        international: string;
        mobile: boolean;
        national: string;
        phone: string;
        raw: string;
        timezone: PossiblePhoneTimezone;
        type: PhoneTypes;
        valid: boolean;
    }

    • A JSON-safe representation of the phone number.
    • country: CountryOrUnknown

      The country code of the phone number.

      Remarks

      In cases where the country was not recognized and could not be guessed from the phone number, 'XX' is used.

    • e164: string

      The phone number as a string in the E.164 format.

    • international: string

      The phone number as a string in the international format for the parsed country.

    • mobile: boolean

      Whether the phone number is possibly a mobile number or not.

    • national: string

      The phone number as a string in the national format for the parsed country.

    • phone: string

      The phone number as a string stripped of all non-numeric characters.

    • raw: string

      The phone number as a string stripped of all non-numeric characters.

    • timezone: PossiblePhoneTimezone

      The estimated timezone of the phone number based on the phone number's country. It can be either a CountryTimezone or 'UTC'.

    • type: PhoneTypes

      The type of the phone number.

    • valid: boolean

      Whether the phone number uses a valid format for the parsed country or not.

  • Returns an object representation of the phone number.

    Returns {
        country: CountryOrUnknown;
        e164: string;
        international: string;
        mobile: boolean;
        national: string;
        phone: string;
        raw: string;
        timezone: PossiblePhoneTimezone;
        type: PhoneTypes;
        valid: boolean;
    }

    • An object representation of the phone number.
    • country: CountryOrUnknown

      The country code of the phone number.

      Remarks

      In cases where the country was not recognized and could not be guessed from the phone number, 'XX' is used.

    • e164: string

      The phone number as a string in the E.164 format.

    • international: string

      The phone number as a string in the international format for the parsed country.

    • mobile: boolean

      Whether the phone number is possibly a mobile number or not.

    • national: string

      The phone number as a string in the national format for the parsed country.

    • phone: string

      The phone number as a string stripped of all non-numeric characters.

    • raw: string

      The phone number as a string stripped of all non-numeric characters.

    • timezone: PossiblePhoneTimezone

      The estimated timezone of the phone number based on the phone number's country. It can be either a CountryTimezone or 'UTC'.

    • type: PhoneTypes

      The type of the phone number.

    • valid: boolean

      Whether the phone number uses a valid format for the parsed country or not.

  • Returns the E.164 format of the phone number as a string.

    Returns string

    • The E.164 format of the phone number.
  • Creates a new phone object from a serialized phone object.

    Parameters

    • serialized: string

      The serialized phone object returned from the Phone.serialize method.

    Returns Phone

    A Phone instance with the same properties as the original phone object.

    Throws

    An error if the serialized phone object is not valid.