libphonenumber-js 1.12.27 → 1.12.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -41
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -333,69 +333,83 @@ As for "custom" metadata, it could be used in those rare cases when not all coun
|
|
|
333
333
|
|
|
334
334
|
## Definitions
|
|
335
335
|
|
|
336
|
-
###
|
|
336
|
+
### National (Significant) Number
|
|
337
|
+
|
|
338
|
+
"National (significant) number" is all national phone number digits, excluding the "national prefix". Examples:
|
|
339
|
+
* International number: `+1 213 373 4253`. Country: `"US"`. National number: `(213) 373-4253`. National (significant) number: `213 373 4253`
|
|
340
|
+
* Inetrnational number: `+33 1 45 45 32 45`. Country: `"FR"`. National number: `01 45 45 32 45`. Notice the `0` at the start of the national number — it's because in France they [add](https://en.wikipedia.org/wiki/Telephone_numbers_in_France) `0` "national prefix" when writing phone numbers in national format. National (significant) number: `1 45 45 32 45` (doesn't include the "national prefix").
|
|
341
|
+
|
|
342
|
+
### Country Calling Code
|
|
343
|
+
|
|
344
|
+
"Country calling code" is all digits between the `+` and the [national (significant) number](#national-significant-number) in a number that is written in international format. Examples:
|
|
345
|
+
* International number: `+1 213 373 4253`. Country: `"US"`. National (significant) number: `213 373 4253`. Country calling code: `1`
|
|
346
|
+
* Inetrnational number: `+33 1 45 45 32 45`. Country: `"FR"`. National (significant) number: `1 45 45 32 45`. Country calling code: `33`
|
|
347
|
+
|
|
348
|
+
In some cases, multiple countries could share the same "country calling code". For example, USA, Canada and some Caribbean nations [share](https://en.wikipedia.org/wiki/North_American_Numbering_Plan) the same country calling code `1`.
|
|
349
|
+
|
|
350
|
+
### Non-Geographic
|
|
351
|
+
|
|
352
|
+
The following "calling codes" don't belong to any given country or territory and are inherently international:
|
|
353
|
+
|
|
354
|
+
* `+800` — [Universal International Toll Free Number](https://en.wikipedia.org/wiki/Toll-free_telephone_number)
|
|
355
|
+
* `+808` — [Universal International Shared Cost Number](https://en.wikipedia.org/wiki/Shared-cost_service)
|
|
356
|
+
* `+870` — [Inmarsat Global Limited](https://en.wikipedia.org/wiki/Inmarsat)
|
|
357
|
+
* `+878` — [Universal Personal Telecommunications](https://en.wikipedia.org/wiki/Universal_Personal_Telecommunications)
|
|
358
|
+
* `+881` — [Global Mobile Satellite System](https://en.wikipedia.org/wiki/Global_Mobile_Satellite_System)
|
|
359
|
+
* `+882` and `+883` — [International Networks](https://en.wikipedia.org/wiki/International_Networks_(country_code))
|
|
360
|
+
* `+888` — [United Nations Office for the Coordination of Humanitarian Affairs](https://en.wikipedia.org/wiki/United_Nations_Office_for_the_Coordination_of_Humanitarian_Affairs#International_Dialing_Code)
|
|
361
|
+
* `+979` — [International Premium Rate Service](https://en.wikipedia.org/wiki/International_Premium_Rate_Service)
|
|
362
|
+
|
|
363
|
+
Such phone numbers are called "non-geographic", and their `country` is `undefined`.
|
|
364
|
+
|
|
365
|
+
### Country Code
|
|
337
366
|
|
|
338
367
|
A "country code" is a two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) like `"US"`, `"CA"`, etc. <!-- or a special `001` country code used for ["non-geographic entities"](#non-geographic) (as per [Google's libphonenumber library](https://github.com/googlei18n/libphonenumber/blob/0068d861a68d3d4612f7bf8646ab844dd3cefce5/java/libphonenumber/test/com/google/i18n/phonenumbers/RegionCode.java#L23-L24)). -->
|
|
339
368
|
|
|
340
|
-
However, this library uses the term "country code" rather broadly and it includes both the [official](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) ISO country codes and a few of unofficial
|
|
369
|
+
However, this library uses the term "country code" rather broadly and it includes both the [official](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) ISO country codes and a few of [unofficial](#country-code-additions) "country codes" that do not "officially" exist.
|
|
370
|
+
|
|
371
|
+
For that reason, a developer should use a "country code" returned from this library with caution in an application that only expects the official ISO "country codes" to exist. For example, such application will likely not have a label or a flag for such an unofficial "country code".
|
|
372
|
+
|
|
373
|
+
A developer could manually transform any unofficial "country code" returned from this library to a most-suitable official one. For example, it could be the ISO country code of the most suitable "parent" territory.
|
|
374
|
+
|
|
375
|
+
To get a list of all supported "country codes", both official and unofficial, use [`getCountries()`](#getcountries-string) function.
|
|
341
376
|
|
|
342
|
-
|
|
377
|
+
To check if a certain two-letter "country code" is supported by this library, use [`isSupportedCountry()`](#issupportedcountrycountry-string-boolean) function.
|
|
378
|
+
|
|
379
|
+
### Country Code (additions)
|
|
380
|
+
|
|
381
|
+
Here's a list of the unofficial "country codes":
|
|
343
382
|
* `AC` — [Ascension Island](https://en.wikipedia.org/wiki/Ascension_Island)
|
|
344
383
|
* Ascension Island is officially part of [Saint Helena, Ascension and Tristan da Cunha
|
|
345
|
-
](https://en.wikipedia.org/wiki/Saint_Helena,_Ascension_and_Tristan_da_Cunha) (`SH`).
|
|
384
|
+
](https://en.wikipedia.org/wiki/Saint_Helena,_Ascension_and_Tristan_da_Cunha) (`SH`), which used to be called "Saint Helena and Dependencies" until 2009 when the dependencies were raised to equal status with Saint Helena. Ascension Island has been assigned its own country calling code of `+247` and has its own telephone numbering plan. In 2009 An unofficial code of `AC` is used for it in Google's `libphonenumber`.
|
|
346
385
|
* `AC` is also an official ["exceptional reservation"](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Reserved_code_elements) code for Ascension Island in the ISO-3166-1 standard.
|
|
386
|
+
* The last official ISO-3166-2 ["subdivision code"](https://en.wikipedia.org/wiki/ISO_3166-2) assigned to Ascension Island territory [is](https://en.wikipedia.org/wiki/ISO_3166-2:SH) `SH-AC`.
|
|
347
387
|
* `TA` — [Tristan da Cunha](https://en.wikipedia.org/wiki/Tristan_da_Cunha)
|
|
348
388
|
* Tristan da Cunha is officially part of [Saint Helena, Ascension and Tristan da Cunha
|
|
349
|
-
](https://en.wikipedia.org/wiki/Saint_Helena,_Ascension_and_Tristan_da_Cunha) (`SH`). For the purpose of differentiating Tristan da Cunha phone numbers from [Saint Helena](https://en.wikipedia.org/wiki/Saint_Helena) phone numbers, an unofficial code of `TA` is used for it in Google's `libphonenumber`.
|
|
389
|
+
](https://en.wikipedia.org/wiki/Saint_Helena,_Ascension_and_Tristan_da_Cunha) (`SH`), which used to be called "Saint Helena and Dependencies" until 2009 when the dependencies were raised to equal status with Saint Helena. Tristan da Cunha and Saint Helena still share the same country calling code. For the purpose of differentiating Tristan da Cunha phone numbers from [Saint Helena](https://en.wikipedia.org/wiki/Saint_Helena) phone numbers, an unofficial code of `TA` is used for it in Google's `libphonenumber`.
|
|
350
390
|
* `TA` is also an official ["exceptional reservation"](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Reserved_code_elements) code for Tristan da Cunha in the ISO-3166-1 standard.
|
|
391
|
+
* The last official ISO-3166-2 ["subdivision code"](https://en.wikipedia.org/wiki/ISO_3166-2) assigned to Tristan da Cunha territory [is](https://en.wikipedia.org/wiki/ISO_3166-2:SH) `SH-TA`.
|
|
351
392
|
* `SH` — [Saint Helena](https://en.wikipedia.org/wiki/Saint_Helena)
|
|
352
393
|
* Saint Helena is officially part of [Saint Helena, Ascension and Tristan da Cunha
|
|
353
|
-
](https://en.wikipedia.org/wiki/Saint_Helena,_Ascension_and_Tristan_da_Cunha) (`SH`). For the purpose of differentiating Saint Helena phone numbers from [Tristan da Cunha](https://en.wikipedia.org/wiki/Tristan_da_Cunha) phone numbers, the official code of `SH` is only used for Saint Helena in Google's `libphonenumber`.
|
|
394
|
+
](https://en.wikipedia.org/wiki/Saint_Helena,_Ascension_and_Tristan_da_Cunha) (`SH`), which used to be called "Saint Helena and Dependencies" until 2009 when the dependencies were raised to equal status with Saint Helena. For the purpose of differentiating Saint Helena phone numbers from [Tristan da Cunha](https://en.wikipedia.org/wiki/Tristan_da_Cunha) phone numbers, the official ISO country code of `SH` is only used for Saint Helena in Google's `libphonenumber`.
|
|
395
|
+
* The last official ISO-3166-2 ["subdivision code"](https://en.wikipedia.org/wiki/ISO_3166-2) assigned to Saint Helena territory [is](https://en.wikipedia.org/wiki/ISO_3166-2:SH) `SH-HL`.
|
|
354
396
|
* `XK` — [Kosovo](https://en.wikipedia.org/wiki/Kosovo)
|
|
355
397
|
* History: Kosovo separated from Yugoslavia (present Serbia, `RS`) after a civil war in 1998-1999 and a follow-up NATO's bombing of Yugoslavia in 1999. Kosovo officially (unilaterally) declared its independence from Serbia in 2008. Due to the mixed opinions on the legitimacy of NATO's intervention, about half of the United Nations member states currently support Kosovo's independence while the rest of them don't, so Kosovo is currently not assigned any ISO alpha-2 country code.
|
|
356
398
|
* Kosovo has been assigned its own country calling code of `+383` and has its own telephone numbering plan. An unofficial code of `XK` is used for it in Google's `libphonenumber`.
|
|
357
|
-
* `XK` is not an ["exceptional reservation"](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Reserved_code_elements) code in the ISO-3166-1 standard, but it's still being used by various
|
|
399
|
+
* `XK` is not an ["exceptional reservation"](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Reserved_code_elements) code in the ISO-3166-1 standard, but it's still being used by various organizations as a temporary "country code" for Kosovo.
|
|
400
|
+
* The last official ISO-3166-2 ["subdivision code"](https://en.wikipedia.org/wiki/ISO_3166-2) assigned to Kosovo territory [is](https://en.wikipedia.org/wiki/Autonomous_Province_of_Kosovo_and_Metohija) `RS-KM`.
|
|
358
401
|
|
|
359
|
-
There're also other territories
|
|
402
|
+
There're also other territories having a disputed status of an independent state, whose country calling code or telephone numbering plan is different from the one used by their "official" parent territory. These territories are currently not implemented in this library but they could potentially be implemented in some future:
|
|
360
403
|
* `XA` — [Abkhazia](https://en.wikipedia.org/wiki/Abkhazia)
|
|
361
404
|
* History: Abkhazia officially (unilaterally) declared its independence from [Georgia](https://en.wikipedia.org/wiki/Georgia_(country)) (`GE`) in 1994 after a 1992-1994 civil war. The first state to officially recognize Abkhazia's independence was Russia in 2008.
|
|
362
|
-
* Abkhazia currently shares a country calling code of `+7` with Russia
|
|
405
|
+
* Abkhazia currently shares a country calling code of `+7` with [Russia](https://en.wikipedia.org/wiki/Russia) (`RU`) where it has [unique prefixes](https://en.wikipedia.org/wiki/Telephone_numbers_in_Russia#Codes_assigned_to_Abkhazia) of `840` and `940`, so the "country code" is currently `RU` rather than `XA`.
|
|
363
406
|
* `XA` is not an ["exceptional reservation"](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Reserved_code_elements) code in the ISO-3166-1 standard, but it's still being used by some organizations as a temporary "country code" for Abkhazia.
|
|
407
|
+
* The last official ISO-3166-2 ["subdivision code"](https://en.wikipedia.org/wiki/ISO_3166-2) assigned to Abkhazia territory [is](https://en.wikipedia.org/wiki/ISO_3166-2:GE) `GE-AB`.
|
|
364
408
|
* `XO` — [South Ossetia](https://en.wikipedia.org/wiki/South_Ossetia)
|
|
365
409
|
* History: South Ossetia officially (unilaterally) declared its independence from [Georgia](https://en.wikipedia.org/wiki/Georgia_(country)) (`GE`) in 1992 after a 1991–1992 civil war. The first state to officially recognize South Ossetia's independence was Russia in 2008.
|
|
366
|
-
* South Ossetia currently shares a country calling code of `+7` with Russia
|
|
410
|
+
* South Ossetia currently shares a country calling code of `+7` with [Russia](https://en.wikipedia.org/wiki/Russia) (`RU`) where it has [unique prefixes](https://en.wikipedia.org/wiki/Telephone_numbers_in_Russia#Codes_assigned_to_South_Ossetia) of `850` and `929`, so the "country code" is currently `RU` rather than `XO`.
|
|
367
411
|
* `XO` is not an ["exceptional reservation"](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Reserved_code_elements) code in the ISO-3166-1 standard, but it's still being used by some organizations as a temporary "country code" for South Ossetia.
|
|
368
|
-
|
|
369
|
-
To check whether a certain two-letter "country code" is supported by this library, use [`isSupportedCountry()`](#issupportedcountrycountry-string-boolean) function.
|
|
370
|
-
|
|
371
|
-
### Non-geographic
|
|
372
|
-
|
|
373
|
-
There're several calling codes that don't belong to any country:
|
|
374
|
-
|
|
375
|
-
* `+800` — [Universal International Toll Free Number](https://en.wikipedia.org/wiki/Toll-free_telephone_number)
|
|
376
|
-
* `+808` — [Universal International Shared Cost Number](https://en.wikipedia.org/wiki/Shared-cost_service)
|
|
377
|
-
* `+870` — [Inmarsat Global Limited](https://en.wikipedia.org/wiki/Inmarsat)
|
|
378
|
-
* `+878` — [Universal Personal Telecommunications](https://en.wikipedia.org/wiki/Universal_Personal_Telecommunications)
|
|
379
|
-
* `+881` — [Global Mobile Satellite System](https://en.wikipedia.org/wiki/Global_Mobile_Satellite_System)
|
|
380
|
-
* `+882` and `+883` — [International Networks](https://en.wikipedia.org/wiki/International_Networks_(country_code))
|
|
381
|
-
* `+888` — [United Nations Office for the Coordination of Humanitarian Affairs](https://en.wikipedia.org/wiki/United_Nations_Office_for_the_Coordination_of_Humanitarian_Affairs#International_Dialing_Code)
|
|
382
|
-
* `+979` — [International Premium Rate Service](https://en.wikipedia.org/wiki/International_Premium_Rate_Service)
|
|
383
|
-
|
|
384
|
-
Such phone numbering plans are called "non-geographic", and their phone numbers' `country` is `undefined`.
|
|
385
|
-
|
|
386
|
-
### National (significant) number
|
|
387
|
-
|
|
388
|
-
"National (significant) number" is all national phone number digits, excluding the "national prefix". Examples:
|
|
389
|
-
* International number: `+1 213 373 4253`. Country: `"US"`. National number: `(213) 373-4253`. National (significant) number: `213 373 4253`
|
|
390
|
-
* Inetrnational number: `+33 1 45 45 32 45`. Country: `"FR"`. National number: `01 45 45 32 45`. Notice the `0` at the start of the national number — it's because in France they [add](https://en.wikipedia.org/wiki/Telephone_numbers_in_France) `0` "national prefix" when writing phone numbers in national format. National (significant) number: `1 45 45 32 45` (doesn't include the "national prefix").
|
|
391
|
-
|
|
392
|
-
### Country calling code
|
|
393
|
-
|
|
394
|
-
"Country calling code" is all digits between the `+` and the [national (significant) number](#national-significant-number) in a number that is written in international format. Examples:
|
|
395
|
-
* International number: `+1 213 373 4253`. Country: `"US"`. National (significant) number: `213 373 4253`. Country calling code: `1`
|
|
396
|
-
* Inetrnational number: `+33 1 45 45 32 45`. Country: `"FR"`. National (significant) number: `1 45 45 32 45`. Country calling code: `33`
|
|
397
|
-
|
|
398
|
-
Several countries could share the same "country calling code". For example, [NANPA](https://en.wikipedia.org/wiki/North_American_Numbering_Plan) countries like USA and Canada share the same `1` country calling code.
|
|
412
|
+
* South Ossetia is currently [not](https://en.wikipedia.org/wiki/ISO_3166-2:GE) assigned any official ISO-3166-2 ["subdivision code"](https://en.wikipedia.org/wiki/ISO_3166-2).
|
|
399
413
|
|
|
400
414
|
## API
|
|
401
415
|
|