libphonenumber-js 1.12.26 → 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.
Files changed (2) hide show
  1. package/README.md +67 -34
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -333,25 +333,23 @@ As for "custom" metadata, it could be used in those rare cases when not all coun
333
333
 
334
334
  ## Definitions
335
335
 
336
- ### Country code
336
+ ### National (Significant) Number
337
337
 
338
- A "country code" is a [two-letter ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) (like `"US"`). <!-- 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)). -->
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").
339
341
 
340
- This library supports all [officially assigned](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) ISO alpha-2 country codes, plus a few extra ones: `AC` ([Ascension Island](https://en.wikipedia.org/wiki/Ascension_Island)), `TA` ([Tristan da Cunha](https://en.wikipedia.org/wiki/Tristan_da_Cunha)), `XK` ([Kosovo](https://en.wikipedia.org/wiki/Kosovo)).
342
+ ### Country Calling Code
341
343
 
342
- <!--
343
- var countries = []
344
- for (const code of Object.keys(country_calling_codes)) {
345
- countries = countries.concat(country_calling_codes[code])
346
- }
347
- console.log(countries.length)
348
- -->
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`
349
347
 
350
- To check whether a country code is supported, use [`isSupportedCountry()`](#issupportedcountrycountry-string-boolean) function.
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`.
351
349
 
352
- ### Non-geographic
350
+ ### Non-Geographic
353
351
 
354
- There're several calling codes that don't belong to any country:
352
+ The following "calling codes" don't belong to any given country or territory and are inherently international:
355
353
 
356
354
  * `+800` — [Universal International Toll Free Number](https://en.wikipedia.org/wiki/Toll-free_telephone_number)
357
355
  * `+808` — [Universal International Shared Cost Number](https://en.wikipedia.org/wiki/Shared-cost_service)
@@ -362,21 +360,56 @@ There're several calling codes that don't belong to any country:
362
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)
363
361
  * `+979` — [International Premium Rate Service](https://en.wikipedia.org/wiki/International_Premium_Rate_Service)
364
362
 
365
- Such phone numbering plans are called "non-geographic", and their phone numbers' `country` is `undefined`.
366
-
367
- ### National (significant) number
368
-
369
- "National (significant) number" is all national phone number digits, excluding the "national prefix". Examples:
370
- * International number: `+1 213 373 4253`. Country: `"US"`. National number: `(213) 373-4253`. National (significant) number: `213 373 4253`
371
- * 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").
372
-
373
- ### Country calling code
374
-
375
- "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:
376
- * International number: `+1 213 373 4253`. Country: `"US"`. National (significant) number: `213 373 4253`. Country calling code: `1`
377
- * Inetrnational number: `+33 1 45 45 32 45`. Country: `"FR"`. National (significant) number: `1 45 45 32 45`. Country calling code: `33`
378
-
379
- 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.
363
+ Such phone numbers are called "non-geographic", and their `country` is `undefined`.
364
+
365
+ ### Country Code
366
+
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)). -->
368
+
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.
376
+
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":
382
+ * `AC` — [Ascension Island](https://en.wikipedia.org/wiki/Ascension_Island)
383
+ * Ascension Island is officially part of [Saint Helena, Ascension and Tristan da Cunha
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`.
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`.
387
+ * `TA` — [Tristan da Cunha](https://en.wikipedia.org/wiki/Tristan_da_Cunha)
388
+ * Tristan da Cunha is officially part of [Saint Helena, Ascension and Tristan da Cunha
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`.
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`.
392
+ * `SH` — [Saint Helena](https://en.wikipedia.org/wiki/Saint_Helena)
393
+ * Saint Helena is officially part of [Saint Helena, Ascension and Tristan da Cunha
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`.
396
+ * `XK` — [Kosovo](https://en.wikipedia.org/wiki/Kosovo)
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.
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`.
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`.
401
+
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:
403
+ * `XA` — [Abkhazia](https://en.wikipedia.org/wiki/Abkhazia)
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.
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`.
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`.
408
+ * `XO` — [South Ossetia](https://en.wikipedia.org/wiki/South_Ossetia)
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.
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`.
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.
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).
380
413
 
381
414
  ## API
382
415
 
@@ -400,7 +433,7 @@ Returns an instance of [`PhoneNumber`](#phonenumber) class, or `undefined` if no
400
433
 
401
434
  Available `options`:
402
435
 
403
- * `defaultCountry: string` — Default [country](#country-code) for parsing numbers written in non-international form (without a `+` sign). Will be ignored when parsing numbers written in international form (with a `+` sign). Instead of passing it as `options.defaultCountry`, one could also pass it as a standalone `defaultCountry` argument (for convenience).
436
+ * `defaultCountry: string` — Default [country code](#country-code) for parsing numbers written in non-international form (without a `+` sign). Will be ignored when parsing numbers written in international form (with a `+` sign). Instead of passing it as `options.defaultCountry`, one could also pass it as a standalone `defaultCountry` argument (for convenience).
404
437
 
405
438
  * `defaultCallingCode: string` — Default calling code for parsing numbers written in non-international form (without a `+` sign). Will be ignored when parsing numbers written in international form (with a `+` sign). It could be specified when parsing phone numbers belonging to ["non-geographic numbering plans"](#non-geographic) which by nature don't have a country code, making the `defaultCountry` option unusable.
406
439
 
@@ -904,7 +937,7 @@ asYouType.getTemplate() === 'xx xxx xxx xxxx'
904
937
 
905
938
  For legacy API (before version `1.6.0`) the formatter instance provides the following getters:
906
939
 
907
- * `country: string?` — Phone number [country](#country-code). Will return `undefined` if the country couldn't be derived from the number.
940
+ * `country: string?` — The [country code](#country-code) of the phone number. Will return `undefined` if the country couldn't be derived from the number.
908
941
 
909
942
  * `getNationalNumber(): string` — Returns the national (significant) number part of the phone number.
910
943
 
@@ -1082,7 +1115,7 @@ Although Google's javascript port doesn't provide the `findPhoneNumbersInText()`
1082
1115
 
1083
1116
  ### getExampleNumber(country: string, examples: object): PhoneNumber
1084
1117
 
1085
- Returns an example phone number for a [country](#country-code). Returns an instance of [`PhoneNumber`](#phonenumber) class. Will return `undefined` if `country` doesn't exist or isn't supported by this library.
1118
+ Returns an example phone number for a [country code](#country-code). Returns an instance of [`PhoneNumber`](#phonenumber) class. Will return `undefined` if `country` doesn't exist or isn't supported by this library.
1086
1119
 
1087
1120
  ```js
1088
1121
  import examples from 'libphonenumber-js/mobile/examples'
@@ -1095,7 +1128,7 @@ phoneNumber.formatNational() === '8 (912) 345-67-89'
1095
1128
 
1096
1129
  ### isSupportedCountry(country: string): boolean
1097
1130
 
1098
- Checks if a [country](#country-code) is supported by this library.
1131
+ Checks if a given [country code](#country-code) is supported by this library.
1099
1132
 
1100
1133
  ```js
1101
1134
  isSupportedCountry('RU') === true
@@ -1114,7 +1147,7 @@ getCountries() === ["AC", "AD", ...]
1114
1147
 
1115
1148
  ### getCountryCallingCode(country: string): string
1116
1149
 
1117
- Returns [country calling code](#country-calling-code) for a [country](#country-code). Will throw an error if `country` doesn't exist or isn't supported by this library.
1150
+ Returns [country calling code](#country-calling-code) for a [country code](#country-code). Will throw an error if `country` doesn't exist or isn't supported by this library.
1118
1151
 
1119
1152
  ```js
1120
1153
  getCountryCallingCode('RU') === '7'
@@ -1123,7 +1156,7 @@ getCountryCallingCode('IL') === '972'
1123
1156
 
1124
1157
  ### getExtPrefix(country: string): string
1125
1158
 
1126
- Returns phone number extension prefix for a given [country](#country-code). If no custom ext prefix is defined for a `country` then the default `" ext. "` prefix is returned.
1159
+ Returns phone number extension prefix for a given [country code](#country-code). If no custom ext prefix is defined for a `country` then the default `" ext. "` prefix is returned.
1127
1160
 
1128
1161
  ```js
1129
1162
  getExtPrefix('US') === ' ext. '
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libphonenumber-js",
3
- "version": "1.12.26",
3
+ "version": "1.12.28",
4
4
  "description": "A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript",
5
5
  "main": "index.cjs",
6
6
  "module": "index.js",