libphonenumber-js 1.12.40 → 1.12.41
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 +12 -0
- 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/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/.babelrc +0 -21
- package/.nycrc +0 -27
- package/METADATA.md +0 -155
- package/autoupdate.cmd +0 -6
- package/autoupdate.sh +0 -16
- package/build/AsYouType.test.js +0 -1339
- package/build/AsYouTypeFormatter.PatternMatcher.test.js +0 -502
- package/build/AsYouTypeFormatter.PatternParser.test.js +0 -49
- package/build/AsYouTypeFormatter.util.test.js +0 -24
- package/build/PhoneNumber.test.js +0 -141
- package/build/PhoneNumberMatcher.test.js +0 -122
- package/build/findNumbers/util.test.js +0 -34
- package/build/findPhoneNumbersInText.test.js +0 -300
- package/build/format.test.js +0 -339
- package/build/formatIncompletePhoneNumber.test.js +0 -33
- package/build/getCountries.test.js +0 -13
- package/build/getCountryCallingCode.test.js +0 -18
- package/build/getExampleNumber.test.js +0 -21
- package/build/helpers/RFC3966.test.js +0 -47
- package/build/helpers/applyInternationalSeparatorStyle.test.js +0 -13
- package/build/helpers/checkNumberLength.test.js +0 -81
- package/build/helpers/extractCountryCallingCode.test.js +0 -23
- package/build/helpers/extractNationalNumber.test.js +0 -27
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -20
- package/build/helpers/extractPhoneContext.test.js +0 -71
- package/build/helpers/getNumberType.test.js +0 -23
- package/build/helpers/matchesEntirely.test.js +0 -16
- package/build/helpers/mergeArrays.test.js +0 -12
- package/build/helpers/parseDigits.test.js +0 -12
- package/build/helpers/stripIddPrefix.test.js +0 -22
- package/build/isPossible.test.js +0 -121
- package/build/isPossiblePhoneNumber.test.js +0 -42
- package/build/isValid.test.js +0 -144
- package/build/isValidPhoneNumber.test.js +0 -29
- package/build/legacy/findNumbers.test.js +0 -210
- package/build/legacy/findPhoneNumbers.test.js +0 -245
- package/build/legacy/format.test.js +0 -299
- package/build/legacy/getNumberType.test.js +0 -80
- package/build/legacy/isPossibleNumber.test.js +0 -82
- package/build/legacy/isValidNumber.test.js +0 -102
- package/build/legacy/isValidNumberForRegion.test.js +0 -40
- package/build/legacy/parse.test.js +0 -617
- package/build/legacy/searchNumbers.test.js +0 -33
- package/build/metadata.test.js +0 -170
- package/build/parse.test.js +0 -653
- package/build/parseIncompletePhoneNumber.test.js +0 -109
- package/build/parsePhoneNumber.test.js +0 -98
- package/build/parsePhoneNumberWithError.test.js +0 -140
- package/build/searchPhoneNumbersInText.test.js +0 -51
- package/build/tools/semver-compare.test.js +0 -13
- package/build/validatePhoneNumberLength.test.js +0 -37
- package/build-scripts/check-for-metadata-changes-and-create-pull-request.js +0 -88
- package/build-scripts/check-for-metadata-changes-and-release.js +0 -67
- package/build-scripts/check-for-uncommitted-files.js +0 -13
- package/build-scripts/create-commonjs-package-json-file.js +0 -11
- package/build-scripts/create-js-file-for-json-file.js +0 -14
- package/build-scripts/create-metadata-update-branch.js +0 -31
- package/build-scripts/generate-country-codes-list-in-typescript.js +0 -14
- package/build-scripts/generate-metadata-from-google-metadata.js +0 -75
- package/build-scripts/helpers/commit.js +0 -14
- package/build-scripts/helpers/exec.js +0 -6
- package/build-scripts/helpers/getUncommittedChanges.js +0 -33
- package/build-scripts/helpers/sendEmail.js +0 -62
- package/build-scripts/helpers/updateMetadataFromGoogleMetadata.js +0 -130
- package/build-scripts/pull-google-metadata.js +0 -29
- package/es6/AsYouType.test.js +0 -1336
- package/es6/AsYouTypeFormatter.PatternMatcher.test.js +0 -499
- package/es6/AsYouTypeFormatter.PatternParser.test.js +0 -46
- package/es6/AsYouTypeFormatter.util.test.js +0 -22
- package/es6/PhoneNumber.test.js +0 -138
- package/es6/PhoneNumberMatcher.test.js +0 -119
- package/es6/findNumbers/util.test.js +0 -32
- package/es6/findPhoneNumbersInText.test.js +0 -297
- package/es6/format.test.js +0 -336
- package/es6/formatIncompletePhoneNumber.test.js +0 -30
- package/es6/getCountries.test.js +0 -10
- package/es6/getCountryCallingCode.test.js +0 -15
- package/es6/getExampleNumber.test.js +0 -18
- package/es6/helpers/RFC3966.test.js +0 -45
- package/es6/helpers/applyInternationalSeparatorStyle.test.js +0 -10
- package/es6/helpers/checkNumberLength.test.js +0 -76
- package/es6/helpers/extractCountryCallingCode.test.js +0 -20
- package/es6/helpers/extractNationalNumber.test.js +0 -24
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -17
- package/es6/helpers/extractPhoneContext.test.js +0 -68
- package/es6/helpers/getNumberType.test.js +0 -20
- package/es6/helpers/matchesEntirely.test.js +0 -13
- package/es6/helpers/mergeArrays.test.js +0 -9
- package/es6/helpers/parseDigits.test.js +0 -9
- package/es6/helpers/stripIddPrefix.test.js +0 -19
- package/es6/isPossible.test.js +0 -118
- package/es6/isPossiblePhoneNumber.test.js +0 -39
- package/es6/isValid.test.js +0 -141
- package/es6/isValidPhoneNumber.test.js +0 -26
- package/es6/legacy/findNumbers.test.js +0 -207
- package/es6/legacy/findPhoneNumbers.test.js +0 -243
- package/es6/legacy/format.test.js +0 -296
- package/es6/legacy/getNumberType.test.js +0 -77
- package/es6/legacy/isPossibleNumber.test.js +0 -79
- package/es6/legacy/isValidNumber.test.js +0 -99
- package/es6/legacy/isValidNumberForRegion.test.js +0 -37
- package/es6/legacy/parse.test.js +0 -614
- package/es6/legacy/searchNumbers.test.js +0 -30
- package/es6/metadata.test.js +0 -166
- package/es6/parse.test.js +0 -650
- package/es6/parseIncompletePhoneNumber.test.js +0 -105
- package/es6/parsePhoneNumber.test.js +0 -95
- package/es6/parsePhoneNumberWithError.test.js +0 -137
- package/es6/searchPhoneNumbersInText.test.js +0 -48
- package/es6/tools/semver-compare.test.js +0 -10
- package/es6/validatePhoneNumberLength.test.js +0 -34
- package/jest.config.json +0 -26
- package/rollup.config.mjs +0 -57
- package/source/AsYouType.test.js +0 -1409
- package/source/AsYouTypeFormatter.PatternMatcher.test.js +0 -644
- package/source/AsYouTypeFormatter.PatternParser.test.js +0 -70
- package/source/AsYouTypeFormatter.util.test.js +0 -25
- package/source/PhoneNumber.test.js +0 -138
- package/source/PhoneNumberMatcher.test.js +0 -112
- package/source/findNumbers/util.test.js +0 -37
- package/source/findPhoneNumbersInText.test.js +0 -316
- package/source/format.test.js +0 -273
- package/source/formatIncompletePhoneNumber.test.js +0 -33
- package/source/getCountries.test.js +0 -12
- package/source/getCountryCallingCode.test.js +0 -16
- package/source/getExampleNumber.test.js +0 -20
- package/source/helpers/RFC3966.test.js +0 -39
- package/source/helpers/applyInternationalSeparatorStyle.test.js +0 -11
- package/source/helpers/checkNumberLength.test.js +0 -85
- package/source/helpers/extractCountryCallingCode.test.js +0 -23
- package/source/helpers/extractNationalNumber.test.js +0 -27
- package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -18
- package/source/helpers/extractPhoneContext.test.js +0 -107
- package/source/helpers/getNumberType.test.js +0 -27
- package/source/helpers/matchesEntirely.test.js +0 -14
- package/source/helpers/mergeArrays.test.js +0 -10
- package/source/helpers/parseDigits.test.js +0 -10
- package/source/helpers/stripIddPrefix.test.js +0 -24
- package/source/isPossible.test.js +0 -86
- package/source/isPossiblePhoneNumber.test.js +0 -36
- package/source/isValid.test.js +0 -123
- package/source/isValidPhoneNumber.test.js +0 -23
- package/source/legacy/findNumbers.test.js +0 -220
- package/source/legacy/findPhoneNumbers.test.js +0 -252
- package/source/legacy/format.test.js +0 -246
- package/source/legacy/getNumberType.test.js +0 -70
- package/source/legacy/isPossibleNumber.test.js +0 -49
- package/source/legacy/isValidNumber.test.js +0 -95
- package/source/legacy/isValidNumberForRegion.test.js +0 -31
- package/source/legacy/parse.test.js +0 -533
- package/source/legacy/searchNumbers.test.js +0 -29
- package/source/metadata.test.js +0 -178
- package/source/parse.test.js +0 -561
- package/source/parseIncompletePhoneNumber.test.js +0 -118
- package/source/parsePhoneNumber.test.js +0 -99
- package/source/parsePhoneNumberWithError.test.js +0 -115
- package/source/searchPhoneNumbersInText.test.js +0 -47
- package/source/tools/semver-compare.test.js +0 -43
- package/source/validatePhoneNumberLength.test.js +0 -33
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import metadata from '../../metadata.min.json' with { type: 'json' };
|
|
4
|
-
import _formatNumber from './format.js';
|
|
5
|
-
function formatNumber() {
|
|
6
|
-
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
7
|
-
parameters[_key] = arguments[_key];
|
|
8
|
-
}
|
|
9
|
-
parameters.push(metadata);
|
|
10
|
-
return _formatNumber.apply(this, parameters);
|
|
11
|
-
}
|
|
12
|
-
describe('format', function () {
|
|
13
|
-
it('should work with the first argument being a E.164 number', function () {
|
|
14
|
-
expect(formatNumber('+12133734253', 'NATIONAL')).to.equal('(213) 373-4253');
|
|
15
|
-
expect(formatNumber('+12133734253', 'INTERNATIONAL')).to.equal('+1 213 373 4253');
|
|
16
|
-
|
|
17
|
-
// Invalid number.
|
|
18
|
-
expect(formatNumber('+12111111111', 'NATIONAL')).to.equal('(211) 111-1111');
|
|
19
|
-
|
|
20
|
-
// Formatting invalid E.164 numbers.
|
|
21
|
-
expect(formatNumber('+11111', 'INTERNATIONAL')).to.equal('+1 1111');
|
|
22
|
-
expect(formatNumber('+11111', 'NATIONAL')).to.equal('1111');
|
|
23
|
-
});
|
|
24
|
-
it('should work with the first object argument expanded', function () {
|
|
25
|
-
expect(formatNumber('2133734253', 'US', 'NATIONAL')).to.equal('(213) 373-4253');
|
|
26
|
-
expect(formatNumber('2133734253', 'US', 'INTERNATIONAL')).to.equal('+1 213 373 4253');
|
|
27
|
-
});
|
|
28
|
-
it('should support legacy "National" / "International" formats', function () {
|
|
29
|
-
expect(formatNumber('2133734253', 'US', 'National')).to.equal('(213) 373-4253');
|
|
30
|
-
expect(formatNumber('2133734253', 'US', 'International')).to.equal('+1 213 373 4253');
|
|
31
|
-
});
|
|
32
|
-
it('should format using formats with no leading digits (`format.leadingDigitsPatterns().length === 0`)', function () {
|
|
33
|
-
expect(formatNumber({
|
|
34
|
-
phone: '12345678901',
|
|
35
|
-
countryCallingCode: 888
|
|
36
|
-
}, 'INTERNATIONAL')).to.equal('+888 123 456 78901');
|
|
37
|
-
});
|
|
38
|
-
it('should sort out the arguments', function () {
|
|
39
|
-
var options = {
|
|
40
|
-
formatExtension: function formatExtension(number, extension) {
|
|
41
|
-
return "".concat(number, " \u0434\u043E\u0431. ").concat(extension);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
expect(formatNumber({
|
|
45
|
-
phone: '8005553535',
|
|
46
|
-
country: 'RU',
|
|
47
|
-
ext: '123'
|
|
48
|
-
}, 'NATIONAL', options)).to.equal('8 (800) 555-35-35 доб. 123');
|
|
49
|
-
|
|
50
|
-
// Parse number from string.
|
|
51
|
-
expect(formatNumber('+78005553535', 'NATIONAL', options)).to.equal('8 (800) 555-35-35');
|
|
52
|
-
expect(formatNumber('8005553535', 'RU', 'NATIONAL', options)).to.equal('8 (800) 555-35-35');
|
|
53
|
-
});
|
|
54
|
-
it('should format with national prefix when specifically instructed', function () {
|
|
55
|
-
// With national prefix.
|
|
56
|
-
expect(formatNumber('88005553535', 'RU', 'NATIONAL')).to.equal('8 (800) 555-35-35');
|
|
57
|
-
// Without national prefix via an explicitly set option.
|
|
58
|
-
expect(formatNumber('88005553535', 'RU', 'NATIONAL', {
|
|
59
|
-
nationalPrefix: false
|
|
60
|
-
})).to.equal('800 555-35-35');
|
|
61
|
-
});
|
|
62
|
-
it('should format valid phone numbers', function () {
|
|
63
|
-
// Switzerland
|
|
64
|
-
expect(formatNumber({
|
|
65
|
-
country: 'CH',
|
|
66
|
-
phone: '446681800'
|
|
67
|
-
}, 'INTERNATIONAL')).to.equal('+41 44 668 18 00');
|
|
68
|
-
expect(formatNumber({
|
|
69
|
-
country: 'CH',
|
|
70
|
-
phone: '446681800'
|
|
71
|
-
}, 'E.164')).to.equal('+41446681800');
|
|
72
|
-
expect(formatNumber({
|
|
73
|
-
country: 'CH',
|
|
74
|
-
phone: '446681800'
|
|
75
|
-
}, 'RFC3966')).to.equal('tel:+41446681800');
|
|
76
|
-
expect(formatNumber({
|
|
77
|
-
country: 'CH',
|
|
78
|
-
phone: '446681800'
|
|
79
|
-
}, 'NATIONAL')).to.equal('044 668 18 00');
|
|
80
|
-
|
|
81
|
-
// France
|
|
82
|
-
expect(formatNumber({
|
|
83
|
-
country: 'FR',
|
|
84
|
-
phone: '169454850'
|
|
85
|
-
}, 'NATIONAL')).to.equal('01 69 45 48 50');
|
|
86
|
-
|
|
87
|
-
// Kazakhstan
|
|
88
|
-
expect(formatNumber('+7 702 211 1111', 'NATIONAL')).to.equal('8 (702) 211 1111');
|
|
89
|
-
});
|
|
90
|
-
it('should format national numbers with national prefix even if it\'s optional', function () {
|
|
91
|
-
// Russia
|
|
92
|
-
expect(formatNumber({
|
|
93
|
-
country: 'RU',
|
|
94
|
-
phone: '9991234567'
|
|
95
|
-
}, 'NATIONAL')).to.equal('8 (999) 123-45-67');
|
|
96
|
-
});
|
|
97
|
-
it('should work in edge cases', function () {
|
|
98
|
-
var thrower;
|
|
99
|
-
|
|
100
|
-
// No phone number
|
|
101
|
-
expect(formatNumber('', 'RU', 'INTERNATIONAL')).to.equal('');
|
|
102
|
-
expect(formatNumber('', 'RU', 'NATIONAL')).to.equal('');
|
|
103
|
-
expect(formatNumber({
|
|
104
|
-
country: 'RU',
|
|
105
|
-
phone: ''
|
|
106
|
-
}, 'INTERNATIONAL')).to.equal('+7');
|
|
107
|
-
expect(formatNumber({
|
|
108
|
-
country: 'RU',
|
|
109
|
-
phone: ''
|
|
110
|
-
}, 'NATIONAL')).to.equal('');
|
|
111
|
-
|
|
112
|
-
// No suitable format
|
|
113
|
-
expect(formatNumber('+121337342530', 'US', 'NATIONAL')).to.equal('21337342530');
|
|
114
|
-
// No suitable format (leading digits mismatch)
|
|
115
|
-
expect(formatNumber('28199999', 'AD', 'NATIONAL')).to.equal('28199999');
|
|
116
|
-
|
|
117
|
-
// Numerical `value`
|
|
118
|
-
thrower = function thrower() {
|
|
119
|
-
return formatNumber(89150000000, 'RU', 'NATIONAL');
|
|
120
|
-
};
|
|
121
|
-
expect(thrower).to["throw"]('A phone number must either be a string or an object of shape { phone, [country] }.');
|
|
122
|
-
|
|
123
|
-
// No metadata for country
|
|
124
|
-
expect(function () {
|
|
125
|
-
return formatNumber('+121337342530', 'USA', 'NATIONAL');
|
|
126
|
-
}).to["throw"]('Unknown country');
|
|
127
|
-
expect(function () {
|
|
128
|
-
return formatNumber('21337342530', 'USA', 'NATIONAL');
|
|
129
|
-
}).to["throw"]('Unknown country');
|
|
130
|
-
|
|
131
|
-
// No format type
|
|
132
|
-
thrower = function thrower() {
|
|
133
|
-
return formatNumber('+123');
|
|
134
|
-
};
|
|
135
|
-
expect(thrower).to["throw"]('`format` argument not passed');
|
|
136
|
-
|
|
137
|
-
// Unknown format type
|
|
138
|
-
thrower = function thrower() {
|
|
139
|
-
return formatNumber('123', 'US', 'Gay');
|
|
140
|
-
};
|
|
141
|
-
expect(thrower).to["throw"]('Unknown "format" argument');
|
|
142
|
-
|
|
143
|
-
// No metadata
|
|
144
|
-
thrower = function thrower() {
|
|
145
|
-
return _formatNumber('123', 'US', 'E.164');
|
|
146
|
-
};
|
|
147
|
-
expect(thrower).to["throw"]('`metadata`');
|
|
148
|
-
|
|
149
|
-
// No formats
|
|
150
|
-
expect(formatNumber('012345', 'AC', 'NATIONAL')).to.equal('012345');
|
|
151
|
-
|
|
152
|
-
// No `fromCountry` for `IDD` format.
|
|
153
|
-
expect(formatNumber('+78005553535', 'IDD')).to.be.undefined;
|
|
154
|
-
|
|
155
|
-
// `fromCountry` has no default IDD prefix.
|
|
156
|
-
expect(formatNumber('+78005553535', 'IDD', {
|
|
157
|
-
fromCountry: 'BO'
|
|
158
|
-
})).to.be.undefined;
|
|
159
|
-
|
|
160
|
-
// No such country.
|
|
161
|
-
expect(function () {
|
|
162
|
-
return formatNumber({
|
|
163
|
-
phone: '123',
|
|
164
|
-
country: 'USA'
|
|
165
|
-
}, 'NATIONAL');
|
|
166
|
-
}).to["throw"]('Unknown country');
|
|
167
|
-
});
|
|
168
|
-
it('should format phone number extensions', function () {
|
|
169
|
-
// National
|
|
170
|
-
expect(formatNumber({
|
|
171
|
-
country: 'US',
|
|
172
|
-
phone: '2133734253',
|
|
173
|
-
ext: '123'
|
|
174
|
-
}, 'NATIONAL')).to.equal('(213) 373-4253 ext. 123');
|
|
175
|
-
|
|
176
|
-
// International
|
|
177
|
-
expect(formatNumber({
|
|
178
|
-
country: 'US',
|
|
179
|
-
phone: '2133734253',
|
|
180
|
-
ext: '123'
|
|
181
|
-
}, 'INTERNATIONAL')).to.equal('+1 213 373 4253 ext. 123');
|
|
182
|
-
|
|
183
|
-
// International
|
|
184
|
-
expect(formatNumber({
|
|
185
|
-
country: 'US',
|
|
186
|
-
phone: '2133734253',
|
|
187
|
-
ext: '123'
|
|
188
|
-
}, 'INTERNATIONAL')).to.equal('+1 213 373 4253 ext. 123');
|
|
189
|
-
|
|
190
|
-
// E.164
|
|
191
|
-
expect(formatNumber({
|
|
192
|
-
country: 'US',
|
|
193
|
-
phone: '2133734253',
|
|
194
|
-
ext: '123'
|
|
195
|
-
}, 'E.164')).to.equal('+12133734253');
|
|
196
|
-
|
|
197
|
-
// RFC3966
|
|
198
|
-
expect(formatNumber({
|
|
199
|
-
country: 'US',
|
|
200
|
-
phone: '2133734253',
|
|
201
|
-
ext: '123'
|
|
202
|
-
}, 'RFC3966')).to.equal('tel:+12133734253;ext=123');
|
|
203
|
-
|
|
204
|
-
// Custom ext prefix.
|
|
205
|
-
expect(formatNumber({
|
|
206
|
-
country: 'GB',
|
|
207
|
-
phone: '7912345678',
|
|
208
|
-
ext: '123'
|
|
209
|
-
}, 'INTERNATIONAL')).to.equal('+44 7912 345678 x123');
|
|
210
|
-
});
|
|
211
|
-
it('should work with Argentina numbers', function () {
|
|
212
|
-
// The same mobile number is written differently
|
|
213
|
-
// in different formats in Argentina:
|
|
214
|
-
// `9` gets prepended in international format.
|
|
215
|
-
expect(formatNumber({
|
|
216
|
-
country: 'AR',
|
|
217
|
-
phone: '3435551212'
|
|
218
|
-
}, 'INTERNATIONAL')).to.equal('+54 3435 55 1212');
|
|
219
|
-
expect(formatNumber({
|
|
220
|
-
country: 'AR',
|
|
221
|
-
phone: '3435551212'
|
|
222
|
-
}, 'NATIONAL')).to.equal('03435 55-1212');
|
|
223
|
-
});
|
|
224
|
-
it('should work with Mexico numbers', function () {
|
|
225
|
-
// Fixed line.
|
|
226
|
-
expect(formatNumber({
|
|
227
|
-
country: 'MX',
|
|
228
|
-
phone: '4499780001'
|
|
229
|
-
}, 'INTERNATIONAL')).to.equal('+52 449 978 0001');
|
|
230
|
-
expect(formatNumber({
|
|
231
|
-
country: 'MX',
|
|
232
|
-
phone: '4499780001'
|
|
233
|
-
}, 'NATIONAL')).to.equal('449 978 0001');
|
|
234
|
-
// or '(449)978-0001'.
|
|
235
|
-
// Mobile.
|
|
236
|
-
// `1` is prepended before area code to mobile numbers in international format.
|
|
237
|
-
expect(formatNumber({
|
|
238
|
-
country: 'MX',
|
|
239
|
-
phone: '3312345678'
|
|
240
|
-
}, 'INTERNATIONAL')).to.equal('+52 33 1234 5678');
|
|
241
|
-
expect(formatNumber({
|
|
242
|
-
country: 'MX',
|
|
243
|
-
phone: '3312345678'
|
|
244
|
-
}, 'NATIONAL')).to.equal('33 1234 5678');
|
|
245
|
-
// or '045 33 1234-5678'.
|
|
246
|
-
});
|
|
247
|
-
it('should format possible numbers', function () {
|
|
248
|
-
expect(formatNumber({
|
|
249
|
-
countryCallingCode: '7',
|
|
250
|
-
phone: '1111111111'
|
|
251
|
-
}, 'E.164')).to.equal('+71111111111');
|
|
252
|
-
expect(formatNumber({
|
|
253
|
-
countryCallingCode: '7',
|
|
254
|
-
phone: '1111111111'
|
|
255
|
-
}, 'NATIONAL')).to.equal('1111111111');
|
|
256
|
-
expect(formatNumber({
|
|
257
|
-
countryCallingCode: '7',
|
|
258
|
-
phone: '1111111111'
|
|
259
|
-
}, 'INTERNATIONAL')).to.equal('+7 1111111111');
|
|
260
|
-
});
|
|
261
|
-
it('should format IDD-prefixed number', function () {
|
|
262
|
-
// No `fromCountry`.
|
|
263
|
-
expect(formatNumber('+78005553535', 'IDD')).to.be.undefined;
|
|
264
|
-
|
|
265
|
-
// No default IDD prefix.
|
|
266
|
-
expect(formatNumber('+78005553535', 'IDD', {
|
|
267
|
-
fromCountry: 'BO'
|
|
268
|
-
})).to.be.undefined;
|
|
269
|
-
|
|
270
|
-
// Same country calling code.
|
|
271
|
-
expect(formatNumber('+12133734253', 'IDD', {
|
|
272
|
-
fromCountry: 'CA'
|
|
273
|
-
})).to.equal('1 (213) 373-4253');
|
|
274
|
-
expect(formatNumber('+78005553535', 'IDD', {
|
|
275
|
-
fromCountry: 'KZ'
|
|
276
|
-
})).to.equal('8 (800) 555-35-35');
|
|
277
|
-
|
|
278
|
-
// formatNumber('+78005553535', 'IDD', { fromCountry: 'US' }).should.equal('01178005553535')
|
|
279
|
-
expect(formatNumber('+78005553535', 'IDD', {
|
|
280
|
-
fromCountry: 'US'
|
|
281
|
-
})).to.equal('011 7 800 555 35 35');
|
|
282
|
-
});
|
|
283
|
-
it('should format non-geographic numbering plan phone numbers', function () {
|
|
284
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/323
|
|
285
|
-
expect(formatNumber('+870773111632', 'INTERNATIONAL')).to.equal('+870 773 111 632');
|
|
286
|
-
expect(formatNumber('+870773111632', 'NATIONAL')).to.equal('773 111 632');
|
|
287
|
-
});
|
|
288
|
-
it('should use the default IDD prefix when formatting a phone number', function () {
|
|
289
|
-
// Testing preferred international prefixes with ~ are supported.
|
|
290
|
-
// ("~" designates waiting on a line until proceeding with the input).
|
|
291
|
-
expect(formatNumber('+390236618300', 'IDD', {
|
|
292
|
-
fromCountry: 'BY'
|
|
293
|
-
})).to.equal('8~10 39 02 3661 8300');
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
//# sourceMappingURL=format.test.js.map
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
import { describe, it } from 'mocha';
|
|
3
|
-
import { expect } from 'chai';
|
|
4
|
-
import metadata from '../../metadata.max.json' with { type: 'json' };
|
|
5
|
-
import Metadata from '../metadata.js';
|
|
6
|
-
import _getNumberType from './getNumberType.js';
|
|
7
|
-
function getNumberType() {
|
|
8
|
-
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
9
|
-
parameters[_key] = arguments[_key];
|
|
10
|
-
}
|
|
11
|
-
parameters.push(metadata);
|
|
12
|
-
return _getNumberType.apply(this, parameters);
|
|
13
|
-
}
|
|
14
|
-
describe('getNumberType', function () {
|
|
15
|
-
it('should infer phone number type MOBILE', function () {
|
|
16
|
-
expect(getNumberType('9150000000', 'RU')).to.equal('MOBILE');
|
|
17
|
-
expect(getNumberType('7912345678', 'GB')).to.equal('MOBILE');
|
|
18
|
-
expect(getNumberType('51234567', 'EE')).to.equal('MOBILE');
|
|
19
|
-
});
|
|
20
|
-
it('should infer phone number types', function () {
|
|
21
|
-
expect(getNumberType('88005553535', 'RU')).to.equal('TOLL_FREE');
|
|
22
|
-
expect(getNumberType('8005553535', 'RU')).to.equal('TOLL_FREE');
|
|
23
|
-
expect(getNumberType('4957777777', 'RU')).to.equal('FIXED_LINE');
|
|
24
|
-
expect(getNumberType('8030000000', 'RU')).to.equal('PREMIUM_RATE');
|
|
25
|
-
expect(getNumberType('2133734253', 'US')).to.equal('FIXED_LINE_OR_MOBILE');
|
|
26
|
-
expect(getNumberType('5002345678', 'US')).to.equal('PERSONAL_NUMBER');
|
|
27
|
-
});
|
|
28
|
-
it('should work when no country is passed', function () {
|
|
29
|
-
expect(getNumberType('+79150000000')).to.equal('MOBILE');
|
|
30
|
-
});
|
|
31
|
-
it('should return FIXED_LINE_OR_MOBILE when there is ambiguity', function () {
|
|
32
|
-
// (no such country in the metadata, therefore no unit test for this `if`)
|
|
33
|
-
});
|
|
34
|
-
it('should work in edge cases', function () {
|
|
35
|
-
var thrower;
|
|
36
|
-
|
|
37
|
-
// // No metadata
|
|
38
|
-
// thrower = () => _getNumberType({ phone: '+78005553535' })
|
|
39
|
-
// thrower.should.throw('`metadata` argument not passed')
|
|
40
|
-
|
|
41
|
-
// Parsed phone number
|
|
42
|
-
expect(getNumberType({
|
|
43
|
-
phone: '8005553535',
|
|
44
|
-
country: 'RU'
|
|
45
|
-
})).to.equal('TOLL_FREE');
|
|
46
|
-
|
|
47
|
-
// Invalid phone number
|
|
48
|
-
expect(type(getNumberType('123', 'RU'))).to.equal('undefined');
|
|
49
|
-
|
|
50
|
-
// Invalid country
|
|
51
|
-
thrower = function thrower() {
|
|
52
|
-
return getNumberType({
|
|
53
|
-
phone: '8005553535',
|
|
54
|
-
country: 'RUS'
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
expect(thrower).to["throw"]('Unknown country');
|
|
58
|
-
|
|
59
|
-
// Numerical `value`
|
|
60
|
-
thrower = function thrower() {
|
|
61
|
-
return getNumberType(89150000000, 'RU');
|
|
62
|
-
};
|
|
63
|
-
expect(thrower).to["throw"]('A phone number must either be a string or an object of shape { phone, [country] }.');
|
|
64
|
-
|
|
65
|
-
// When `options` argument is passed.
|
|
66
|
-
expect(getNumberType('8005553535', 'RU', {})).to.equal('TOLL_FREE');
|
|
67
|
-
expect(getNumberType('+78005553535', {})).to.equal('TOLL_FREE');
|
|
68
|
-
expect(getNumberType({
|
|
69
|
-
phone: '8005553535',
|
|
70
|
-
country: 'RU'
|
|
71
|
-
}, {})).to.equal('TOLL_FREE');
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
function type(something) {
|
|
75
|
-
return _typeof(something);
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=getNumberType.test.js.map
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import metadata from '../../metadata.min.json' with { type: 'json' };
|
|
4
|
-
import _isPossibleNumber from './isPossibleNumber.js';
|
|
5
|
-
function isPossibleNumber() {
|
|
6
|
-
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
7
|
-
parameters[_key] = arguments[_key];
|
|
8
|
-
}
|
|
9
|
-
parameters.push(metadata);
|
|
10
|
-
return _isPossibleNumber.apply(this, parameters);
|
|
11
|
-
}
|
|
12
|
-
describe('isPossibleNumber', function () {
|
|
13
|
-
it('should work', function () {
|
|
14
|
-
expect(isPossibleNumber('+79992223344')).to.equal(true);
|
|
15
|
-
expect(isPossibleNumber({
|
|
16
|
-
phone: '1112223344',
|
|
17
|
-
country: 'RU'
|
|
18
|
-
})).to.equal(true);
|
|
19
|
-
expect(isPossibleNumber({
|
|
20
|
-
phone: '111222334',
|
|
21
|
-
country: 'RU'
|
|
22
|
-
})).to.equal(false);
|
|
23
|
-
expect(isPossibleNumber({
|
|
24
|
-
phone: '11122233445',
|
|
25
|
-
country: 'RU'
|
|
26
|
-
})).to.equal(false);
|
|
27
|
-
expect(isPossibleNumber({
|
|
28
|
-
phone: '1112223344',
|
|
29
|
-
countryCallingCode: 7
|
|
30
|
-
})).to.equal(true);
|
|
31
|
-
});
|
|
32
|
-
it('should work v2', function () {
|
|
33
|
-
expect(isPossibleNumber({
|
|
34
|
-
nationalNumber: '111222334',
|
|
35
|
-
countryCallingCode: 7
|
|
36
|
-
}, {
|
|
37
|
-
v2: true
|
|
38
|
-
})).to.equal(false);
|
|
39
|
-
expect(isPossibleNumber({
|
|
40
|
-
nationalNumber: '1112223344',
|
|
41
|
-
countryCallingCode: 7
|
|
42
|
-
}, {
|
|
43
|
-
v2: true
|
|
44
|
-
})).to.equal(true);
|
|
45
|
-
expect(isPossibleNumber({
|
|
46
|
-
nationalNumber: '11122233445',
|
|
47
|
-
countryCallingCode: 7
|
|
48
|
-
}, {
|
|
49
|
-
v2: true
|
|
50
|
-
})).to.equal(false);
|
|
51
|
-
});
|
|
52
|
-
it('should work in edge cases', function () {
|
|
53
|
-
// Invalid `PhoneNumber` argument.
|
|
54
|
-
expect(function () {
|
|
55
|
-
return isPossibleNumber({}, {
|
|
56
|
-
v2: true
|
|
57
|
-
});
|
|
58
|
-
}).to["throw"]('Invalid phone number object passed');
|
|
59
|
-
|
|
60
|
-
// Empty input is passed.
|
|
61
|
-
// This is just to support `isValidNumber({})`
|
|
62
|
-
// for cases when `parseNumber()` returns `{}`.
|
|
63
|
-
expect(isPossibleNumber({})).to.equal(false);
|
|
64
|
-
expect(function () {
|
|
65
|
-
return isPossibleNumber({
|
|
66
|
-
phone: '1112223344'
|
|
67
|
-
});
|
|
68
|
-
}).to["throw"]('Invalid phone number object passed');
|
|
69
|
-
|
|
70
|
-
// Incorrect country.
|
|
71
|
-
expect(function () {
|
|
72
|
-
return isPossibleNumber({
|
|
73
|
-
phone: '1112223344',
|
|
74
|
-
country: 'XX'
|
|
75
|
-
});
|
|
76
|
-
}).to["throw"]('Unknown country');
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
//# sourceMappingURL=isPossibleNumber.test.js.map
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import metadata from '../../metadata.min.json' with { type: 'json' };
|
|
4
|
-
import _isValidNumber from './isValidNumber.js';
|
|
5
|
-
function isValidNumber() {
|
|
6
|
-
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
7
|
-
parameters[_key] = arguments[_key];
|
|
8
|
-
}
|
|
9
|
-
parameters.push(metadata);
|
|
10
|
-
return _isValidNumber.apply(this, parameters);
|
|
11
|
-
}
|
|
12
|
-
describe('isValidNumber', function () {
|
|
13
|
-
it('should validate phone numbers', function () {
|
|
14
|
-
expect(isValidNumber('+1-213-373-4253')).to.equal(true);
|
|
15
|
-
expect(isValidNumber('+1-213-373')).to.equal(false);
|
|
16
|
-
expect(isValidNumber('+1-213-373-4253', undefined)).to.equal(true);
|
|
17
|
-
expect(isValidNumber('(213) 373-4253', 'US')).to.equal(true);
|
|
18
|
-
expect(isValidNumber('(213) 37', 'US')).to.equal(false);
|
|
19
|
-
expect(isValidNumber({
|
|
20
|
-
country: 'US',
|
|
21
|
-
phone: '2133734253'
|
|
22
|
-
})).to.equal(true);
|
|
23
|
-
|
|
24
|
-
// No "types" info: should return `true`.
|
|
25
|
-
expect(isValidNumber('+380972423740')).to.equal(true);
|
|
26
|
-
expect(isValidNumber('0912345678', 'TW')).to.equal(true);
|
|
27
|
-
|
|
28
|
-
// Moible numbers starting 07624* are Isle of Man
|
|
29
|
-
// which has its own "country code" "IM"
|
|
30
|
-
// which is in the "GB" "country calling code" zone.
|
|
31
|
-
// So while this number is for "IM" it's still supposed to
|
|
32
|
-
// be valid when passed "GB" as a default country.
|
|
33
|
-
expect(isValidNumber('07624369230', 'GB')).to.equal(true);
|
|
34
|
-
});
|
|
35
|
-
it('should refine phone number validation in case extended regular expressions are set for a country', function () {
|
|
36
|
-
// Germany general validation must pass
|
|
37
|
-
expect(isValidNumber('961111111', 'UZ')).to.equal(true);
|
|
38
|
-
var phoneNumberTypePatterns = metadata.countries.UZ[11];
|
|
39
|
-
|
|
40
|
-
// Different regular expressions for precise national number validation.
|
|
41
|
-
// `types` index in compressed array is `9` for v1.
|
|
42
|
-
// For v2 it's 10.
|
|
43
|
-
// For v3 it's 11.
|
|
44
|
-
metadata.countries.UZ[11] = [["(?:6(?:1(?:22|3[124]|4[1-4]|5[123578]|64)|2(?:22|3[0-57-9]|41)|5(?:22|3[3-7]|5[024-8])|6\\d{2}|7(?:[23]\\d|7[69])|9(?:22|4[1-8]|6[135]))|7(?:0(?:5[4-9]|6[0146]|7[12456]|9[135-8])|1[12]\\d|2(?:22|3[1345789]|4[123579]|5[14])|3(?:2\\d|3[1578]|4[1-35-7]|5[1-57]|61)|4(?:2\\d|3[1-579]|7[1-79])|5(?:22|5[1-9]|6[1457])|6(?:22|3[12457]|4[13-8])|9(?:22|5[1-9])))\\d{5}"], ["6(?:1(?:2(?:98|2[01])|35[0-4]|50\\d|61[23]|7(?:[01][017]|4\\d|55|9[5-9]))|2(?:11\\d|2(?:[12]1|9[01379])|5(?:[126]\\d|3[0-4])|7\\d{2})|5(?:19[01]|2(?:27|9[26])|30\\d|59\\d|7\\d{2})|6(?:2(?:1[5-9]|2[0367]|38|41|52|60)|3[79]\\d|4(?:56|83)|7(?:[07]\\d|1[017]|3[07]|4[047]|5[057]|67|8[0178]|9[79])|9[0-3]\\d)|7(?:2(?:24|3[237]|4[5-9]|7[15-8])|5(?:7[12]|8[0589])|7(?:0\\d|[39][07])|9(?:0\\d|7[079]))|9(?:2(?:1[1267]|5\\d|3[01]|7[0-4])|5[67]\\d|6(?:2[0-26]|8\\d)|7\\d{2}))\\d{4}|7(?:0\\d{3}|1(?:13[01]|6(?:0[47]|1[67]|66)|71[3-69]|98\\d)|2(?:2(?:2[79]|95)|3(?:2[5-9]|6[0-6])|57\\d|7(?:0\\d|1[17]|2[27]|3[37]|44|5[057]|66|88))|3(?:2(?:1[0-6]|21|3[469]|7[159])|33\\d|5(?:0[0-4]|5[579]|9\\d)|7(?:[0-3579]\\d|4[0467]|6[67]|8[078])|9[4-6]\\d)|4(?:2(?:29|5[0257]|6[0-7]|7[1-57])|5(?:1[0-4]|8\\d|9[5-9])|7(?:0\\d|1[024589]|2[0127]|3[0137]|[46][07]|5[01]|7[5-9]|9[079])|9(?:7[015-9]|[89]\\d))|5(?:112|2(?:0\\d|2[29]|[49]4)|3[1568]\\d|52[6-9]|7(?:0[01578]|1[017]|[23]7|4[047]|[5-7]\\d|8[78]|9[079]))|6(?:2(?:2[1245]|4[2-4])|39\\d|41[179]|5(?:[349]\\d|5[0-2])|7(?:0[017]|[13]\\d|22|44|55|67|88))|9(?:22[128]|3(?:2[0-4]|7\\d)|57[05629]|7(?:2[05-9]|3[37]|4\\d|60|7[2579]|87|9[07])))\\d{4}|9[0-57-9]\\d{7}"]];
|
|
45
|
-
|
|
46
|
-
// Extended validation must not pass for an invalid phone number
|
|
47
|
-
expect(isValidNumber('961111111', 'UZ')).to.equal(false);
|
|
48
|
-
|
|
49
|
-
// Extended validation must pass for a valid phone number
|
|
50
|
-
expect(isValidNumber('912345678', 'UZ')).to.equal(true);
|
|
51
|
-
metadata.countries.UZ[11] = phoneNumberTypePatterns;
|
|
52
|
-
});
|
|
53
|
-
it('should work in edge cases', function () {
|
|
54
|
-
// No metadata
|
|
55
|
-
var thrower = function thrower() {
|
|
56
|
-
return _isValidNumber('+78005553535');
|
|
57
|
-
};
|
|
58
|
-
expect(thrower).to["throw"]('`metadata` argument not passed');
|
|
59
|
-
|
|
60
|
-
// Non-phone-number characters in a phone number
|
|
61
|
-
expect(isValidNumber('+499821958a')).to.equal(false);
|
|
62
|
-
expect(isValidNumber('88005553535x', 'RU')).to.equal(false);
|
|
63
|
-
|
|
64
|
-
// Doesn't have `types` regexps in default metadata.
|
|
65
|
-
expect(isValidNumber({
|
|
66
|
-
country: 'UA',
|
|
67
|
-
phone: '300000000'
|
|
68
|
-
})).to.equal(true);
|
|
69
|
-
expect(isValidNumber({
|
|
70
|
-
country: 'UA',
|
|
71
|
-
phone: '200000000'
|
|
72
|
-
})).to.equal(false);
|
|
73
|
-
|
|
74
|
-
// Numerical `value`
|
|
75
|
-
thrower = function thrower() {
|
|
76
|
-
return isValidNumber(88005553535, 'RU');
|
|
77
|
-
};
|
|
78
|
-
expect(thrower).to["throw"]('A phone number must either be a string or an object of shape { phone, [country] }.');
|
|
79
|
-
|
|
80
|
-
// Long country phone code
|
|
81
|
-
expect(isValidNumber('+3725555555')).to.equal(true);
|
|
82
|
-
|
|
83
|
-
// Invalid country
|
|
84
|
-
thrower = function thrower() {
|
|
85
|
-
return isValidNumber({
|
|
86
|
-
phone: '8005553535',
|
|
87
|
-
country: 'RUS'
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
expect(thrower).to["throw"]('Unknown country');
|
|
91
|
-
});
|
|
92
|
-
it('should accept phone number extensions', function () {
|
|
93
|
-
// International
|
|
94
|
-
expect(isValidNumber('+12133734253 ext. 123')).to.equal(true);
|
|
95
|
-
// National
|
|
96
|
-
expect(isValidNumber('88005553535 x123', 'RU')).to.equal(true);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
//# sourceMappingURL=isValidNumber.test.js.map
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import metadata from '../../metadata.min.json' with { type: 'json' };
|
|
4
|
-
import isValidNumberForRegionCustom from './isValidNumberForRegion.js';
|
|
5
|
-
import _isValidNumberForRegion from './isValidNumberForRegion_.js';
|
|
6
|
-
function isValidNumberForRegion() {
|
|
7
|
-
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
8
|
-
parameters[_key] = arguments[_key];
|
|
9
|
-
}
|
|
10
|
-
parameters.push(metadata);
|
|
11
|
-
return isValidNumberForRegionCustom.apply(this, parameters);
|
|
12
|
-
}
|
|
13
|
-
describe('isValidNumberForRegion', function () {
|
|
14
|
-
it('should detect if is valid number for region', function () {
|
|
15
|
-
expect(isValidNumberForRegion('07624369230', 'GB')).to.equal(false);
|
|
16
|
-
expect(isValidNumberForRegion('07624369230', 'IM')).to.equal(true);
|
|
17
|
-
});
|
|
18
|
-
it('should validate arguments', function () {
|
|
19
|
-
expect(function () {
|
|
20
|
-
return isValidNumberForRegion({
|
|
21
|
-
phone: '7624369230',
|
|
22
|
-
country: 'GB'
|
|
23
|
-
});
|
|
24
|
-
}).to["throw"]('number must be a string');
|
|
25
|
-
expect(function () {
|
|
26
|
-
return isValidNumberForRegion('7624369230');
|
|
27
|
-
}).to["throw"]('country must be a string');
|
|
28
|
-
});
|
|
29
|
-
it('should work in edge cases', function () {
|
|
30
|
-
// Not a "viable" phone number.
|
|
31
|
-
expect(isValidNumberForRegion('7', 'GB')).to.equal(false);
|
|
32
|
-
|
|
33
|
-
// `options` argument `if/else` coverage.
|
|
34
|
-
expect(_isValidNumberForRegion('07624369230', 'GB', {}, metadata)).to.equal(false);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
//# sourceMappingURL=isValidNumberForRegion.test.js.map
|