libphonenumber-js 1.12.16 → 1.12.18
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 +40 -35
- package/METADATA.md +2 -0
- package/README.md +209 -158
- package/build/AsYouType.js +6 -8
- package/build/AsYouType.js.map +1 -1
- package/build/AsYouType.test.js +13 -14
- package/build/AsYouType.test.js.map +1 -1
- package/build/AsYouTypeFormatter.complete.js +4 -4
- package/build/AsYouTypeFormatter.complete.js.map +1 -1
- package/build/AsYouTypeFormatter.js +4 -4
- package/build/AsYouTypeFormatter.js.map +1 -1
- package/build/AsYouTypeParser.js +42 -29
- package/build/AsYouTypeParser.js.map +1 -1
- package/build/AsYouTypeState.js +21 -17
- package/build/AsYouTypeState.js.map +1 -1
- package/build/PhoneNumber.js +2 -2
- package/build/PhoneNumber.js.map +1 -1
- package/build/findNumbers/Leniency.js +0 -1
- package/build/findNumbers/Leniency.js.map +1 -1
- package/build/format.js +4 -4
- package/build/format.js.map +1 -1
- package/build/formatPhoneNumberForMobileDialing.js +2 -2
- package/build/formatPhoneNumberForMobileDialing.js.map +1 -1
- package/build/helpers/checkNumberLength.js +39 -7
- package/build/helpers/checkNumberLength.js.map +1 -1
- package/build/helpers/checkNumberLength.test.js +51 -12
- package/build/helpers/checkNumberLength.test.js.map +1 -1
- package/build/helpers/extractCountryCallingCode.js +13 -10
- package/build/helpers/extractCountryCallingCode.js.map +1 -1
- package/build/helpers/extractCountryCallingCode.test.js +3 -3
- package/build/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +10 -8
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
- package/build/helpers/extractNationalNumber.js +15 -5
- package/build/helpers/extractNationalNumber.js.map +1 -1
- package/build/helpers/extractNationalNumber.test.js +10 -2
- package/build/helpers/extractNationalNumber.test.js.map +1 -1
- package/build/helpers/getCountryByCallingCode.js +3 -2
- package/build/helpers/getCountryByCallingCode.js.map +1 -1
- package/build/helpers/getCountryByNationalNumber.js +27 -6
- package/build/helpers/getCountryByNationalNumber.js.map +1 -1
- package/build/helpers/matchesEntirely.js +4 -4
- package/build/helpers/matchesEntirely.js.map +1 -1
- package/build/isPossible.js +4 -4
- package/build/isPossible.js.map +1 -1
- package/build/isPossible.test.js +7 -0
- package/build/isPossible.test.js.map +1 -1
- package/build/isPossiblePhoneNumber.test.js +4 -0
- package/build/isPossiblePhoneNumber.test.js.map +1 -1
- package/build/metadata.js +2 -2
- package/build/metadata.js.map +1 -1
- package/build/parse.js +9 -7
- package/build/parse.js.map +1 -1
- package/build/parseIncompletePhoneNumber.js +7 -7
- package/build/parseIncompletePhoneNumber.js.map +1 -1
- package/build/parsePhoneNumber.test.js +12 -0
- package/build/parsePhoneNumber.test.js.map +1 -1
- package/build/validatePhoneNumberLength.js +1 -1
- package/build/validatePhoneNumberLength.js.map +1 -1
- package/build-scripts/check-for-metadata-changes-and-create-pull-request.js +87 -0
- package/{runnable/metadata-update-and-release.js → build-scripts/check-for-metadata-changes-and-release.js} +10 -4
- package/{runnable/json-to-js.js → build-scripts/create-js-file-for-json-file.js} +2 -2
- package/{runnable/metadata-branch.js → build-scripts/create-metadata-update-branch.js} +6 -1
- package/{runnable/generate-country-codes.js → build-scripts/generate-country-codes-list-in-typescript.js} +1 -0
- package/{runnable/generate.js → build-scripts/generate-metadata-from-google-metadata.js} +8 -14
- package/{runnable/modules → build-scripts/helpers}/commit.js +1 -0
- package/{runnable/modules → build-scripts/helpers}/exec.js +1 -0
- package/{runnable/modules/update-metadata.js → build-scripts/helpers/update-metadata-from-google-metadata.js} +9 -7
- package/{runnable/download.js → build-scripts/pull-google-metadata.js} +12 -4
- 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/core/index.d.cts +1 -1
- package/core/index.d.ts +1 -1
- package/custom.d.ts +1 -1
- package/es6/AsYouType.js +6 -8
- package/es6/AsYouType.js.map +1 -1
- package/es6/AsYouType.test.js +13 -14
- package/es6/AsYouType.test.js.map +1 -1
- package/es6/AsYouTypeFormatter.complete.js +4 -4
- package/es6/AsYouTypeFormatter.complete.js.map +1 -1
- package/es6/AsYouTypeFormatter.js +4 -4
- package/es6/AsYouTypeFormatter.js.map +1 -1
- package/es6/AsYouTypeParser.js +42 -29
- package/es6/AsYouTypeParser.js.map +1 -1
- package/es6/AsYouTypeState.js +21 -17
- package/es6/AsYouTypeState.js.map +1 -1
- package/es6/PhoneNumber.js +1 -2
- package/es6/PhoneNumber.js.map +1 -1
- package/es6/findNumbers/Leniency.js +0 -1
- package/es6/findNumbers/Leniency.js.map +1 -1
- package/es6/format.js +4 -4
- package/es6/format.js.map +1 -1
- package/es6/formatPhoneNumberForMobileDialing.js +2 -2
- package/es6/formatPhoneNumberForMobileDialing.js.map +1 -1
- package/es6/helpers/checkNumberLength.js +39 -7
- package/es6/helpers/checkNumberLength.js.map +1 -1
- package/es6/helpers/checkNumberLength.test.js +49 -12
- package/es6/helpers/checkNumberLength.test.js.map +1 -1
- package/es6/helpers/extractCountryCallingCode.js +13 -10
- package/es6/helpers/extractCountryCallingCode.js.map +1 -1
- package/es6/helpers/extractCountryCallingCode.test.js +3 -3
- package/es6/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +10 -8
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
- package/es6/helpers/extractNationalNumber.js +15 -5
- package/es6/helpers/extractNationalNumber.js.map +1 -1
- package/es6/helpers/extractNationalNumber.test.js +10 -2
- package/es6/helpers/extractNationalNumber.test.js.map +1 -1
- package/es6/helpers/getCountryByCallingCode.js +3 -2
- package/es6/helpers/getCountryByCallingCode.js.map +1 -1
- package/es6/helpers/getCountryByNationalNumber.js +28 -6
- package/es6/helpers/getCountryByNationalNumber.js.map +1 -1
- package/es6/helpers/matchesEntirely.js +4 -4
- package/es6/helpers/matchesEntirely.js.map +1 -1
- package/es6/isPossible.js +4 -4
- package/es6/isPossible.js.map +1 -1
- package/es6/isPossible.test.js +7 -0
- package/es6/isPossible.test.js.map +1 -1
- package/es6/isPossiblePhoneNumber.test.js +4 -0
- package/es6/isPossiblePhoneNumber.test.js.map +1 -1
- package/es6/metadata.js +2 -2
- package/es6/metadata.js.map +1 -1
- package/es6/parse.js +9 -7
- package/es6/parse.js.map +1 -1
- package/es6/parseIncompletePhoneNumber.js +7 -7
- package/es6/parseIncompletePhoneNumber.js.map +1 -1
- package/es6/parsePhoneNumber.test.js +12 -0
- package/es6/parsePhoneNumber.test.js.map +1 -1
- package/es6/validatePhoneNumberLength.js +1 -1
- package/es6/validatePhoneNumberLength.js.map +1 -1
- package/index.d.cts +1 -1
- package/index.d.ts +1 -1
- package/max/index.d.cts +1 -1
- package/max/index.d.ts +1 -1
- package/min/index.d.cts +1 -1
- package/min/index.d.ts +1 -1
- package/mobile/index.d.cts +1 -1
- package/mobile/index.d.ts +1 -1
- package/package.json +16 -23
- package/source/AsYouType.js +8 -10
- package/source/AsYouType.test.js +13 -14
- package/source/AsYouTypeFormatter.complete.js +4 -4
- package/source/AsYouTypeFormatter.js +4 -4
- package/source/AsYouTypeParser.js +45 -28
- package/source/AsYouTypeState.js +21 -17
- package/source/PhoneNumber.js +1 -2
- package/source/findNumbers/Leniency.js +0 -1
- package/source/format.js +4 -4
- package/source/formatPhoneNumberForMobileDialing.js +2 -2
- package/source/helpers/checkNumberLength.js +40 -7
- package/source/helpers/checkNumberLength.test.js +54 -12
- package/source/helpers/extractCountryCallingCode.js +15 -10
- package/source/helpers/extractCountryCallingCode.test.js +3 -3
- package/source/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +19 -8
- package/source/helpers/extractNationalNumber.js +15 -5
- package/source/helpers/extractNationalNumber.test.js +11 -2
- package/source/helpers/getCountryByCallingCode.js +2 -2
- package/source/helpers/getCountryByNationalNumber.js +27 -6
- package/source/helpers/matchesEntirely.js +4 -4
- package/source/isPossible.js +4 -4
- package/source/isPossible.test.js +9 -0
- package/source/isPossiblePhoneNumber.test.js +5 -0
- package/source/metadata.js +2 -2
- package/source/parse.js +9 -5
- package/source/parseIncompletePhoneNumber.js +7 -7
- package/source/parsePhoneNumber.test.js +14 -0
- package/source/validatePhoneNumberLength.js +1 -1
- package/runnable/metadata-update-and-push-and-pull-request.js +0 -47
- package/runnable/metadata-update-and-push.js +0 -30
- /package/{runnable/create-commonjs-package-json.js → build-scripts/create-commonjs-package-json-file.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libphonenumber-js",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.18",
|
|
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",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"istanbul": "^1.1.0-alpha.1",
|
|
103
103
|
"jest": "^30.0.5",
|
|
104
104
|
"jest-codemods": "^0.34.2",
|
|
105
|
-
"libphonenumber-metadata-generator": "^2.0.
|
|
105
|
+
"libphonenumber-metadata-generator": "^2.0.3",
|
|
106
106
|
"minimist": "^1.2.8",
|
|
107
107
|
"mocha": "^10.0.0",
|
|
108
108
|
"npm-run-all": "^4.1.5",
|
|
@@ -114,26 +114,19 @@
|
|
|
114
114
|
"tslib": "^2.8.1"
|
|
115
115
|
},
|
|
116
116
|
"scripts": {
|
|
117
|
-
"metadata:update:job": "git reset --hard && git pull && npm install && npm run metadata:update
|
|
118
|
-
"metadata:
|
|
119
|
-
"metadata:branch": "node runnable/metadata-branch",
|
|
120
|
-
"metadata:unbranch": "node runnable/metadata-unbranch",
|
|
121
|
-
"metadata:publish": "npm version patch && npm publish && git push",
|
|
122
|
-
"metadata:update:release": "npm run metadata:download && node runnable/metadata-update-and-release",
|
|
123
|
-
"metadata:update:branch": "npm run metadata:branch && npm run metadata:download && node runnable/metadata-update-and-push",
|
|
124
|
-
"metadata:update:pull-request": "npm run metadata:branch && npm run metadata:download && node runnable/metadata-update-and-push-and-pull-request",
|
|
117
|
+
"metadata:update:job": "git reset --hard && git pull && npm install && npm run metadata:update-and-release",
|
|
118
|
+
"metadata:update-and-release": "node build-scripts/pull-google-metadata ./PhoneNumberMetadata.xml ./metadata-info.json && node build-scripts/check-for-metadata-changes-and-release ./PhoneNumberMetadata.xml ./metadata-info.json",
|
|
125
119
|
"metadata:generate": "npm-run-all metadata:generate:min metadata:generate:full metadata:generate:max metadata:generate:mobile metadata:generate:min:js metadata:generate:full:js metadata:generate:max:js metadata:generate:mobile:js metadata:generate:mobile:examples:js",
|
|
126
|
-
"metadata:generate:min": "node
|
|
127
|
-
"metadata:generate:full": "node
|
|
128
|
-
"metadata:generate:max": "node
|
|
129
|
-
"metadata:generate:mobile": "node
|
|
130
|
-
"metadata:generate:min:js": "node
|
|
131
|
-
"metadata:generate:full:js": "node
|
|
132
|
-
"metadata:generate:max:js": "node
|
|
133
|
-
"metadata:generate:mobile:js": "node
|
|
134
|
-
"metadata:generate:mobile:examples:js": "node
|
|
135
|
-
"
|
|
136
|
-
"generate-country-codes": "node --experimental-json-modules runnable/generate-country-codes",
|
|
120
|
+
"metadata:generate:min": "node build-scripts/generate-metadata-from-google-metadata ./PhoneNumberMetadata.xml ./metadata.min.json --examples mobile",
|
|
121
|
+
"metadata:generate:full": "node build-scripts/generate-metadata-from-google-metadata ./PhoneNumberMetadata.xml ./metadata.full.json --extended --debug",
|
|
122
|
+
"metadata:generate:max": "node build-scripts/generate-metadata-from-google-metadata ./PhoneNumberMetadata.xml ./metadata.max.json --extended --debug",
|
|
123
|
+
"metadata:generate:mobile": "node build-scripts/generate-metadata-from-google-metadata ./PhoneNumberMetadata.xml ./metadata.mobile.json --types mobile",
|
|
124
|
+
"metadata:generate:min:js": "node build-scripts/create-js-file-for-json-file ./metadata.min.json",
|
|
125
|
+
"metadata:generate:full:js": "node build-scripts/create-js-file-for-json-file ./metadata.full.json",
|
|
126
|
+
"metadata:generate:max:js": "node build-scripts/create-js-file-for-json-file ./metadata.max.json",
|
|
127
|
+
"metadata:generate:mobile:js": "node build-scripts/create-js-file-for-json-file ./metadata.mobile.json",
|
|
128
|
+
"metadata:generate:mobile:examples:js": "node build-scripts/create-js-file-for-json-file ./examples.mobile.json",
|
|
129
|
+
"typescript:generate-country-codes-list": "node --experimental-json-modules build-scripts/generate-country-codes-list-in-typescript",
|
|
137
130
|
"transform-mocha-tests-into-jest-tests": "npx jest-codemods",
|
|
138
131
|
"test": "npm run test--mocha",
|
|
139
132
|
"test--jest": "npm-run-all test:except-exports--jest test:exports--mocha",
|
|
@@ -152,7 +145,7 @@
|
|
|
152
145
|
"build:commonjs": "npm-run-all build:commonjs:with-tests build:commonjs:package.json build:commonjs:create-typescript-definitions build:commonjs:patch-typescript-definitions",
|
|
153
146
|
"build:commonjs:before-es-modules": "cross-env BABEL_ENV=commonjs babel ./source --out-dir ./build --source-maps --ignore test.js",
|
|
154
147
|
"build:commonjs:with-tests": "cross-env BABEL_ENV=commonjs babel ./source --out-dir ./build --source-maps",
|
|
155
|
-
"build:commonjs:package.json": "node
|
|
148
|
+
"build:commonjs:package.json": "node build-scripts/create-commonjs-package-json-file.js",
|
|
156
149
|
"build:commonjs:create-typescript-definitions": "rimraf --verbose --glob ./*.d.cts \"./!(node_modules)/**/*.d.cts\" && cpy **/{index,metadata*,examples*,types}.d.ts . --rename={{basename}}.cts && renamer --find d.cts.ts --replace d.cts ./*.d.cts.ts \"./!(node_modules)/**/*.d.cts.ts\"",
|
|
157
150
|
"build:commonjs:patch-typescript-definitions": "replace-in-file \".d.js';\" \".d.cjs';\" **/*.d.cts",
|
|
158
151
|
"build:modules:copy-typescript-definitions": "cpy --flat min/index.d.ts max && cpy --flat min/index.d.ts mobile",
|
|
@@ -165,7 +158,7 @@
|
|
|
165
158
|
"build:modules": "cross-env BABEL_ENV=es6 babel ./source --out-dir ./es6 --source-maps --ignore test.js",
|
|
166
159
|
"build:bundle": "rollup --config rollup.config.mjs",
|
|
167
160
|
"build": "npm-run-all clean build:modules:copy-typescript-definitions build:modules build:commonjs build:bundle build:copy-metadata-files-to-subpackage-folders build:copy-examples-files-to-subpackage-folders",
|
|
168
|
-
"prepublishOnly": "npm run metadata:generate && npm run generate-country-codes && crlf --set=LF metadata.*.json && npm-run-all build test"
|
|
161
|
+
"prepublishOnly": "npm run metadata:generate && npm run typescript:generate-country-codes-list && crlf --set=LF metadata.*.json && npm-run-all build test"
|
|
169
162
|
},
|
|
170
163
|
"repository": {
|
|
171
164
|
"type": "git",
|
package/source/AsYouType.js
CHANGED
|
@@ -96,7 +96,7 @@ export default class AsYouType {
|
|
|
96
96
|
this.state = new AsYouTypeState({
|
|
97
97
|
onCountryChange: (country) => {
|
|
98
98
|
// Before version `1.6.0`, the official `AsYouType` formatter API
|
|
99
|
-
// included
|
|
99
|
+
// included a `.country` property on an `AsYouType` instance.
|
|
100
100
|
// Since that property (along with the others) have been moved to
|
|
101
101
|
// `this.state`, `this.country` property is emulated for compatibility
|
|
102
102
|
// with the old versions.
|
|
@@ -239,11 +239,11 @@ export default class AsYouType {
|
|
|
239
239
|
getNonFormattedNationalNumberWithPrefix() {
|
|
240
240
|
const {
|
|
241
241
|
nationalSignificantNumber,
|
|
242
|
-
|
|
242
|
+
prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix,
|
|
243
243
|
nationalPrefix
|
|
244
244
|
} = this.state
|
|
245
245
|
let number = nationalSignificantNumber
|
|
246
|
-
const prefix =
|
|
246
|
+
const prefix = prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix || nationalPrefix
|
|
247
247
|
if (prefix) {
|
|
248
248
|
number = prefix + number
|
|
249
249
|
}
|
|
@@ -251,11 +251,11 @@ export default class AsYouType {
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
getNonFormattedNumber() {
|
|
254
|
-
const {
|
|
254
|
+
const { nationalSignificantNumberIsModified } = this.state
|
|
255
255
|
return this.getFullNumber(
|
|
256
|
-
|
|
257
|
-
? this.
|
|
258
|
-
: this.
|
|
256
|
+
nationalSignificantNumberIsModified
|
|
257
|
+
? this.state.getNationalDigits()
|
|
258
|
+
: this.getNonFormattedNationalNumberWithPrefix()
|
|
259
259
|
)
|
|
260
260
|
}
|
|
261
261
|
|
|
@@ -272,7 +272,7 @@ export default class AsYouType {
|
|
|
272
272
|
return countryCodes && countryCodes.length > 1
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
// Determines the country of the phone number
|
|
275
|
+
// Determines the exact country of the phone number
|
|
276
276
|
// entered so far based on the country phone code
|
|
277
277
|
// and the national phone number.
|
|
278
278
|
determineTheCountry() {
|
|
@@ -280,7 +280,6 @@ export default class AsYouType {
|
|
|
280
280
|
this.isInternational() ? this.state.callingCode : this.defaultCallingCode,
|
|
281
281
|
{
|
|
282
282
|
nationalNumber: this.state.nationalSignificantNumber,
|
|
283
|
-
defaultCountry: this.defaultCountry,
|
|
284
283
|
metadata: this.metadata
|
|
285
284
|
}
|
|
286
285
|
))
|
|
@@ -386,7 +385,6 @@ export default class AsYouType {
|
|
|
386
385
|
if (ambiguousCountries.length > 1) {
|
|
387
386
|
const exactCountry = getCountryByNationalNumber(nationalSignificantNumber, {
|
|
388
387
|
countries: ambiguousCountries,
|
|
389
|
-
defaultCountry: this.defaultCountry,
|
|
390
388
|
metadata: this.metadata.metadata
|
|
391
389
|
})
|
|
392
390
|
if (exactCountry) {
|
package/source/AsYouType.test.js
CHANGED
|
@@ -630,17 +630,16 @@ describe('AsYouType', () => {
|
|
|
630
630
|
})
|
|
631
631
|
|
|
632
632
|
it('should return non-formatted phone number when no format matches and national (significant) number has digits added', () => {
|
|
633
|
-
// When
|
|
634
|
-
//
|
|
633
|
+
// When inputting "0343515551212999" Argentinian mobile number,
|
|
634
|
+
// the parsed national (significant) number is "93435551212999".
|
|
635
|
+
// There, one can see how it stripped "0" national prefix and prepended a "9",
|
|
636
|
+
// because that's how it is instructed to do in Argentina's metadata.
|
|
637
|
+
//
|
|
638
|
+
// So in this case, national (significant) number doesn't match the input
|
|
639
|
+
// and, therefore, `state.nationalSignificantNumberIsModified` flag is `true`.
|
|
640
|
+
//
|
|
635
641
|
const asYouType = new AsYouType('AR')
|
|
636
|
-
//
|
|
637
|
-
// (no `9` is prepended).
|
|
638
|
-
// First parses national (significant) number by prepending `9` to it
|
|
639
|
-
// and stripping `15` from it.
|
|
640
|
-
// Then uses `$2 15-$3-$4` format that strips the leading `9`
|
|
641
|
-
// and adds `15`.
|
|
642
|
-
// `this.nationalSignificantNumberMatchesInput` is `false` in this case,
|
|
643
|
-
// so `getNonFormattedNumber()` returns `getFullNumber(getNationalDigits())`.
|
|
642
|
+
// This line checks that the formatter didn't alter the output digits compared to the input digits.
|
|
644
643
|
expect(asYouType.input('0343515551212999')).to.equal('0343515551212999')
|
|
645
644
|
})
|
|
646
645
|
|
|
@@ -718,7 +717,7 @@ describe('AsYouType', () => {
|
|
|
718
717
|
expect(formatter.input('081')).to.equal('081')
|
|
719
718
|
})
|
|
720
719
|
|
|
721
|
-
it('should prepend `
|
|
720
|
+
it('should prepend `prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix` (not a complete number)', () => {
|
|
722
721
|
// A country having `national_prefix_for_parsing` with a "capturing group".
|
|
723
722
|
// National prefix is either not used in a format or is optional.
|
|
724
723
|
// Input phone number without a national prefix.
|
|
@@ -730,10 +729,10 @@ describe('AsYouType', () => {
|
|
|
730
729
|
// `formatter.digits` is not always `formatter.nationalPrefix`
|
|
731
730
|
// plus `formatter.nationalNumberDigits`.
|
|
732
731
|
expect(formatter.state.nationalPrefix).to.be.undefined
|
|
733
|
-
expect(formatter.state.
|
|
732
|
+
expect(formatter.state.prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix).to.equal('1831')
|
|
734
733
|
})
|
|
735
734
|
|
|
736
|
-
it('should prepend `
|
|
735
|
+
it('should prepend `prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix` (complete number)', () => {
|
|
737
736
|
// A country having `national_prefix_for_parsing` with a "capturing group".
|
|
738
737
|
// National prefix is either not used in a format or is optional.
|
|
739
738
|
// Input phone number without a national prefix.
|
|
@@ -745,7 +744,7 @@ describe('AsYouType', () => {
|
|
|
745
744
|
// `formatter.digits` is not always `formatter.nationalPrefix`
|
|
746
745
|
// plus `formatter.nationalNumberDigits`.
|
|
747
746
|
expect(formatter.state.nationalPrefix).to.be.undefined
|
|
748
|
-
expect(formatter.state.
|
|
747
|
+
expect(formatter.state.prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix).to.equal('1831')
|
|
749
748
|
})
|
|
750
749
|
|
|
751
750
|
it('should work with Mexico numbers', () => {
|
|
@@ -21,8 +21,8 @@ export default function formatCompleteNumber(state, format, {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function canFormatCompleteNumber(nationalSignificantNumber, metadata) {
|
|
25
|
-
return checkNumberLength(nationalSignificantNumber, metadata) === 'IS_POSSIBLE'
|
|
24
|
+
export function canFormatCompleteNumber(nationalSignificantNumber, country, metadata) {
|
|
25
|
+
return checkNumberLength(nationalSignificantNumber, country, metadata) === 'IS_POSSIBLE'
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
function formatNationalNumberWithAndWithoutNationalPrefixFormattingRule(state, format, {
|
|
@@ -90,8 +90,8 @@ function formatNationalNumber(state, format, {
|
|
|
90
90
|
formattedNationalNumber = state.nationalPrefix +
|
|
91
91
|
getSeparatorAfterNationalPrefix(format) +
|
|
92
92
|
formattedNationalNumber
|
|
93
|
-
} else if (state.
|
|
94
|
-
formattedNationalNumber = state.
|
|
93
|
+
} else if (state.prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix) {
|
|
94
|
+
formattedNationalNumber = state.prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix +
|
|
95
95
|
' ' +
|
|
96
96
|
formattedNationalNumber
|
|
97
97
|
}
|
|
@@ -154,7 +154,7 @@ export default class AsYouTypeFormatter {
|
|
|
154
154
|
// If so, we should use this instead of any other formatting template
|
|
155
155
|
// whose leadingDigitsPattern also matches the input."
|
|
156
156
|
//
|
|
157
|
-
if (canFormatCompleteNumber(state.nationalSignificantNumber, this.metadata)) {
|
|
157
|
+
if (canFormatCompleteNumber(state.nationalSignificantNumber, state.country, this.metadata)) {
|
|
158
158
|
for (const format of this.matchingFormats) {
|
|
159
159
|
const formattedCompleteNumber = formatCompleteNumber(
|
|
160
160
|
state,
|
|
@@ -534,7 +534,7 @@ export default class AsYouTypeFormatter {
|
|
|
534
534
|
nationalSignificantNumber,
|
|
535
535
|
international,
|
|
536
536
|
nationalPrefix,
|
|
537
|
-
|
|
537
|
+
prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix
|
|
538
538
|
}) {
|
|
539
539
|
let pattern = format.pattern()
|
|
540
540
|
|
|
@@ -654,9 +654,9 @@ export default class AsYouTypeFormatter {
|
|
|
654
654
|
// before the national (significant) number, optionally spacing
|
|
655
655
|
// the two with a whitespace.
|
|
656
656
|
if (!nationalPrefixIncludedInTemplate) {
|
|
657
|
-
if (
|
|
657
|
+
if (prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix) {
|
|
658
658
|
// Prepend the prefix to the template manually.
|
|
659
|
-
template = repeat(DIGIT_PLACEHOLDER,
|
|
659
|
+
template = repeat(DIGIT_PLACEHOLDER, prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix.length) +
|
|
660
660
|
' ' +
|
|
661
661
|
template
|
|
662
662
|
} else if (nationalPrefix) {
|
|
@@ -66,7 +66,7 @@ export default class AsYouTypeParser {
|
|
|
66
66
|
let justLeadingPlus
|
|
67
67
|
if (hasPlus) {
|
|
68
68
|
if (!state.digits) {
|
|
69
|
-
state.startInternationalNumber()
|
|
69
|
+
state.startInternationalNumber(undefined, undefined)
|
|
70
70
|
if (!digits) {
|
|
71
71
|
justLeadingPlus = true
|
|
72
72
|
}
|
|
@@ -143,6 +143,7 @@ export default class AsYouTypeParser {
|
|
|
143
143
|
extractCountryCallingCode(state) {
|
|
144
144
|
const { countryCallingCode, number } = extractCountryCallingCode(
|
|
145
145
|
'+' + state.getDigitsWithoutInternationalPrefix(),
|
|
146
|
+
state.country,
|
|
146
147
|
this.defaultCountry,
|
|
147
148
|
this.defaultCallingCode,
|
|
148
149
|
this.metadata.metadata
|
|
@@ -245,39 +246,55 @@ export default class AsYouTypeParser {
|
|
|
245
246
|
nationalDigits,
|
|
246
247
|
setState
|
|
247
248
|
) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
//
|
|
251
|
-
|
|
252
|
-
//
|
|
253
|
-
//
|
|
254
|
-
//
|
|
255
|
-
//
|
|
249
|
+
// Tells if the parsed national (significant) number is present as-is in the input string.
|
|
250
|
+
// For example, when inputting "0343515551212999" Argentinian mobile number,
|
|
251
|
+
// the parsed national (significant) number is "93435551212999".
|
|
252
|
+
// There, one can see how it stripped "0" national prefix and prepended a "9",
|
|
253
|
+
// because that's how it is instructed to do in Argentina's metadata.
|
|
254
|
+
// So in the described example, the parsed national (significant) number is not present
|
|
255
|
+
// as-is in the input string. Instead, it's "modified" in the input string.
|
|
256
|
+
// https://gitlab.com/catamphetamine/libphonenumber-js/-/blob/master/METADATA.md#national_prefix_for_parsing--national_prefix_transform_rule
|
|
257
|
+
let nationalSignificantNumberIsModified = false
|
|
258
|
+
|
|
259
|
+
// In some countries, a phone number could have a prefix that is not a "national prefix"
|
|
260
|
+
// but rather some other type of "utility" prefix.
|
|
261
|
+
// For example, when calling within Australia, one could prepend `1831` prefix to hide
|
|
262
|
+
// caller's phone number.
|
|
256
263
|
// https://gitlab.com/catamphetamine/libphonenumber-js/-/blob/master/METADATA.md#national_prefix_for_parsing--national_prefix_transform_rule
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
264
|
+
let prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix
|
|
265
|
+
|
|
266
|
+
// `nationalSignificantNumber` could be empty. In that case, `.lastIndexOf()` still works correctly.
|
|
267
|
+
const nationalSignificantNumberIndex = nationalDigits.lastIndexOf(nationalSignificantNumber)
|
|
268
|
+
|
|
269
|
+
// If the parsed national (significant) number is the last substring of the `nationalDigits`,
|
|
270
|
+
// then it means that it's present as-is in the input string.
|
|
271
|
+
// In any other case, the parsed national (significant) number is "modified" in the input string.
|
|
272
|
+
if (
|
|
273
|
+
nationalSignificantNumberIndex < 0 ||
|
|
274
|
+
nationalSignificantNumberIndex !== nationalDigits.length - nationalSignificantNumber.length
|
|
275
|
+
) {
|
|
276
|
+
nationalSignificantNumberIsModified = true
|
|
277
|
+
} else {
|
|
265
278
|
const prefixBeforeNationalNumber = nationalDigits.slice(0, nationalSignificantNumberIndex)
|
|
266
|
-
//
|
|
267
|
-
//
|
|
268
|
-
//
|
|
269
|
-
//
|
|
270
|
-
//
|
|
271
|
-
|
|
272
|
-
|
|
279
|
+
// When national (significant) number is equal to the `nationalDigits`,
|
|
280
|
+
// this `onExtractedNationalNumber()` function simply doesn't get called.
|
|
281
|
+
// This means that at this point, `prefixBeforeNationalNumber` is always non-empty.
|
|
282
|
+
// Still, added this `if` check just to prevent potential silly bugs.
|
|
283
|
+
// The `!prefixBeforeNationalNumber` case is not really testable
|
|
284
|
+
// so this line is exluded from the code coverage.
|
|
285
|
+
/* istanbul ignore if */
|
|
286
|
+
if (prefixBeforeNationalNumber) {
|
|
287
|
+
if (prefixBeforeNationalNumber !== nationalPrefix) {
|
|
288
|
+
prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix = prefixBeforeNationalNumber
|
|
289
|
+
}
|
|
273
290
|
}
|
|
274
291
|
}
|
|
275
292
|
setState({
|
|
276
293
|
nationalPrefix,
|
|
277
294
|
carrierCode,
|
|
278
295
|
nationalSignificantNumber,
|
|
279
|
-
|
|
280
|
-
|
|
296
|
+
nationalSignificantNumberIsModified,
|
|
297
|
+
prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix
|
|
281
298
|
})
|
|
282
299
|
// `onExtractedNationalNumber()` is only called when
|
|
283
300
|
// the national (significant) number actually did change.
|
|
@@ -396,10 +413,10 @@ export default class AsYouTypeParser {
|
|
|
396
413
|
fixMissingPlus(state) {
|
|
397
414
|
if (!state.international) {
|
|
398
415
|
const {
|
|
399
|
-
countryCallingCode: newCallingCode
|
|
400
|
-
number
|
|
416
|
+
countryCallingCode: newCallingCode
|
|
401
417
|
} = extractCountryCallingCodeFromInternationalNumberWithoutPlusSign(
|
|
402
418
|
state.digits,
|
|
419
|
+
state.country,
|
|
403
420
|
this.defaultCountry,
|
|
404
421
|
this.defaultCallingCode,
|
|
405
422
|
this.metadata.metadata
|
package/source/AsYouTypeState.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
// This "state" object simply holds the state of the "AsYouType" parser:
|
|
2
2
|
//
|
|
3
|
-
// * `country?: string`
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// * `
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// * `
|
|
12
|
-
// * `
|
|
13
|
-
// * `
|
|
14
|
-
//
|
|
15
|
-
// `
|
|
16
|
-
//
|
|
17
|
-
//
|
|
3
|
+
// * `country?: string` — The exact country of the phone number, if it could be determined.
|
|
4
|
+
// When inputting a phone number in "international" format, it will derive the `country` from "country calling code" and the phone number digits.
|
|
5
|
+
// When inputting a phone number in "national" format, it will derive the `country` from `defaultCountry` that was specified when creating the `AsYouType` formatter.
|
|
6
|
+
// Sidenote: If `USE_NON_GEOGRAPHIC_COUNTRY_CODE` flag was `true`, then for "non-geographic phone numbers" `state.country` would've been "001".
|
|
7
|
+
// * `callingCode?: string` — "Country calling code" that has been extracted from the input phone number.
|
|
8
|
+
// When inputting a phone number in "international" format, it will extract the "country calling code" from the digits that follow the "+" character.
|
|
9
|
+
// When inputting a phone number in "national" format, `callingCode` will be `undefined`.
|
|
10
|
+
// Sidenote: `state.callingCode` is therefore independent from `state.country` and there could be situations when `state.country` is defined by `state.callingCode` is not — that would be when inputting a phone number not in "international" format.
|
|
11
|
+
// * `digits: string` — Phone number digits that have been input so far, including the "+" character, if present. In case of inputting non-arabic digits, those will be converted to arabic ones.
|
|
12
|
+
// * `international: boolean` — Whether the phone number is being input in "international" format, i.e. with a "+" character.
|
|
13
|
+
// * `missingPlus: boolean` — Whether it's a phone number in "international" format that is missing the leading "+" character for some reason — apparently, Google thinks that it's a common mistake when inputting a phone number.
|
|
14
|
+
// * `IDDPrefix?: string` — An "IDD prefix", when the phone number is being input in an "out-of-country dialing" format. https://wikitravel.org/en/International_dialling_prefix
|
|
15
|
+
// * `carrierCode?: string` — A "carrier code", if the phone number contains it. Normally, those can only be present in Colombia or Brazil, and only when calling from mobile phones to fixed-line numbers.
|
|
16
|
+
// * `nationalPrefix?: string` — "National prefix", if present in the phone number input.
|
|
17
|
+
// * `nationalSignificantNumber?: string` — National (significant) number digits that have been input so far.
|
|
18
|
+
// * `nationalSignificantNumberIsModified: boolean` — Tells if the parsed national (significant) number is present as-is in the input string. For example, when inputting "0343515551212999" Argentinian mobile number, the parsed national (significant) number is "93435551212999". There, one can see how it stripped "0" national prefix and prepended a "9", because that's how it is instructed to do in Argentina's metadata. So in the described example, the parsed national (significant) number is not present as-is in the input string. Instead, it's "modified" in the input string. https://gitlab.com/caamphetamine/libphonenumber-js/-/blob/master/METADATA.md#national_prefix_for_parsing--national_prefix_transform_rule
|
|
19
|
+
// * `prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix?: string` — In some countries, a phone number could have a prefix that is not a "national prefix" but rather some other type of "utility" prefix.
|
|
20
|
+
// For example, when calling within Australia, one could prepend `1831` prefix to hide caller's phone number.
|
|
21
|
+
// https://gitlab.com/catamphetamine/libphonenumber-js/-/blob/master/METADATA.md#national_prefix_for_parsing--national_prefix_transform_rule
|
|
18
22
|
//
|
|
19
23
|
export default class AsYouTypeState {
|
|
20
24
|
constructor({ onCountryChange, onCallingCodeChange }) {
|
|
@@ -34,10 +38,10 @@ export default class AsYouTypeState {
|
|
|
34
38
|
|
|
35
39
|
resetNationalSignificantNumber() {
|
|
36
40
|
this.nationalSignificantNumber = this.getNationalDigits()
|
|
37
|
-
this.
|
|
41
|
+
this.nationalSignificantNumberIsModified = false
|
|
38
42
|
this.nationalPrefix = undefined
|
|
39
43
|
this.carrierCode = undefined
|
|
40
|
-
this.
|
|
44
|
+
this.prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix = undefined
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
update(properties) {
|
package/source/PhoneNumber.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import Metadata, { validateMetadata } from './metadata.js'
|
|
2
2
|
import isPossibleNumber from './isPossible.js'
|
|
3
3
|
import isValidNumber from './isValid.js'
|
|
4
|
-
// import checkNumberLength from './helpers/checkNumberLength.js'
|
|
5
4
|
import getNumberType from './helpers/getNumberType.js'
|
|
6
5
|
import getPossibleCountriesForNumber from './helpers/getPossibleCountriesForNumber.js'
|
|
7
6
|
import extractCountryCallingCode from './helpers/extractCountryCallingCode.js'
|
|
@@ -38,7 +37,7 @@ export default class PhoneNumber {
|
|
|
38
37
|
if (!E164_NUMBER_REGEXP.test(e164Number)) {
|
|
39
38
|
throw new Error('Invalid `number` argument passed: must consist of a "+" followed by digits')
|
|
40
39
|
}
|
|
41
|
-
const { countryCallingCode, number } = extractCountryCallingCode(e164Number, undefined, undefined, metadata)
|
|
40
|
+
const { countryCallingCode, number } = extractCountryCallingCode(e164Number, undefined, undefined, undefined, metadata)
|
|
42
41
|
nationalNumber = number
|
|
43
42
|
countryOrCountryCallingCode = countryCallingCode
|
|
44
43
|
if (!nationalNumber) {
|
|
@@ -170,7 +170,6 @@ function isNationalPrefixPresentIfRequired(phoneNumber, { defaultCountry, metada
|
|
|
170
170
|
|
|
171
171
|
const phoneNumberRegion = phoneNumber.country || getCountryByCallingCode(phoneNumber.countryCallingCode, {
|
|
172
172
|
nationalNumber: phoneNumber.nationalNumber,
|
|
173
|
-
defaultCountry,
|
|
174
173
|
metadata
|
|
175
174
|
})
|
|
176
175
|
|
package/source/format.js
CHANGED
|
@@ -43,7 +43,7 @@ export default function formatNumber(input, format, options, metadata) {
|
|
|
43
43
|
if (!metadata.hasCountry(input.country)) {
|
|
44
44
|
throw new Error(`Unknown country: ${input.country}`)
|
|
45
45
|
}
|
|
46
|
-
metadata.
|
|
46
|
+
metadata.selectNumberingPlan(input.country)
|
|
47
47
|
}
|
|
48
48
|
else if (input.countryCallingCode) {
|
|
49
49
|
metadata.selectNumberingPlan(input.countryCallingCode)
|
|
@@ -128,7 +128,7 @@ function formatNationalNumber(number, carrierCode, formatAs, metadata, options)
|
|
|
128
128
|
)
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
export function chooseFormatForNumber(availableFormats,
|
|
131
|
+
export function chooseFormatForNumber(availableFormats, nationalNumber) {
|
|
132
132
|
for (const format of availableFormats) {
|
|
133
133
|
// Validate leading digits.
|
|
134
134
|
// The test case for "else path" could be found by searching for
|
|
@@ -137,12 +137,12 @@ export function chooseFormatForNumber(availableFormats, nationalNnumber) {
|
|
|
137
137
|
// The last leading_digits_pattern is used here, as it is the most detailed
|
|
138
138
|
const lastLeadingDigitsPattern = format.leadingDigitsPatterns()[format.leadingDigitsPatterns().length - 1]
|
|
139
139
|
// If leading digits don't match then move on to the next phone number format
|
|
140
|
-
if (
|
|
140
|
+
if (nationalNumber.search(lastLeadingDigitsPattern) !== 0) {
|
|
141
141
|
continue
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
// Check that the national number matches the phone number format regular expression
|
|
145
|
-
if (matchesEntirely(
|
|
145
|
+
if (matchesEntirely(nationalNumber, format.pattern())) {
|
|
146
146
|
return format
|
|
147
147
|
}
|
|
148
148
|
}
|
|
@@ -67,10 +67,10 @@ export default function(number, from_country, with_formatting, metadata) {
|
|
|
67
67
|
// dialled in national format.
|
|
68
68
|
|
|
69
69
|
// Select country for `checkNumberLength()`.
|
|
70
|
-
metadata.
|
|
70
|
+
metadata.selectNumberingPlan(country)
|
|
71
71
|
|
|
72
72
|
if (can_be_internationally_dialled(number) &&
|
|
73
|
-
checkNumberLength(number.phone, metadata) !== 'TOO_SHORT') {
|
|
73
|
+
checkNumberLength(number.phone, country, metadata) !== 'TOO_SHORT') {
|
|
74
74
|
formatted_number = format(number, 'INTERNATIONAL', metadata.metadata)
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
@@ -1,12 +1,45 @@
|
|
|
1
|
+
import Metadata from '../metadata.js'
|
|
1
2
|
import mergeArrays from './mergeArrays.js'
|
|
2
3
|
|
|
3
|
-
export default function checkNumberLength(nationalNumber, metadata) {
|
|
4
|
-
return checkNumberLengthForType(nationalNumber, undefined, metadata)
|
|
4
|
+
export default function checkNumberLength(nationalNumber, country, metadata) {
|
|
5
|
+
return checkNumberLengthForType(nationalNumber, country, undefined, metadata)
|
|
5
6
|
}
|
|
6
7
|
|
|
7
|
-
// Checks whether a number is possible for
|
|
8
|
-
//
|
|
9
|
-
|
|
8
|
+
// Checks whether a number is possible for a certain `country` based on the number length.
|
|
9
|
+
//
|
|
10
|
+
// This function is not supported by metadata generated with ancient versions of
|
|
11
|
+
// `libphonenumber-js` (before version `1.0.18`) which didn't include "possible lengths".
|
|
12
|
+
//
|
|
13
|
+
// There was also a known issue with `checkNumberLength()` function:
|
|
14
|
+
// if a number is possible only in a certain `country` among several `countries`
|
|
15
|
+
// that share the same "country calling code", that function would check
|
|
16
|
+
// the possibility of the phone number only in the "main" `country` for the "country calling code"
|
|
17
|
+
// and would not check if it's actually be possible in the speciifc `country`.
|
|
18
|
+
//
|
|
19
|
+
// For example, "+1310xxxx" numbers are valid in Canada.
|
|
20
|
+
// However, they are not possible in the US due to being too short.
|
|
21
|
+
// Since Canada and the US share the same country calling code — "+1" —
|
|
22
|
+
// `checkNumberLength()` function used to return not "IS_POSSIBLE" for "+1310xxxx" numbers.
|
|
23
|
+
//
|
|
24
|
+
// In such cases, when using "/max" metadata, `isValid()` could output `true`
|
|
25
|
+
// but at the same time `isPossible()` could output `false`, which was contradictory.
|
|
26
|
+
//
|
|
27
|
+
// See https://issuetracker.google.com/issues/335892662 for the discusson in Google's issues.
|
|
28
|
+
//
|
|
29
|
+
// The solution suggested by Google was implemented: an optional `country` argument
|
|
30
|
+
// was added to `checkNumberLength()` function. If present, that `country` will be used
|
|
31
|
+
// to check phone number length for that specific `country` rather than the "main" country
|
|
32
|
+
// for the shared "country calling code".
|
|
33
|
+
//
|
|
34
|
+
export function checkNumberLengthForType(nationalNumber, country, type, metadata) {
|
|
35
|
+
// If the exact `country` is specified, it's no necessarily already selected in `metadata`.
|
|
36
|
+
// Most likely, in cases when there're multiple countries corresponding to the same
|
|
37
|
+
// "country calling code", the "main" country for that "country calling code" will be selected.
|
|
38
|
+
if (country) {
|
|
39
|
+
metadata = new Metadata(metadata.metadata)
|
|
40
|
+
metadata.selectNumberingPlan(country)
|
|
41
|
+
}
|
|
42
|
+
|
|
10
43
|
const type_info = metadata.type(type)
|
|
11
44
|
|
|
12
45
|
// There should always be "<possiblePengths/>" set for every type element.
|
|
@@ -17,7 +50,7 @@ export function checkNumberLengthForType(nationalNumber, type, metadata) {
|
|
|
17
50
|
// exist at all, there is one possible length (-1) which is guaranteed
|
|
18
51
|
// not to match the length of any real phone number.
|
|
19
52
|
let possible_lengths = type_info && type_info.possibleLengths() || metadata.possibleLengths()
|
|
20
|
-
// let local_lengths
|
|
53
|
+
// let local_lengths = type_info && type.possibleLengthsLocal() || metadata.possibleLengthsLocal()
|
|
21
54
|
|
|
22
55
|
// Metadata before version `1.0.18` didn't contain `possible_lengths`.
|
|
23
56
|
if (!possible_lengths) {
|
|
@@ -30,7 +63,7 @@ export function checkNumberLengthForType(nationalNumber, type, metadata) {
|
|
|
30
63
|
if (!metadata.type('FIXED_LINE')) {
|
|
31
64
|
// The rare case has been encountered where no fixedLine data is available
|
|
32
65
|
// (true for some non-geographic entities), so we just check mobile.
|
|
33
|
-
return checkNumberLengthForType(nationalNumber, 'MOBILE', metadata)
|
|
66
|
+
return checkNumberLengthForType(nationalNumber, country, 'MOBILE', metadata)
|
|
34
67
|
}
|
|
35
68
|
|
|
36
69
|
const mobile_type = metadata.type('MOBILE')
|