libphonenumber-js 1.13.1 → 1.13.3
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/CHANGELOG.md +15 -2
- package/README.md +8 -13
- package/build/isPossible.js +16 -15
- package/build/isPossible.js.map +1 -1
- package/bundle/libphonenumber-js.min.js +1 -1
- package/bundle/libphonenumber-js.min.js.map +1 -1
- package/bundle/libphonenumber-max.js +1 -1
- package/bundle/libphonenumber-max.js.map +1 -1
- package/bundle/libphonenumber-min.js +1 -1
- package/bundle/libphonenumber-min.js.map +1 -1
- package/bundle/libphonenumber-mobile.js +1 -1
- package/bundle/libphonenumber-mobile.js.map +1 -1
- package/es6/isPossible.js +16 -15
- package/es6/isPossible.js.map +1 -1
- package/es6-modern/isPossible.js +16 -15
- package/es6-modern/isPossible.js.map +1 -1
- package/max/metadata/metadata.max.json +1 -1
- package/max/metadata/metadata.max.json.js +1 -1
- package/metadata.full.json +1 -1
- package/metadata.full.json.js +1 -1
- package/metadata.max.json +1 -1
- package/metadata.max.json.js +1 -1
- package/metadata.min.json +1 -1
- package/metadata.min.json.js +1 -1
- package/metadata.mobile.json +1 -1
- package/metadata.mobile.json.js +1 -1
- package/min/metadata/metadata.min.json +1 -1
- package/min/metadata/metadata.min.json.js +1 -1
- package/mobile/metadata/metadata.mobile.json +1 -1
- package/mobile/metadata/metadata.mobile.json.js +1 -1
- package/package.json +1 -1
- package/source/isPossible.js +16 -15
package/CHANGELOG.md
CHANGED
|
@@ -67,8 +67,21 @@ And edit the README:
|
|
|
67
67
|
|
|
68
68
|
<!-- This changelog [only](https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/16#note_594165443) mentions the changes in the code. See [Google's changelog](https://github.com/google/libphonenumber/blob/master/release_notes.txt) for metadata changes. -->
|
|
69
69
|
|
|
70
|
-
<!-- CHANGELOG START -->
|
|
71
|
-
|
|
70
|
+
<!-- CHANGELOG START -->
|
|
71
|
+
|
|
72
|
+
1.13.3 / 22.5.2026
|
|
73
|
+
===================
|
|
74
|
+
|
|
75
|
+
* Updated metadata to version 9.0.31:
|
|
76
|
+
- Updated alternate formatting data for country calling code(s): 84
|
|
77
|
+
- Updated phone metadata for region code(s):
|
|
78
|
+
AI, BO, DZ, ET, GE, GM, IN, TR, UG, VN
|
|
79
|
+
- Updated short number metadata for region code(s): IT
|
|
80
|
+
- Updated geocoding data for country calling code(s): 213 (en)
|
|
81
|
+
- Updated carrier data for country calling code(s):
|
|
82
|
+
34 (en), 43 (en), 84 (en), 90 (en), 220 (en), 251 (en), 256 (en), 354 (en),
|
|
83
|
+
591 (en), 1264 (en)
|
|
84
|
+
|
|
72
85
|
1.13.0 / 08.05.2026
|
|
73
86
|
===================
|
|
74
87
|
|
package/README.md
CHANGED
|
@@ -237,22 +237,17 @@ new AsYouType('US').input('2133734') === '(213) 373-4'
|
|
|
237
237
|
Validates a complete phone number.
|
|
238
238
|
|
|
239
239
|
```js
|
|
240
|
-
import {
|
|
241
|
-
isPossiblePhoneNumber,
|
|
242
|
-
isValidPhoneNumber,
|
|
243
|
-
validatePhoneNumberLength
|
|
244
|
-
} from 'libphonenumber-js'
|
|
240
|
+
import { isPossiblePhoneNumber, isValidPhoneNumber } from 'libphonenumber-js'
|
|
245
241
|
|
|
246
242
|
isPossiblePhoneNumber('8 (800) 555-35-35', 'RU') === true
|
|
247
243
|
isValidPhoneNumber('8 (800) 555-35-35', 'RU') === true
|
|
248
|
-
|
|
249
|
-
validatePhoneNumberLength('8 (800) 555', 'RU') === 'TOO_SHORT' // Length is invalid
|
|
250
|
-
validatePhoneNumberLength('8 (800) 555-35-35', 'RU') === undefined // Length is valid
|
|
251
244
|
```
|
|
252
245
|
|
|
253
|
-
`isPossiblePhoneNumber()`
|
|
246
|
+
`isPossiblePhoneNumber()` validates phone number length.
|
|
247
|
+
|
|
248
|
+
`isValidPhoneNumber()` validates both phone number length and phone number digits.
|
|
254
249
|
|
|
255
|
-
`
|
|
250
|
+
[Choosing between the two](#using-phone-number-validation-feature): I'd personally prefer `isPossiblePhoneNumber()` because its strength is in its weakness. `isValidPhoneNumber()` is a double-edged sword in terms of how strict it is, and when not kept up-to-date, it could get stale over time and start rejecting freshly-assigned phone number ranges.
|
|
256
251
|
|
|
257
252
|
### Full-text search
|
|
258
253
|
|
|
@@ -660,7 +655,7 @@ Checks if the phone number is "possible". Only checks the phone number length. D
|
|
|
660
655
|
|
|
661
656
|
Checks if the phone number is "valid". First checks the phone number length and then checks the phone number digits against all available regular expressions.
|
|
662
657
|
|
|
663
|
-
By default, this
|
|
658
|
+
By default, this package uses [`min`](#min-vs-max-vs-mobile-vs-core) ("minimal") metadata which is only `80 kB` in size but also doesn't include the precise regular expressions for validating phone number digits, i.e. it only validates phone number length, effectively causing `isValid()` to behave same way as if it was `isPossible()`. So if you need to validate phone number digits themselves and you don't mind the extra `65 kB` of metadata then use [`max`](#min-vs-max-vs-mobile-vs-core) metadata instead of the default (`min`) one. For reference, Google's original `libphonenumber` always uses `max` metadata and doesn't have a concept of `min` metadata.
|
|
664
659
|
|
|
665
660
|
<details>
|
|
666
661
|
<summary>See an example illustrating different results when using <code>/min</code> vs <code>/max</code> vs <code>/mobile</code> metadata</summary>
|
|
@@ -1580,9 +1575,9 @@ isValidNumberForRegion('07624369230', 'IM') === true
|
|
|
1580
1575
|
|
|
1581
1576
|
## Using phone number validation feature
|
|
1582
1577
|
|
|
1583
|
-
|
|
1578
|
+
When choosing between [`.isValid()`](#isvalid-boolean) and [`.isPossible()`](#ispossible-boolean), I'd personally prefer the latter. The rationale is that telephone numbering plans can and sometimes do change, meaning that [`.isValid()`](#isvalid-boolean) function may one day become outdated on a website that isn't actively maintained anymore. Imagine a "promo-site" or a "personal website" being deployed once and then running for years without any maintenance, where a client may be unable to submit a simple "Contact Us" form just because this newly-allocated pool of mobile phone numbers wasn't present in that old version of `libphonenumber-js` that was used when building the website.
|
|
1584
1579
|
|
|
1585
|
-
Whenever there's a "business requirement" to validate phone number input, I prefer using [
|
|
1580
|
+
Whenever there's a "business requirement" to validate phone number input, I prefer using [`.isPossible()`](#ispossible-boolean) instead of [`.isValid()`](#isvalid-boolean), so that it just validates the phone number length and doesn't validate the actual phone number digits. But it doesn't mean that you shouldn't use [`.isValid()`](#isvalid-boolean) — maybe in your case it would make sense. Just be warned that by using [`.isValid()`](#isvalid-boolean) in an application or on a website, you volunteer to keep it updated for the rest of its lifespan.
|
|
1586
1581
|
|
|
1587
1582
|
## React
|
|
1588
1583
|
|
package/build/isPossible.js
CHANGED
|
@@ -49,24 +49,25 @@ function isPossiblePhoneNumber(input, options, metadata) {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
// Old metadata (< 1.0.18) had no "possible length" data.
|
|
52
|
+
// Old (legacy) metadata (< 1.0.18) had no "possible length" data.
|
|
53
|
+
// So `isPossibleNumber()` function is supported only for non-legacy metadata.
|
|
53
54
|
if (metadata.possibleLengths()) {
|
|
54
55
|
return isPossibleNumber(input.phone || input.nationalNumber, input.country, metadata);
|
|
55
|
-
} else {
|
|
56
|
-
// There was a bug between `1.7.35` and `1.7.37` where "possible_lengths"
|
|
57
|
-
// were missing for "non-geographical" numbering plans.
|
|
58
|
-
// Just assume the number is possible in such cases:
|
|
59
|
-
// it's unlikely that anyone generated their custom metadata
|
|
60
|
-
// in that short period of time (one day).
|
|
61
|
-
// This code can be removed in some future major version update.
|
|
62
|
-
if (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {
|
|
63
|
-
// "Non-geographic entities" did't have `possibleLengths`
|
|
64
|
-
// due to a bug in metadata generation process.
|
|
65
|
-
return true;
|
|
66
|
-
} else {
|
|
67
|
-
throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.');
|
|
68
|
-
}
|
|
69
56
|
}
|
|
57
|
+
|
|
58
|
+
// There was a bug in versions from `1.7.35` to `1.7.37` of `libphonenumber-js`
|
|
59
|
+
// where "possible_lengths" property was missing from "non-geographical" numbering plans' metadata.
|
|
60
|
+
// After that, the bug was noticed and fixed.
|
|
61
|
+
// So for versions from `1.7.35` to `1.7.37`, just assume that all "non=geotraphical" numbers are possible.
|
|
62
|
+
// The reason is that the bug was noticed relatively quickly (within a day or so)
|
|
63
|
+
// and it's unlikely that anyone generated their custom metadata in that short time span.
|
|
64
|
+
// And if they didn't generate any custom metadata then a follow-up package update would've silently fixed the bug.
|
|
65
|
+
if (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// `isPossibleNumber()` function is not supported.
|
|
70
|
+
throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.');
|
|
70
71
|
}
|
|
71
72
|
function isPossibleNumber(nationalNumber, country, metadata) {
|
|
72
73
|
//, isInternational) {
|
package/build/isPossible.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPossible.js","names":["_metadata","_interopRequireDefault","require","_checkNumberLength","e","__esModule","isPossiblePhoneNumber","input","options","metadata","undefined","Metadata","v2","countryCallingCode","Error","selectNumberingPlan","phone","country","hasCountry","concat","possibleLengths","isPossibleNumber","nationalNumber","isNonGeographicCallingCode","checkNumberLength"],"sources":["../source/isPossible.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport checkNumberLength from './helpers/checkNumberLength.js'\r\n\r\n/**\r\n * Checks if a phone number is \"possible\" (basically just checks its length).\r\n *\r\n * isPossible(phoneNumberInstance, { ..., v2: true }, metadata)\r\n *\r\n * isPossible({ phone: '8005553535', country: 'RU' }, { ... }, metadata)\r\n * isPossible({ phone: '8005553535', country: 'RU' }, undefined, metadata)\r\n *\r\n * @param {object|PhoneNumber} input — If `options.v2: true` flag is passed, the `input` should be a `PhoneNumber` instance. Otherwise, it should be an object of shape `{ phone: '...', country: '...' }`.\r\n * @param {object} [options]\r\n * @param {object} metadata\r\n * @return {string}\r\n */\r\nexport default function isPossiblePhoneNumber(input, options, metadata) {\r\n\t/* istanbul ignore if */\r\n\tif (options === undefined) {\r\n\t\toptions = {}\r\n\t}\r\n\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\tif (options.v2) {\r\n\t\tif (!input.countryCallingCode) {\r\n\t\t\tthrow new Error('Invalid phone number object passed')\r\n\t\t}\r\n\t\tmetadata.selectNumberingPlan(input.countryCallingCode)\r\n\t} else {\r\n\t\tif (!input.phone) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\tif (input.country) {\r\n\t\t\tif (!metadata.hasCountry(input.country)) {\r\n\t\t\t\tthrow new Error(`Unknown country: ${input.country}`)\r\n\t\t\t}\r\n\t\t\tmetadata.selectNumberingPlan(input.country)\r\n\t\t} else {\r\n\t\t\tif (!input.countryCallingCode) {\r\n\t\t\t\tthrow new Error('Invalid phone number object passed')\r\n\t\t\t}\r\n\t\t\tmetadata.selectNumberingPlan(input.countryCallingCode)\r\n\t\t}\r\n\t}\r\n\r\n\t// Old metadata (< 1.0.18) had no \"possible length\" data.\r\n\tif (metadata.possibleLengths()) {\r\n\t\treturn isPossibleNumber(input.phone || input.nationalNumber, input.country, metadata)\r\n\t}
|
|
1
|
+
{"version":3,"file":"isPossible.js","names":["_metadata","_interopRequireDefault","require","_checkNumberLength","e","__esModule","isPossiblePhoneNumber","input","options","metadata","undefined","Metadata","v2","countryCallingCode","Error","selectNumberingPlan","phone","country","hasCountry","concat","possibleLengths","isPossibleNumber","nationalNumber","isNonGeographicCallingCode","checkNumberLength"],"sources":["../source/isPossible.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport checkNumberLength from './helpers/checkNumberLength.js'\r\n\r\n/**\r\n * Checks if a phone number is \"possible\" (basically just checks its length).\r\n *\r\n * isPossible(phoneNumberInstance, { ..., v2: true }, metadata)\r\n *\r\n * isPossible({ phone: '8005553535', country: 'RU' }, { ... }, metadata)\r\n * isPossible({ phone: '8005553535', country: 'RU' }, undefined, metadata)\r\n *\r\n * @param {object|PhoneNumber} input — If `options.v2: true` flag is passed, the `input` should be a `PhoneNumber` instance. Otherwise, it should be an object of shape `{ phone: '...', country: '...' }`.\r\n * @param {object} [options]\r\n * @param {object} metadata\r\n * @return {string}\r\n */\r\nexport default function isPossiblePhoneNumber(input, options, metadata) {\r\n\t/* istanbul ignore if */\r\n\tif (options === undefined) {\r\n\t\toptions = {}\r\n\t}\r\n\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\tif (options.v2) {\r\n\t\tif (!input.countryCallingCode) {\r\n\t\t\tthrow new Error('Invalid phone number object passed')\r\n\t\t}\r\n\t\tmetadata.selectNumberingPlan(input.countryCallingCode)\r\n\t} else {\r\n\t\tif (!input.phone) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\tif (input.country) {\r\n\t\t\tif (!metadata.hasCountry(input.country)) {\r\n\t\t\t\tthrow new Error(`Unknown country: ${input.country}`)\r\n\t\t\t}\r\n\t\t\tmetadata.selectNumberingPlan(input.country)\r\n\t\t} else {\r\n\t\t\tif (!input.countryCallingCode) {\r\n\t\t\t\tthrow new Error('Invalid phone number object passed')\r\n\t\t\t}\r\n\t\t\tmetadata.selectNumberingPlan(input.countryCallingCode)\r\n\t\t}\r\n\t}\r\n\r\n\t// Old (legacy) metadata (< 1.0.18) had no \"possible length\" data.\r\n\t// So `isPossibleNumber()` function is supported only for non-legacy metadata.\r\n\tif (metadata.possibleLengths()) {\r\n\t\treturn isPossibleNumber(input.phone || input.nationalNumber, input.country, metadata)\r\n\t}\r\n\r\n\t// There was a bug in versions from `1.7.35` to `1.7.37` of `libphonenumber-js`\r\n\t// where \"possible_lengths\" property was missing from \"non-geographical\" numbering plans' metadata.\r\n\t// After that, the bug was noticed and fixed.\r\n\t// So for versions from `1.7.35` to `1.7.37`, just assume that all \"non=geotraphical\" numbers are possible.\r\n\t// The reason is that the bug was noticed relatively quickly (within a day or so)\r\n\t// and it's unlikely that anyone generated their custom metadata in that short time span.\r\n\t// And if they didn't generate any custom metadata then a follow-up package update would've silently fixed the bug.\r\n\tif (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {\r\n\t\treturn true\r\n\t}\r\n\r\n\t// `isPossibleNumber()` function is not supported.\r\n\tthrow new Error('Missing \"possibleLengths\" in metadata. Perhaps the metadata has been generated before v1.0.18.');\r\n}\r\n\r\nexport function isPossibleNumber(nationalNumber, country, metadata) { //, isInternational) {\r\n\tswitch (checkNumberLength(nationalNumber, country, metadata)) {\r\n\t\tcase 'IS_POSSIBLE':\r\n\t\t\treturn true\r\n\t\t// This library ignores \"local-only\" phone numbers (for simplicity).\r\n\t\t// See the readme for more info on what are \"local-only\" phone numbers.\r\n\t\t// case 'IS_POSSIBLE_LOCAL_ONLY':\r\n\t\t// \treturn !isInternational\r\n\t\tdefault:\r\n\t\t\treturn false\r\n\t}\r\n}"],"mappings":";;;;;;;AAAA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAF,sBAAA,CAAAC,OAAA;AAA8D,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,gBAAAA,CAAA;AAE9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASE,qBAAqBA,CAACC,KAAK,EAAEC,OAAO,EAAEC,QAAQ,EAAE;EACvE;EACA,IAAID,OAAO,KAAKE,SAAS,EAAE;IAC1BF,OAAO,GAAG,CAAC,CAAC;EACb;EAEAC,QAAQ,GAAG,IAAIE,oBAAQ,CAACF,QAAQ,CAAC;EAEjC,IAAID,OAAO,CAACI,EAAE,EAAE;IACf,IAAI,CAACL,KAAK,CAACM,kBAAkB,EAAE;MAC9B,MAAM,IAAIC,KAAK,CAAC,oCAAoC,CAAC;IACtD;IACAL,QAAQ,CAACM,mBAAmB,CAACR,KAAK,CAACM,kBAAkB,CAAC;EACvD,CAAC,MAAM;IACN,IAAI,CAACN,KAAK,CAACS,KAAK,EA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