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
package/source/format.test.js
DELETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import metadata from '../metadata.min.json' with { type: 'json' }
|
|
5
|
-
import formatNumber_ from './format.js'
|
|
6
|
-
import parsePhoneNumber from './parsePhoneNumber.js'
|
|
7
|
-
|
|
8
|
-
function formatNumber(...parameters) {
|
|
9
|
-
let v2
|
|
10
|
-
if (parameters.length < 1) {
|
|
11
|
-
// `input` parameter.
|
|
12
|
-
parameters.push(undefined)
|
|
13
|
-
} else {
|
|
14
|
-
// Convert string `input` to a `PhoneNumber` instance.
|
|
15
|
-
if (typeof parameters[0] === 'string') {
|
|
16
|
-
v2 = true
|
|
17
|
-
parameters[0] = parsePhoneNumber(parameters[0], {
|
|
18
|
-
...parameters[2],
|
|
19
|
-
extract: false
|
|
20
|
-
}, metadata)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (parameters.length < 2) {
|
|
24
|
-
// `format` parameter.
|
|
25
|
-
parameters.push(undefined)
|
|
26
|
-
}
|
|
27
|
-
if (parameters.length < 3) {
|
|
28
|
-
// `options` parameter.
|
|
29
|
-
parameters.push(undefined)
|
|
30
|
-
}
|
|
31
|
-
// Set `v2` flag.
|
|
32
|
-
parameters[2] = {
|
|
33
|
-
v2,
|
|
34
|
-
...parameters[2]
|
|
35
|
-
}
|
|
36
|
-
// Add `metadata` parameter.
|
|
37
|
-
parameters.push(metadata)
|
|
38
|
-
// Call the function.
|
|
39
|
-
return formatNumber_.apply(this, parameters)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
describe('format', () => {
|
|
43
|
-
it('should work with the first argument being a E.164 number', () => {
|
|
44
|
-
expect(formatNumber('+12133734253', 'NATIONAL')).to.equal('(213) 373-4253')
|
|
45
|
-
expect(formatNumber('+12133734253', 'INTERNATIONAL')).to.equal('+1 213 373 4253')
|
|
46
|
-
|
|
47
|
-
// Invalid number.
|
|
48
|
-
expect(formatNumber('+12111111111', 'NATIONAL')).to.equal('(211) 111-1111')
|
|
49
|
-
|
|
50
|
-
// Formatting invalid E.164 numbers.
|
|
51
|
-
expect(formatNumber('+11111', 'INTERNATIONAL')).to.equal('+1 1111')
|
|
52
|
-
expect(formatNumber('+11111', 'NATIONAL')).to.equal('1111')
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('should work with the first object argument expanded', () => {
|
|
56
|
-
expect(formatNumber('2133734253', 'NATIONAL', { defaultCountry: 'US' })).to.equal('(213) 373-4253')
|
|
57
|
-
expect(formatNumber('2133734253', 'INTERNATIONAL', { defaultCountry: 'US' })).to.equal('+1 213 373 4253')
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('should format using formats with no leading digits (`format.leadingDigitsPatterns().length === 0`)', () => {
|
|
61
|
-
expect(
|
|
62
|
-
formatNumber({ phone: '12345678901', countryCallingCode: 888 }, 'INTERNATIONAL')
|
|
63
|
-
).to.equal('+888 123 456 78901')
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
it('should sort out the arguments', () => {
|
|
67
|
-
const options = {
|
|
68
|
-
formatExtension: (number, extension) => `${number} доб. ${extension}`
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
expect(formatNumber({
|
|
72
|
-
phone : '8005553535',
|
|
73
|
-
country : 'RU',
|
|
74
|
-
ext : '123'
|
|
75
|
-
},
|
|
76
|
-
'NATIONAL', options)).to.equal('8 (800) 555-35-35 доб. 123')
|
|
77
|
-
|
|
78
|
-
// Parse number from string.
|
|
79
|
-
expect(formatNumber('+78005553535', 'NATIONAL', options)).to.equal('8 (800) 555-35-35')
|
|
80
|
-
expect(
|
|
81
|
-
formatNumber('8005553535', 'NATIONAL', { ...options, defaultCountry: 'RU' })
|
|
82
|
-
).to.equal('8 (800) 555-35-35')
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it('should format with national prefix when specifically instructed', () => {
|
|
86
|
-
// With national prefix.
|
|
87
|
-
expect(formatNumber('88005553535', 'NATIONAL', { defaultCountry: 'RU' })).to.equal('8 (800) 555-35-35')
|
|
88
|
-
// Without national prefix via an explicitly set option.
|
|
89
|
-
expect(
|
|
90
|
-
formatNumber('88005553535', 'NATIONAL', { nationalPrefix: false, defaultCountry: 'RU' })
|
|
91
|
-
).to.equal('800 555-35-35')
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('should format valid phone numbers', () => {
|
|
95
|
-
// Switzerland
|
|
96
|
-
expect(formatNumber({ country: 'CH', phone: '446681800' }, 'INTERNATIONAL')).to.equal('+41 44 668 18 00')
|
|
97
|
-
expect(formatNumber({ country: 'CH', phone: '446681800' }, 'E.164')).to.equal('+41446681800')
|
|
98
|
-
expect(formatNumber({ country: 'CH', phone: '446681800' }, 'RFC3966')).to.equal('tel:+41446681800')
|
|
99
|
-
expect(formatNumber({ country: 'CH', phone: '446681800' }, 'NATIONAL')).to.equal('044 668 18 00')
|
|
100
|
-
|
|
101
|
-
// France
|
|
102
|
-
expect(formatNumber({ country: 'FR', phone: '169454850' }, 'NATIONAL')).to.equal('01 69 45 48 50')
|
|
103
|
-
|
|
104
|
-
// Kazakhstan
|
|
105
|
-
expect(formatNumber('+7 702 211 1111', 'NATIONAL')).to.equal('8 (702) 211 1111')
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
it('should format national numbers with national prefix even if it\'s optional', () => {
|
|
109
|
-
// Russia
|
|
110
|
-
expect(formatNumber({ country: 'RU', phone: '9991234567' }, 'NATIONAL')).to.equal('8 (999) 123-45-67')
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
it('should work in edge cases', () => {
|
|
114
|
-
let thrower
|
|
115
|
-
|
|
116
|
-
// // No phone number
|
|
117
|
-
// formatNumber('', 'INTERNATIONAL', { defaultCountry: 'RU' }).should.equal('')
|
|
118
|
-
// formatNumber('', 'NATIONAL', { defaultCountry: 'RU' }).should.equal('')
|
|
119
|
-
|
|
120
|
-
expect(formatNumber({ country: 'RU', phone: '' }, 'INTERNATIONAL')).to.equal('+7')
|
|
121
|
-
expect(formatNumber({ country: 'RU', phone: '' }, 'NATIONAL')).to.equal('')
|
|
122
|
-
|
|
123
|
-
// No suitable format
|
|
124
|
-
expect(formatNumber('+121337342530', 'NATIONAL', { defaultCountry: 'US' })).to.equal('21337342530')
|
|
125
|
-
// No suitable format (leading digits mismatch)
|
|
126
|
-
expect(formatNumber('28199999', 'NATIONAL', { defaultCountry: 'AD' })).to.equal('28199999')
|
|
127
|
-
|
|
128
|
-
// // Numerical `value`
|
|
129
|
-
// thrower = () => formatNumber(89150000000, 'NATIONAL', { defaultCountry: 'RU' })
|
|
130
|
-
// thrower.should.throw('A phone number must either be a string or an object of shape { phone, [country] }.')
|
|
131
|
-
|
|
132
|
-
// // No metadata for country
|
|
133
|
-
// expect(() => formatNumber('+121337342530', 'NATIONAL', { defaultCountry: 'USA' })).to.throw('Unknown country')
|
|
134
|
-
// expect(() => formatNumber('21337342530', 'NATIONAL', { defaultCountry: 'USA' })).to.throw('Unknown country')
|
|
135
|
-
|
|
136
|
-
// No format type
|
|
137
|
-
thrower = () => formatNumber('+123')
|
|
138
|
-
expect(thrower).to.throw('Unknown "format" argument')
|
|
139
|
-
|
|
140
|
-
// Unknown format type
|
|
141
|
-
thrower = () => formatNumber('123', 'Gay', { defaultCountry: 'US' })
|
|
142
|
-
expect(thrower).to.throw('Unknown "format" argument')
|
|
143
|
-
|
|
144
|
-
// // No metadata
|
|
145
|
-
// thrower = () => _formatNumber('123', 'E.164', { defaultCountry: 'RU' })
|
|
146
|
-
// thrower.should.throw('`metadata`')
|
|
147
|
-
|
|
148
|
-
// No formats
|
|
149
|
-
expect(formatNumber('012345', 'NATIONAL', { defaultCountry: 'AC' })).to.equal('012345')
|
|
150
|
-
|
|
151
|
-
// No `fromCountry` for `IDD` format.
|
|
152
|
-
expect(formatNumber('+78005553535', 'IDD')).to.be.undefined
|
|
153
|
-
|
|
154
|
-
// `fromCountry` has no default IDD prefix.
|
|
155
|
-
expect(formatNumber('+78005553535', 'IDD', { fromCountry: 'BO' })).to.be.undefined
|
|
156
|
-
|
|
157
|
-
// No such country.
|
|
158
|
-
expect(() => formatNumber({ phone: '123', country: 'USA' }, 'NATIONAL')).to.throw('Unknown country')
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
it('should format phone number extensions', () => {
|
|
162
|
-
// National
|
|
163
|
-
expect(formatNumber({
|
|
164
|
-
country: 'US',
|
|
165
|
-
phone: '2133734253',
|
|
166
|
-
ext: '123'
|
|
167
|
-
},
|
|
168
|
-
'NATIONAL')).to.equal('(213) 373-4253 ext. 123')
|
|
169
|
-
|
|
170
|
-
// International
|
|
171
|
-
expect(formatNumber({
|
|
172
|
-
country : 'US',
|
|
173
|
-
phone : '2133734253',
|
|
174
|
-
ext : '123'
|
|
175
|
-
},
|
|
176
|
-
'INTERNATIONAL')).to.equal('+1 213 373 4253 ext. 123')
|
|
177
|
-
|
|
178
|
-
// International
|
|
179
|
-
expect(formatNumber({
|
|
180
|
-
country : 'US',
|
|
181
|
-
phone : '2133734253',
|
|
182
|
-
ext : '123'
|
|
183
|
-
},
|
|
184
|
-
'INTERNATIONAL')).to.equal('+1 213 373 4253 ext. 123')
|
|
185
|
-
|
|
186
|
-
// E.164
|
|
187
|
-
expect(formatNumber({
|
|
188
|
-
country : 'US',
|
|
189
|
-
phone : '2133734253',
|
|
190
|
-
ext : '123'
|
|
191
|
-
},
|
|
192
|
-
'E.164')).to.equal('+12133734253')
|
|
193
|
-
|
|
194
|
-
// RFC3966
|
|
195
|
-
expect(formatNumber({
|
|
196
|
-
country : 'US',
|
|
197
|
-
phone : '2133734253',
|
|
198
|
-
ext : '123'
|
|
199
|
-
},
|
|
200
|
-
'RFC3966')).to.equal('tel:+12133734253;ext=123')
|
|
201
|
-
|
|
202
|
-
// Custom ext prefix.
|
|
203
|
-
expect(formatNumber({
|
|
204
|
-
country : 'GB',
|
|
205
|
-
phone : '7912345678',
|
|
206
|
-
ext : '123'
|
|
207
|
-
},
|
|
208
|
-
'INTERNATIONAL')).to.equal('+44 7912 345678 x123')
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
it('should work with Argentina numbers', () => {
|
|
212
|
-
// The same mobile number is written differently
|
|
213
|
-
// in different formats in Argentina:
|
|
214
|
-
// `9` gets prepended in international format.
|
|
215
|
-
expect(formatNumber({ country: 'AR', phone: '3435551212' }, 'INTERNATIONAL')).to.equal('+54 3435 55 1212')
|
|
216
|
-
expect(formatNumber({ country: 'AR', phone: '3435551212' }, 'NATIONAL')).to.equal('03435 55-1212')
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
it('should work with Mexico numbers', () => {
|
|
220
|
-
// Fixed line.
|
|
221
|
-
expect(formatNumber({ country: 'MX', phone: '4499780001' }, 'INTERNATIONAL')).to.equal('+52 449 978 0001')
|
|
222
|
-
expect(formatNumber({ country: 'MX', phone: '4499780001' }, 'NATIONAL')).to.equal('449 978 0001')
|
|
223
|
-
// or '(449)978-0001'.
|
|
224
|
-
// Mobile.
|
|
225
|
-
// `1` is prepended before area code to mobile numbers in international format.
|
|
226
|
-
expect(formatNumber({ country: 'MX', phone: '3312345678' }, 'INTERNATIONAL')).to.equal('+52 33 1234 5678')
|
|
227
|
-
expect(formatNumber({ country: 'MX', phone: '3312345678' }, 'NATIONAL')).to.equal('33 1234 5678')
|
|
228
|
-
// or '045 33 1234-5678'.
|
|
229
|
-
})
|
|
230
|
-
|
|
231
|
-
it('should format possible numbers', () => {
|
|
232
|
-
expect(formatNumber({ countryCallingCode: '7', phone: '1111111111' }, 'E.164')).to.equal('+71111111111')
|
|
233
|
-
|
|
234
|
-
expect(formatNumber({ countryCallingCode: '7', phone: '1111111111' }, 'NATIONAL')).to.equal('1111111111')
|
|
235
|
-
|
|
236
|
-
expect(
|
|
237
|
-
formatNumber({ countryCallingCode: '7', phone: '1111111111' }, 'INTERNATIONAL')
|
|
238
|
-
).to.equal('+7 1111111111')
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
it('should format IDD-prefixed number', () => {
|
|
242
|
-
// No `fromCountry`.
|
|
243
|
-
expect(formatNumber('+78005553535', 'IDD')).to.be.undefined
|
|
244
|
-
|
|
245
|
-
// No default IDD prefix.
|
|
246
|
-
expect(formatNumber('+78005553535', 'IDD', { fromCountry: 'BO' })).to.be.undefined
|
|
247
|
-
|
|
248
|
-
// Same country calling code.
|
|
249
|
-
expect(
|
|
250
|
-
formatNumber('+12133734253', 'IDD', { fromCountry: 'CA' })
|
|
251
|
-
).to.equal('1 (213) 373-4253')
|
|
252
|
-
expect(
|
|
253
|
-
formatNumber('+78005553535', 'IDD', { fromCountry: 'KZ' })
|
|
254
|
-
).to.equal('8 (800) 555-35-35')
|
|
255
|
-
|
|
256
|
-
// formatNumber('+78005553535', 'IDD', { fromCountry: 'US' }).should.equal('01178005553535')
|
|
257
|
-
expect(
|
|
258
|
-
formatNumber('+78005553535', 'IDD', { fromCountry: 'US' })
|
|
259
|
-
).to.equal('011 7 800 555 35 35')
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
it('should format non-geographic numbering plan phone numbers', () => {
|
|
263
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/323
|
|
264
|
-
expect(formatNumber('+870773111632', 'INTERNATIONAL')).to.equal('+870 773 111 632')
|
|
265
|
-
expect(formatNumber('+870773111632', 'NATIONAL')).to.equal('773 111 632')
|
|
266
|
-
})
|
|
267
|
-
|
|
268
|
-
it('should use the default IDD prefix when formatting a phone number', () => {
|
|
269
|
-
// Testing preferred international prefixes with ~ are supported.
|
|
270
|
-
// ("~" designates waiting on a line until proceeding with the input).
|
|
271
|
-
expect(formatNumber('+390236618300', 'IDD', { fromCountry: 'BY' })).to.equal('8~10 39 02 3661 8300')
|
|
272
|
-
})
|
|
273
|
-
})
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import formatIncompletePhoneNumber from './formatIncompletePhoneNumber.js'
|
|
5
|
-
|
|
6
|
-
import metadata from '../metadata.min.json' with { type: 'json' }
|
|
7
|
-
|
|
8
|
-
describe('formatIncompletePhoneNumber', () => {
|
|
9
|
-
it('should format parsed input value', () => {
|
|
10
|
-
let result
|
|
11
|
-
|
|
12
|
-
// National input.
|
|
13
|
-
expect(formatIncompletePhoneNumber('880055535', 'RU', metadata)).to.equal('8 (800) 555-35')
|
|
14
|
-
|
|
15
|
-
// International input, no country.
|
|
16
|
-
expect(formatIncompletePhoneNumber('+780055535', null, metadata)).to.equal('+7 800 555 35')
|
|
17
|
-
|
|
18
|
-
// International input, no country argument.
|
|
19
|
-
expect(formatIncompletePhoneNumber('+780055535', metadata)).to.equal('+7 800 555 35')
|
|
20
|
-
|
|
21
|
-
// International input, with country.
|
|
22
|
-
expect(formatIncompletePhoneNumber('+780055535', 'RU', metadata)).to.equal('+7 800 555 35')
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('should support an object argument', () => {
|
|
26
|
-
expect(
|
|
27
|
-
formatIncompletePhoneNumber('880055535', { defaultCountry: 'RU' }, metadata)
|
|
28
|
-
).to.equal('8 (800) 555-35')
|
|
29
|
-
expect(
|
|
30
|
-
formatIncompletePhoneNumber('880055535', { defaultCallingCode: '7' }, metadata)
|
|
31
|
-
).to.equal('8 (800) 555-35')
|
|
32
|
-
})
|
|
33
|
-
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import metadata from '../metadata.min.json' with { type: 'json' }
|
|
5
|
-
|
|
6
|
-
import getCountries from './getCountries.js'
|
|
7
|
-
|
|
8
|
-
describe('getCountries', () => {
|
|
9
|
-
it('should get countries list', () => {
|
|
10
|
-
expect(getCountries(metadata).indexOf('RU') > 0).to.equal(true);
|
|
11
|
-
})
|
|
12
|
-
})
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import metadata from '../metadata.min.json' with { type: 'json' }
|
|
5
|
-
|
|
6
|
-
import getCountryCallingCode from './getCountryCallingCode.js'
|
|
7
|
-
|
|
8
|
-
describe('getCountryCallingCode', () => {
|
|
9
|
-
it('should get country calling code', () => {
|
|
10
|
-
expect(getCountryCallingCode('US', metadata)).to.equal('1')
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
it('should throw if country is unknown', () => {
|
|
14
|
-
expect(() => getCountryCallingCode('ZZ', metadata)).to.throw('Unknown country: ZZ')
|
|
15
|
-
})
|
|
16
|
-
})
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import examples from '../examples.mobile.json' with { type: 'json' }
|
|
5
|
-
import metadata from '../metadata.min.json' with { type: 'json' }
|
|
6
|
-
import getExampleNumber from './getExampleNumber.js'
|
|
7
|
-
|
|
8
|
-
describe('getExampleNumber', () => {
|
|
9
|
-
it('should get an example number', () => {
|
|
10
|
-
const phoneNumber = getExampleNumber('RU', examples, metadata)
|
|
11
|
-
expect(phoneNumber.nationalNumber).to.equal('9123456789')
|
|
12
|
-
expect(phoneNumber.number).to.equal('+79123456789')
|
|
13
|
-
expect(phoneNumber.countryCallingCode).to.equal('7')
|
|
14
|
-
expect(phoneNumber.country).to.equal('RU')
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it('should handle a non-existing country', () => {
|
|
18
|
-
expect(getExampleNumber('XX', examples, metadata)).to.be.undefined
|
|
19
|
-
})
|
|
20
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import { parseRFC3966, formatRFC3966 } from './RFC3966.js'
|
|
5
|
-
|
|
6
|
-
describe('RFC3966', () => {
|
|
7
|
-
it('should format', () => {
|
|
8
|
-
expect(() => formatRFC3966({ number: '123' })).to.throw('expects "number" to be in E.164 format')
|
|
9
|
-
expect(formatRFC3966({})).to.equal('')
|
|
10
|
-
expect(formatRFC3966({ number: '+78005553535' })).to.equal('tel:+78005553535')
|
|
11
|
-
expect(formatRFC3966({ number: '+78005553535', ext: '123' })).to.equal('tel:+78005553535;ext=123')
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('should parse', () => {
|
|
15
|
-
expect(parseRFC3966('tel:+78005553535')).to.deep.equal({
|
|
16
|
-
number : '+78005553535'
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
expect(parseRFC3966('tel:+78005553535;ext=123')).to.deep.equal({
|
|
20
|
-
number : '+78005553535',
|
|
21
|
-
ext : '123'
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
// With `phone-context`
|
|
25
|
-
expect(parseRFC3966('tel:8005553535;ext=123;phone-context=+7')).to.deep.equal({
|
|
26
|
-
number : '+78005553535',
|
|
27
|
-
ext : '123'
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
// "Domain contexts" are ignored
|
|
31
|
-
expect(parseRFC3966('tel:8005553535;ext=123;phone-context=www.leningrad.spb.ru')).to.deep.equal({
|
|
32
|
-
number : '8005553535',
|
|
33
|
-
ext : '123'
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
// Not a viable phone number.
|
|
37
|
-
expect(parseRFC3966('tel:3')).to.deep.equal({})
|
|
38
|
-
})
|
|
39
|
-
})
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import applyInternationalSeparatorStyle from './applyInternationalSeparatorStyle.js'
|
|
5
|
-
|
|
6
|
-
describe('applyInternationalSeparatorStyle', () => {
|
|
7
|
-
it('should change Google\'s international format style', () => {
|
|
8
|
-
expect(applyInternationalSeparatorStyle('(xxx) xxx-xx-xx')).to.equal('xxx xxx xx xx')
|
|
9
|
-
expect(applyInternationalSeparatorStyle('(xxx)xxx')).to.equal('xxx xxx')
|
|
10
|
-
})
|
|
11
|
-
})
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import Metadata from '../metadata.js'
|
|
5
|
-
import metadata from '../../metadata.max.json' with { type: 'json' }
|
|
6
|
-
import oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }
|
|
7
|
-
|
|
8
|
-
import checkNumberLength, { checkNumberLengthForType } from './checkNumberLength.js'
|
|
9
|
-
|
|
10
|
-
describe('checkNumberLength', () => {
|
|
11
|
-
it('should check phone number length', () => {
|
|
12
|
-
// Too short.
|
|
13
|
-
expect(checkNumberLengthWithCountry('800555353', 'RU', 'FIXED_LINE')).to.equal('TOO_SHORT')
|
|
14
|
-
// Normal.
|
|
15
|
-
expect(checkNumberLengthWithCountry('8005553535', 'RU', 'FIXED_LINE')).to.equal('IS_POSSIBLE')
|
|
16
|
-
// Too long.
|
|
17
|
-
expect(checkNumberLengthWithCountry('80055535355', 'RU', 'FIXED_LINE')).to.equal('TOO_LONG')
|
|
18
|
-
|
|
19
|
-
// No such type.
|
|
20
|
-
expect(checkNumberLengthWithCountry('169454850', 'AC', 'VOIP')).to.equal('INVALID_LENGTH')
|
|
21
|
-
// No such possible length.
|
|
22
|
-
expect(checkNumberLengthWithCountry('1694548', 'AD', undefined)).to.equal('INVALID_LENGTH')
|
|
23
|
-
|
|
24
|
-
// FIXED_LINE_OR_MOBILE
|
|
25
|
-
expect(checkNumberLengthWithCountry('1694548', 'AD', 'FIXED_LINE_OR_MOBILE')).to.equal('INVALID_LENGTH')
|
|
26
|
-
// No mobile phones.
|
|
27
|
-
expect(checkNumberLengthWithCountry('8123', 'TA', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')
|
|
28
|
-
// No "possible lengths" for "mobile".
|
|
29
|
-
expect(checkNumberLengthWithCountry('81234567', 'SZ', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('should check phone number length (no `country` specified)', () => {
|
|
33
|
-
// Too short.
|
|
34
|
-
expect(checkNumberLengthWithoutCountry('800555353', 'RU', 'FIXED_LINE')).to.equal('TOO_SHORT')
|
|
35
|
-
// Normal.
|
|
36
|
-
expect(checkNumberLengthWithoutCountry('8005553535', 'RU', 'FIXED_LINE')).to.equal('IS_POSSIBLE')
|
|
37
|
-
// Too long.
|
|
38
|
-
expect(checkNumberLengthWithoutCountry('80055535355', 'RU', 'FIXED_LINE')).to.equal('TOO_LONG')
|
|
39
|
-
|
|
40
|
-
// No such type.
|
|
41
|
-
expect(checkNumberLengthWithoutCountry('169454850', 'AC', 'VOIP')).to.equal('INVALID_LENGTH')
|
|
42
|
-
// No such possible length.
|
|
43
|
-
expect(checkNumberLengthWithoutCountry('1694548', 'AD', undefined)).to.equal('INVALID_LENGTH')
|
|
44
|
-
|
|
45
|
-
// FIXED_LINE_OR_MOBILE
|
|
46
|
-
expect(checkNumberLengthWithoutCountry('1694548', 'AD', 'FIXED_LINE_OR_MOBILE')).to.equal('INVALID_LENGTH')
|
|
47
|
-
// No mobile phones.
|
|
48
|
-
expect(checkNumberLengthWithoutCountry('8123', 'TA', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')
|
|
49
|
-
// No "possible lengths" for "mobile".
|
|
50
|
-
expect(checkNumberLengthWithoutCountry('81234567', 'SZ', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it('should work for old metadata', function() {
|
|
54
|
-
const _oldMetadata = new Metadata(oldMetadata)
|
|
55
|
-
_oldMetadata.country('RU')
|
|
56
|
-
expect(checkNumberLengthForType('8005553535', 'RU', 'FIXED_LINE', _oldMetadata)).to.equal('IS_POSSIBLE')
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('should work for old metadata (no `country` specified)', function() {
|
|
60
|
-
const _oldMetadata = new Metadata(oldMetadata)
|
|
61
|
-
_oldMetadata.country('RU')
|
|
62
|
-
expect(checkNumberLengthForType('8005553535', undefined, 'FIXED_LINE', _oldMetadata)).to.equal('IS_POSSIBLE')
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
it('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-"main" country and is not possible in the "main" country', () => {
|
|
66
|
-
const _metadata = new Metadata(metadata)
|
|
67
|
-
_metadata.country('US')
|
|
68
|
-
|
|
69
|
-
expect(checkNumberLength('3100000', undefined, _metadata)).to.equal('TOO_SHORT');
|
|
70
|
-
expect(checkNumberLength('3100000', 'US', _metadata)).to.equal('TOO_SHORT');
|
|
71
|
-
expect(checkNumberLength('3100000', 'CA', _metadata)).to.equal('IS_POSSIBLE');
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
function checkNumberLengthWithCountry(number, country, type) {
|
|
76
|
-
const _metadata = new Metadata(metadata)
|
|
77
|
-
_metadata.country(country)
|
|
78
|
-
return checkNumberLengthForType(number, country, type, _metadata)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function checkNumberLengthWithoutCountry(number, country, type) {
|
|
82
|
-
const _metadata = new Metadata(metadata)
|
|
83
|
-
_metadata.country(country)
|
|
84
|
-
return checkNumberLengthForType(number, undefined, type, _metadata)
|
|
85
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import extractCountryCallingCode from './extractCountryCallingCode.js'
|
|
5
|
-
import metadata from '../../metadata.min.json' with { type: 'json' }
|
|
6
|
-
|
|
7
|
-
describe('extractCountryCallingCode', () => {
|
|
8
|
-
it('should extract country calling code from a number', () => {
|
|
9
|
-
expect(extractCountryCallingCode('+78005553535', null, null, null, metadata)).to.deep.equal({
|
|
10
|
-
countryCallingCodeSource: 'FROM_NUMBER_WITH_PLUS_SIGN',
|
|
11
|
-
countryCallingCode: '7',
|
|
12
|
-
number: '8005553535'
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
expect(extractCountryCallingCode('+7800', null, null, null, metadata)).to.deep.equal({
|
|
16
|
-
countryCallingCodeSource: 'FROM_NUMBER_WITH_PLUS_SIGN',
|
|
17
|
-
countryCallingCode: '7',
|
|
18
|
-
number: '800'
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
expect(extractCountryCallingCode('', null, null, null, metadata)).to.deep.equal({})
|
|
22
|
-
})
|
|
23
|
-
})
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import extractNationalNumber from './extractNationalNumber.js'
|
|
5
|
-
|
|
6
|
-
import Metadata from '../metadata.js'
|
|
7
|
-
import oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }
|
|
8
|
-
|
|
9
|
-
describe('extractNationalNumber', function() {
|
|
10
|
-
it('should extract a national number when using old metadata (no `country` or `defaultCountry` specified)', function() {
|
|
11
|
-
const _oldMetadata = new Metadata(oldMetadata)
|
|
12
|
-
_oldMetadata.selectNumberingPlan('RU')
|
|
13
|
-
expect(extractNationalNumber('88005553535', undefined, _oldMetadata)).to.deep.equal({
|
|
14
|
-
nationalNumber: '8005553535',
|
|
15
|
-
carrierCode: undefined
|
|
16
|
-
})
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('should extract a national number when using old metadata (`country` is specified)', function() {
|
|
20
|
-
const _oldMetadata = new Metadata(oldMetadata)
|
|
21
|
-
_oldMetadata.selectNumberingPlan('RU')
|
|
22
|
-
expect(extractNationalNumber('88005553535', 'RU', _oldMetadata)).to.deep.equal({
|
|
23
|
-
nationalNumber: '8005553535',
|
|
24
|
-
carrierCode: undefined
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
})
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import Metadata from '../metadata.js'
|
|
5
|
-
import metadata from '../../metadata.min.json' with { type: 'json' }
|
|
6
|
-
import extractNationalNumberFromPossiblyIncompleteNumber from './extractNationalNumberFromPossiblyIncompleteNumber.js'
|
|
7
|
-
|
|
8
|
-
describe('extractNationalNumberFromPossiblyIncompleteNumber', () => {
|
|
9
|
-
it('should parse a carrier code when there is no national prefix transform rule', () => {
|
|
10
|
-
const meta = new Metadata(metadata)
|
|
11
|
-
meta.country('AU')
|
|
12
|
-
expect(extractNationalNumberFromPossiblyIncompleteNumber('18311800123', meta)).to.deep.equal({
|
|
13
|
-
nationalPrefix: undefined,
|
|
14
|
-
carrierCode: '1831',
|
|
15
|
-
nationalNumber: '1800123'
|
|
16
|
-
})
|
|
17
|
-
})
|
|
18
|
-
})
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import parsePhoneNumber_ from '../parsePhoneNumber.js'
|
|
5
|
-
import PhoneNumber from '../PhoneNumber.js'
|
|
6
|
-
import metadata from '../../metadata.min.json' with { type: 'json' }
|
|
7
|
-
|
|
8
|
-
function parsePhoneNumber(...parameters) {
|
|
9
|
-
parameters.push(metadata)
|
|
10
|
-
return parsePhoneNumber_.apply(this, parameters)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
describe('extractPhoneContext', function() {
|
|
14
|
-
it('should parse RFC 3966 phone number URIs', function() {
|
|
15
|
-
// context = ";phone-context=" descriptor
|
|
16
|
-
// descriptor = domainname / global-number-digits
|
|
17
|
-
|
|
18
|
-
const NZ_NUMBER = new PhoneNumber('64', '33316005', metadata)
|
|
19
|
-
|
|
20
|
-
// Valid global-phone-digits
|
|
21
|
-
expectPhoneNumbersToBeEqual(
|
|
22
|
-
parsePhoneNumber('tel:033316005;phone-context=+64'),
|
|
23
|
-
NZ_NUMBER
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
expectPhoneNumbersToBeEqual(
|
|
27
|
-
parsePhoneNumber('tel:033316005;phone-context=+64;{this isn\'t part of phone-context anymore!}'),
|
|
28
|
-
NZ_NUMBER
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
const nzFromPhoneContext = new PhoneNumber('64', '3033316005', metadata)
|
|
32
|
-
expectPhoneNumbersToBeEqual(
|
|
33
|
-
parsePhoneNumber('tel:033316005;phone-context=+64-3'),
|
|
34
|
-
nzFromPhoneContext
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
const brFromPhoneContext = new PhoneNumber('55', '5033316005', metadata)
|
|
38
|
-
expectPhoneNumbersToBeEqual(
|
|
39
|
-
parsePhoneNumber('tel:033316005;phone-context=+(555)'),
|
|
40
|
-
brFromPhoneContext
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
const usFromPhoneContext = new PhoneNumber('1', '23033316005', metadata)
|
|
44
|
-
expectPhoneNumbersToBeEqual(
|
|
45
|
-
parsePhoneNumber('tel:033316005;phone-context=+-1-2.3()'),
|
|
46
|
-
usFromPhoneContext
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
// Valid domainname.
|
|
50
|
-
expectPhoneNumbersToBeEqual(
|
|
51
|
-
parsePhoneNumber('tel:033316005;phone-context=abc.nz', 'NZ'),
|
|
52
|
-
NZ_NUMBER
|
|
53
|
-
)
|
|
54
|
-
expectPhoneNumbersToBeEqual(
|
|
55
|
-
parsePhoneNumber('tel:033316005;phone-context=www.PHONE-numb3r.com', 'NZ'),
|
|
56
|
-
NZ_NUMBER
|
|
57
|
-
)
|
|
58
|
-
expectPhoneNumbersToBeEqual(
|
|
59
|
-
parsePhoneNumber('tel:033316005;phone-context=a', 'NZ'),
|
|
60
|
-
NZ_NUMBER
|
|
61
|
-
)
|
|
62
|
-
expectPhoneNumbersToBeEqual(
|
|
63
|
-
parsePhoneNumber('tel:033316005;phone-context=3phone.J.', 'NZ'),
|
|
64
|
-
NZ_NUMBER
|
|
65
|
-
)
|
|
66
|
-
expectPhoneNumbersToBeEqual(
|
|
67
|
-
parsePhoneNumber('tel:033316005;phone-context=a--z', 'NZ'),
|
|
68
|
-
NZ_NUMBER
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
// Should strip ISDN subaddress.
|
|
72
|
-
expectPhoneNumbersToBeEqual(
|
|
73
|
-
parsePhoneNumber('tel:033316005;isub=/@;phone-context=+64', 'NZ'),
|
|
74
|
-
NZ_NUMBER
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
// // Should support incorrectly-written RFC 3966 phone numbers:
|
|
78
|
-
// // the ones written without a `tel:` prefix.
|
|
79
|
-
// expectPhoneNumbersToBeEqual(
|
|
80
|
-
// parsePhoneNumber('033316005;phone-context=+64', 'NZ'),
|
|
81
|
-
// NZ_NUMBER
|
|
82
|
-
// )
|
|
83
|
-
|
|
84
|
-
// Invalid descriptor.
|
|
85
|
-
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=')
|
|
86
|
-
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=+')
|
|
87
|
-
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=64')
|
|
88
|
-
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=++64')
|
|
89
|
-
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=+abc')
|
|
90
|
-
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=.')
|
|
91
|
-
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=3phone')
|
|
92
|
-
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=a-.nz')
|
|
93
|
-
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=a{b}c')
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
function expectToThrowForInvalidPhoneContext(string) {
|
|
98
|
-
expect(parsePhoneNumber(string)).to.be.undefined
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function expectPhoneNumbersToBeEqual(phoneNumber1, phoneNumber2) {
|
|
102
|
-
if (!phoneNumber1 || !phoneNumber2) {
|
|
103
|
-
return false
|
|
104
|
-
}
|
|
105
|
-
return phoneNumber1.number === phoneNumber2.number &&
|
|
106
|
-
phoneNumber1.ext === phoneNumber2.ext
|
|
107
|
-
}
|