libphonenumber-js 1.12.39 → 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 +23 -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/parse.test.js
DELETED
|
@@ -1,561 +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 _parseNumber from './parse.js'
|
|
6
|
-
import Metadata from './metadata.js'
|
|
7
|
-
|
|
8
|
-
function parseNumber(...parameters) {
|
|
9
|
-
if (parameters.length < 2) {
|
|
10
|
-
// `options` parameter.
|
|
11
|
-
parameters.push(undefined)
|
|
12
|
-
}
|
|
13
|
-
// Convert default country argument to an `options` object.
|
|
14
|
-
if (typeof parameters[1] === 'string') {
|
|
15
|
-
parameters[1] = {
|
|
16
|
-
...parameters[2],
|
|
17
|
-
defaultCountry: parameters[1]
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
if (parameters[2]) {
|
|
21
|
-
parameters[2] = metadata
|
|
22
|
-
} else {
|
|
23
|
-
parameters.push(metadata)
|
|
24
|
-
}
|
|
25
|
-
return _parseNumber.apply(this, parameters)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
|
|
29
|
-
|
|
30
|
-
describe('parse', () => {
|
|
31
|
-
it('should not parse invalid phone numbers', () => {
|
|
32
|
-
// Too short.
|
|
33
|
-
expect(parseNumber('+7 (800) 55-35-35')).to.deep.equal({})
|
|
34
|
-
// Too long.
|
|
35
|
-
expect(parseNumber('+7 (800) 55-35-35-55')).to.deep.equal({})
|
|
36
|
-
|
|
37
|
-
expect(parseNumber('+7 (800) 55-35-35', 'US')).to.deep.equal({})
|
|
38
|
-
expect(parseNumber('(800) 55 35 35', { defaultCountry: 'RU' })).to.deep.equal({})
|
|
39
|
-
expect(parseNumber('+1 187 215 5230', 'US')).to.deep.equal({})
|
|
40
|
-
|
|
41
|
-
expect(parseNumber('911231231', 'BE')).to.deep.equal({})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('should parse valid phone numbers', () => {
|
|
45
|
-
// Instant loans
|
|
46
|
-
// https://www.youtube.com/watch?v=6e1pMrYH5jI
|
|
47
|
-
//
|
|
48
|
-
// Restrict to RU
|
|
49
|
-
expect(parseNumber('Phone: 8 (800) 555 35 35.', 'RU')).to.deep.equal({ country: 'RU', phone: '8005553535' })
|
|
50
|
-
// International format
|
|
51
|
-
expect(parseNumber('Phone: +7 (800) 555-35-35.')).to.deep.equal({ country: 'RU', phone: '8005553535' })
|
|
52
|
-
// // Restrict to US, but not a US country phone code supplied
|
|
53
|
-
// parseNumber('+7 (800) 555-35-35', 'US').should.deep.equal({})
|
|
54
|
-
// Restrict to RU
|
|
55
|
-
expect(parseNumber('(800) 555 35 35', 'RU')).to.deep.equal({ country: 'RU', phone: '8005553535' })
|
|
56
|
-
// Default to RU
|
|
57
|
-
expect(parseNumber('8 (800) 555 35 35', { defaultCountry: 'RU' })).to.deep.equal({ country: 'RU', phone: '8005553535' })
|
|
58
|
-
|
|
59
|
-
// Gangster partyline
|
|
60
|
-
expect(parseNumber('+1-213-373-4253')).to.deep.equal({ country: 'US', phone: '2133734253' })
|
|
61
|
-
|
|
62
|
-
// Switzerland (just in case)
|
|
63
|
-
expect(parseNumber('044 668 18 00', 'CH')).to.deep.equal({ country: 'CH', phone: '446681800' })
|
|
64
|
-
|
|
65
|
-
// China, Beijing
|
|
66
|
-
expect(parseNumber('010-852644821', 'CN')).to.deep.equal({ country: 'CN', phone: '10852644821' })
|
|
67
|
-
|
|
68
|
-
// France
|
|
69
|
-
expect(parseNumber('+33169454850')).to.deep.equal({ country: 'FR', phone: '169454850' })
|
|
70
|
-
|
|
71
|
-
// UK (Jersey)
|
|
72
|
-
expect(parseNumber('+44 7700 300000')).to.deep.equal({ country: 'JE', phone: '7700300000' })
|
|
73
|
-
|
|
74
|
-
// KZ
|
|
75
|
-
expect(parseNumber('+7 702 211 1111')).to.deep.equal({ country: 'KZ', phone: '7022111111' })
|
|
76
|
-
|
|
77
|
-
// Brazil
|
|
78
|
-
expect(parseNumber('11987654321', 'BR')).to.deep.equal({ country: 'BR', phone: '11987654321' })
|
|
79
|
-
|
|
80
|
-
// Long country phone code.
|
|
81
|
-
expect(parseNumber('+212659777777')).to.deep.equal({ country: 'MA', phone: '659777777' })
|
|
82
|
-
|
|
83
|
-
// No country could be derived.
|
|
84
|
-
// parseNumber('+212569887076').should.deep.equal({ countryPhoneCode: '212', phone: '569887076' })
|
|
85
|
-
|
|
86
|
-
// GB. Moible numbers starting 07624* are Isle of Man.
|
|
87
|
-
expect(parseNumber('07624369230', 'GB')).to.deep.equal({ country: 'IM', phone: '7624369230' })
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it('should parse possible numbers', () => {
|
|
91
|
-
// Invalid phone number for a given country.
|
|
92
|
-
expect(parseNumber('1112223344', 'RU', { extended: true })).to.deep.equal({
|
|
93
|
-
country : 'RU',
|
|
94
|
-
countryCallingCode : '7',
|
|
95
|
-
phone : '1112223344',
|
|
96
|
-
carrierCode : undefined,
|
|
97
|
-
ext : undefined,
|
|
98
|
-
valid : false,
|
|
99
|
-
possible : true
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
// International phone number.
|
|
103
|
-
// Several countries with the same country phone code.
|
|
104
|
-
expect(parseNumber('+71112223344')).to.deep.equal({})
|
|
105
|
-
expect(parseNumber('+71112223344', { extended: true })).to.deep.equal({
|
|
106
|
-
country : undefined,
|
|
107
|
-
countryCallingCode : '7',
|
|
108
|
-
phone : '1112223344',
|
|
109
|
-
carrierCode : undefined,
|
|
110
|
-
ext : undefined,
|
|
111
|
-
valid : false,
|
|
112
|
-
possible : true
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
// International phone number.
|
|
116
|
-
// Single country with the given country phone code.
|
|
117
|
-
expect(parseNumber('+33011222333', { extended: true })).to.deep.equal({
|
|
118
|
-
country : 'FR',
|
|
119
|
-
countryCallingCode : '33',
|
|
120
|
-
phone : '011222333',
|
|
121
|
-
carrierCode : undefined,
|
|
122
|
-
ext : undefined,
|
|
123
|
-
valid : false,
|
|
124
|
-
possible : true
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
// Too short.
|
|
128
|
-
// Won't strip national prefix `8` because otherwise the number would be too short.
|
|
129
|
-
expect(parseNumber('+7 (800) 55-35-35', { extended: true })).to.deep.equal({
|
|
130
|
-
country : 'RU',
|
|
131
|
-
countryCallingCode : '7',
|
|
132
|
-
phone : '800553535',
|
|
133
|
-
carrierCode : undefined,
|
|
134
|
-
ext : undefined,
|
|
135
|
-
valid : false,
|
|
136
|
-
possible : false
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
// Too long.
|
|
140
|
-
expect(parseNumber('+1 213 37342530', { extended: true })).to.deep.equal({
|
|
141
|
-
country : undefined,
|
|
142
|
-
countryCallingCode : '1',
|
|
143
|
-
phone : '21337342530',
|
|
144
|
-
carrierCode : undefined,
|
|
145
|
-
ext : undefined,
|
|
146
|
-
valid : false,
|
|
147
|
-
possible : false
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
// No national number to be parsed.
|
|
151
|
-
expect(parseNumber('+996', { extended: true })).to.deep.equal({
|
|
152
|
-
// countryCallingCode : '996'
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
// Valid number.
|
|
156
|
-
expect(parseNumber('+78005553535', { extended: true })).to.deep.equal({
|
|
157
|
-
country : 'RU',
|
|
158
|
-
countryCallingCode : '7',
|
|
159
|
-
phone : '8005553535',
|
|
160
|
-
carrierCode : undefined,
|
|
161
|
-
ext : undefined,
|
|
162
|
-
valid : true,
|
|
163
|
-
possible : true
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/211
|
|
167
|
-
expect(parseNumber('+966', { extended: true })).to.deep.equal({})
|
|
168
|
-
expect(parseNumber('+9664', { extended: true })).to.deep.equal({})
|
|
169
|
-
expect(parseNumber('+96645', { extended: true })).to.deep.equal({
|
|
170
|
-
carrierCode : undefined,
|
|
171
|
-
phone : '45',
|
|
172
|
-
ext : undefined,
|
|
173
|
-
country : 'SA',
|
|
174
|
-
countryCallingCode : '966',
|
|
175
|
-
possible : false,
|
|
176
|
-
valid : false
|
|
177
|
-
})
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
it('should parse non-European digits', () => {
|
|
181
|
-
expect(parseNumber('+١٢١٢٢٣٢٣٢٣٢')).to.deep.equal({ country: 'US', phone: '2122323232' })
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
it('should work in edge cases', () => {
|
|
185
|
-
let thrower
|
|
186
|
-
|
|
187
|
-
// No input
|
|
188
|
-
expect(parseNumber('')).to.deep.equal({})
|
|
189
|
-
|
|
190
|
-
// No country phone code
|
|
191
|
-
expect(parseNumber('+')).to.deep.equal({})
|
|
192
|
-
|
|
193
|
-
// No country at all (non international number and no explicit country code)
|
|
194
|
-
expect(parseNumber('123')).to.deep.equal({})
|
|
195
|
-
|
|
196
|
-
// No country metadata for this `require` country code
|
|
197
|
-
thrower = () => parseNumber('123', 'ZZ')
|
|
198
|
-
expect(thrower).to.throw('Unknown country')
|
|
199
|
-
|
|
200
|
-
// No country metadata for this `default` country code
|
|
201
|
-
thrower = () => parseNumber('123', { defaultCountry: 'ZZ' })
|
|
202
|
-
expect(thrower).to.throw('Unknown country')
|
|
203
|
-
|
|
204
|
-
// Invalid country phone code
|
|
205
|
-
expect(parseNumber('+210')).to.deep.equal({})
|
|
206
|
-
|
|
207
|
-
// Invalid country phone code (extended parsing mode)
|
|
208
|
-
expect(parseNumber('+210', { extended: true })).to.deep.equal({})
|
|
209
|
-
|
|
210
|
-
// Too short of a number.
|
|
211
|
-
expect(parseNumber('1', 'US', { extended: true })).to.deep.equal({})
|
|
212
|
-
|
|
213
|
-
// Too long of a number.
|
|
214
|
-
expect(parseNumber('1111111111111111111', 'RU', { extended: true })).to.deep.equal({})
|
|
215
|
-
|
|
216
|
-
// Not a number.
|
|
217
|
-
expect(parseNumber('abcdefg', 'US', { extended: true })).to.deep.equal({})
|
|
218
|
-
|
|
219
|
-
// Country phone code beginning with a '0'
|
|
220
|
-
expect(parseNumber('+0123')).to.deep.equal({})
|
|
221
|
-
|
|
222
|
-
// Barbados NANPA phone number
|
|
223
|
-
expect(parseNumber('+12460000000')).to.deep.equal({ country: 'BB', phone: '2460000000' })
|
|
224
|
-
|
|
225
|
-
// // A case when country (restricted to) is not equal
|
|
226
|
-
// // to the one parsed out of an international number.
|
|
227
|
-
// parseNumber('+1-213-373-4253', 'RU').should.deep.equal({})
|
|
228
|
-
|
|
229
|
-
// National (significant) number too short
|
|
230
|
-
expect(parseNumber('2', 'US')).to.deep.equal({})
|
|
231
|
-
|
|
232
|
-
// National (significant) number too long
|
|
233
|
-
expect(parseNumber('222222222222222222', 'US')).to.deep.equal({})
|
|
234
|
-
|
|
235
|
-
// No `national_prefix_for_parsing`
|
|
236
|
-
expect(parseNumber('41111', 'AC')).to.deep.equal({ country: 'AC', phone: '41111'})
|
|
237
|
-
|
|
238
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/235
|
|
239
|
-
// `matchesEntirely()` bug fix.
|
|
240
|
-
expect(parseNumber('+4915784846111')).to.deep.equal({ country: 'DE', phone: '15784846111' })
|
|
241
|
-
|
|
242
|
-
// No metadata
|
|
243
|
-
thrower = () => _parseNumber('')
|
|
244
|
-
expect(thrower).to.throw('`metadata` argument not passed')
|
|
245
|
-
|
|
246
|
-
// // Numerical `value`
|
|
247
|
-
// thrower = () => parseNumber(2141111111, 'US')
|
|
248
|
-
// thrower.should.throw('A text for parsing must be a string.')
|
|
249
|
-
|
|
250
|
-
// Input string too long.
|
|
251
|
-
expect(
|
|
252
|
-
parseNumber('8005553535 ', 'RU')
|
|
253
|
-
).to.deep.equal({})
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
it('should parse phone number extensions', () => {
|
|
257
|
-
// "ext"
|
|
258
|
-
expect(parseNumber('2134567890 ext 123', 'US')).to.deep.equal({
|
|
259
|
-
country : 'US',
|
|
260
|
-
phone : '2134567890',
|
|
261
|
-
ext : '123'
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
// "ext."
|
|
265
|
-
expect(parseNumber('+12134567890 ext. 12345', 'US')).to.deep.equal({
|
|
266
|
-
country : 'US',
|
|
267
|
-
phone : '2134567890',
|
|
268
|
-
ext : '12345'
|
|
269
|
-
})
|
|
270
|
-
|
|
271
|
-
// "доб."
|
|
272
|
-
expect(parseNumber('+78005553535 доб. 1234', 'RU')).to.deep.equal({
|
|
273
|
-
country : 'RU',
|
|
274
|
-
phone : '8005553535',
|
|
275
|
-
ext : '1234'
|
|
276
|
-
})
|
|
277
|
-
|
|
278
|
-
// "#"
|
|
279
|
-
expect(parseNumber('+12134567890#1234')).to.deep.equal({
|
|
280
|
-
country : 'US',
|
|
281
|
-
phone : '2134567890',
|
|
282
|
-
ext : '1234'
|
|
283
|
-
})
|
|
284
|
-
|
|
285
|
-
// "x"
|
|
286
|
-
expect(parseNumber('+78005553535 x1234')).to.deep.equal({
|
|
287
|
-
country : 'RU',
|
|
288
|
-
phone : '8005553535',
|
|
289
|
-
ext : '1234'
|
|
290
|
-
})
|
|
291
|
-
|
|
292
|
-
// Not a valid extension
|
|
293
|
-
expect(parseNumber('2134567890 ext. abc', 'US')).to.deep.equal({
|
|
294
|
-
country : 'US',
|
|
295
|
-
phone : '2134567890'
|
|
296
|
-
})
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
it('should parse RFC 3966 phone numbers', () => {
|
|
300
|
-
expect(parseNumber('tel:+78005553535;ext=123')).to.deep.equal({
|
|
301
|
-
country : 'RU',
|
|
302
|
-
phone : '8005553535',
|
|
303
|
-
ext : '123'
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
// Should parse "visual separators".
|
|
307
|
-
expect(parseNumber('tel:+7(800)555-35.35;ext=123')).to.deep.equal({
|
|
308
|
-
country : 'RU',
|
|
309
|
-
phone : '8005553535',
|
|
310
|
-
ext : '123'
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
// Invalid number.
|
|
314
|
-
expect(parseNumber('tel:+7x8005553535;ext=123')).to.deep.equal({})
|
|
315
|
-
})
|
|
316
|
-
|
|
317
|
-
it('should parse invalid international numbers even if they are invalid', () => {
|
|
318
|
-
expect(parseNumber('+7(8)8005553535', 'RU')).to.deep.equal({
|
|
319
|
-
country : 'RU',
|
|
320
|
-
phone : '8005553535'
|
|
321
|
-
})
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
it('should parse carrier codes', () => {
|
|
325
|
-
expect(parseNumber('0 15 21 5555-5555', 'BR', { extended: true })).to.deep.equal({
|
|
326
|
-
country : 'BR',
|
|
327
|
-
countryCallingCode : '55',
|
|
328
|
-
phone : '2155555555',
|
|
329
|
-
carrierCode : '15',
|
|
330
|
-
ext : undefined,
|
|
331
|
-
valid : true,
|
|
332
|
-
possible : true
|
|
333
|
-
})
|
|
334
|
-
})
|
|
335
|
-
|
|
336
|
-
it('should parse IDD prefixes', () => {
|
|
337
|
-
expect(parseNumber('011 61 2 3456 7890', 'US')).to.deep.equal({
|
|
338
|
-
phone : '234567890',
|
|
339
|
-
country : 'AU'
|
|
340
|
-
})
|
|
341
|
-
|
|
342
|
-
expect(parseNumber('011 61 2 3456 7890', 'FR')).to.deep.equal({})
|
|
343
|
-
|
|
344
|
-
expect(parseNumber('00 61 2 3456 7890', 'US')).to.deep.equal({})
|
|
345
|
-
|
|
346
|
-
expect(parseNumber('810 61 2 3456 7890', 'RU')).to.deep.equal({
|
|
347
|
-
phone : '234567890',
|
|
348
|
-
country : 'AU'
|
|
349
|
-
})
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
it('should work with v2 API', () => {
|
|
353
|
-
parseNumber('+99989160151539')
|
|
354
|
-
})
|
|
355
|
-
|
|
356
|
-
it('should work with Argentina numbers', () => {
|
|
357
|
-
// The same mobile number is written differently
|
|
358
|
-
// in different formats in Argentina:
|
|
359
|
-
// `9` gets prepended in international format.
|
|
360
|
-
expect(parseNumber('+54 9 3435 55 1212')).to.deep.equal({
|
|
361
|
-
country: 'AR',
|
|
362
|
-
phone: '93435551212'
|
|
363
|
-
})
|
|
364
|
-
expect(parseNumber('0343 15-555-1212', 'AR')).to.deep.equal({
|
|
365
|
-
country: 'AR',
|
|
366
|
-
phone: '93435551212'
|
|
367
|
-
})
|
|
368
|
-
})
|
|
369
|
-
|
|
370
|
-
it('should work with Mexico numbers', () => {
|
|
371
|
-
// Fixed line.
|
|
372
|
-
expect(parseNumber('+52 449 978 0001')).to.deep.equal({
|
|
373
|
-
country: 'MX',
|
|
374
|
-
phone: '4499780001'
|
|
375
|
-
})
|
|
376
|
-
// "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
|
|
377
|
-
// no longer valid since August 2019."
|
|
378
|
-
//
|
|
379
|
-
// parseNumber('01 (449)978-0001', 'MX').should.deep.equal({
|
|
380
|
-
// country: 'MX',
|
|
381
|
-
// phone: '4499780001'
|
|
382
|
-
// })
|
|
383
|
-
expect(parseNumber('(449)978-0001', 'MX')).to.deep.equal({
|
|
384
|
-
country: 'MX',
|
|
385
|
-
phone: '4499780001'
|
|
386
|
-
})
|
|
387
|
-
// "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
|
|
388
|
-
// no longer valid since August 2019."
|
|
389
|
-
//
|
|
390
|
-
// // Mobile.
|
|
391
|
-
// // `1` is prepended before area code to mobile numbers in international format.
|
|
392
|
-
// parseNumber('+52 1 33 1234-5678', 'MX').should.deep.equal({
|
|
393
|
-
// country: 'MX',
|
|
394
|
-
// phone: '3312345678'
|
|
395
|
-
// })
|
|
396
|
-
expect(parseNumber('+52 33 1234-5678', 'MX')).to.deep.equal({
|
|
397
|
-
country: 'MX',
|
|
398
|
-
phone: '3312345678'
|
|
399
|
-
})
|
|
400
|
-
// "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
|
|
401
|
-
// no longer valid since August 2019."
|
|
402
|
-
//
|
|
403
|
-
// parseNumber('044 (33) 1234-5678', 'MX').should.deep.equal({
|
|
404
|
-
// country: 'MX',
|
|
405
|
-
// phone: '3312345678'
|
|
406
|
-
// })
|
|
407
|
-
// parseNumber('045 33 1234-5678', 'MX').should.deep.equal({
|
|
408
|
-
// country: 'MX',
|
|
409
|
-
// phone: '3312345678'
|
|
410
|
-
// })
|
|
411
|
-
})
|
|
412
|
-
|
|
413
|
-
it('should parse non-geographic numbering plan phone numbers', () => {
|
|
414
|
-
expect(parseNumber('+870773111632')).to.deep.equal(USE_NON_GEOGRAPHIC_COUNTRY_CODE ?
|
|
415
|
-
{
|
|
416
|
-
country: '001',
|
|
417
|
-
phone: '773111632'
|
|
418
|
-
} :
|
|
419
|
-
{})
|
|
420
|
-
})
|
|
421
|
-
|
|
422
|
-
it('should parse non-geographic numbering plan phone numbers (default country code)', () => {
|
|
423
|
-
expect(parseNumber('773111632', { defaultCallingCode: '870' })).to.deep.equal(USE_NON_GEOGRAPHIC_COUNTRY_CODE ?
|
|
424
|
-
{
|
|
425
|
-
country: '001',
|
|
426
|
-
phone: '773111632'
|
|
427
|
-
} :
|
|
428
|
-
{})
|
|
429
|
-
})
|
|
430
|
-
|
|
431
|
-
it('should parse non-geographic numbering plan phone numbers (extended)', () => {
|
|
432
|
-
expect(parseNumber('+870773111632', { extended: true })).to.deep.equal({
|
|
433
|
-
country: USE_NON_GEOGRAPHIC_COUNTRY_CODE ? '001' : undefined,
|
|
434
|
-
countryCallingCode: '870',
|
|
435
|
-
phone: '773111632',
|
|
436
|
-
carrierCode: undefined,
|
|
437
|
-
ext: undefined,
|
|
438
|
-
possible: true,
|
|
439
|
-
valid: true
|
|
440
|
-
})
|
|
441
|
-
})
|
|
442
|
-
|
|
443
|
-
it('should parse non-geographic numbering plan phone numbers (default country code) (extended)', () => {
|
|
444
|
-
expect(parseNumber('773111632', { defaultCallingCode: '870', extended: true })).to.deep.equal({
|
|
445
|
-
country: USE_NON_GEOGRAPHIC_COUNTRY_CODE ? '001' : undefined,
|
|
446
|
-
countryCallingCode: '870',
|
|
447
|
-
phone: '773111632',
|
|
448
|
-
carrierCode: undefined,
|
|
449
|
-
ext: undefined,
|
|
450
|
-
possible: true,
|
|
451
|
-
valid: true
|
|
452
|
-
})
|
|
453
|
-
})
|
|
454
|
-
|
|
455
|
-
it('shouldn\'t crash when invalid `defaultCallingCode` is passed', () => {
|
|
456
|
-
expect(() => parseNumber('773111632', { defaultCallingCode: '999' })).to.throw('Unknown calling code')
|
|
457
|
-
})
|
|
458
|
-
|
|
459
|
-
it('shouldn\'t set `country` when there\'s no `defaultCountry` and `defaultCallingCode` is not of a "non-geographic entity"', () => {
|
|
460
|
-
expect(parseNumber('88005553535', { defaultCallingCode: '7' })).to.deep.equal({
|
|
461
|
-
country: 'RU',
|
|
462
|
-
phone: '8005553535'
|
|
463
|
-
})
|
|
464
|
-
})
|
|
465
|
-
|
|
466
|
-
it('should correctly parse numbers starting with the same digit as the national prefix', () => {
|
|
467
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/373
|
|
468
|
-
// `BY`'s `national_prefix` is `8`.
|
|
469
|
-
expect(parseNumber('+37582004910060')).to.deep.equal({
|
|
470
|
-
country: 'BY',
|
|
471
|
-
phone: '82004910060'
|
|
472
|
-
});
|
|
473
|
-
})
|
|
474
|
-
|
|
475
|
-
it('should autocorrect numbers without a leading +', () => {
|
|
476
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/376
|
|
477
|
-
expect(parseNumber('375447521111', 'BY')).to.deep.equal({
|
|
478
|
-
country: 'BY',
|
|
479
|
-
phone: '447521111'
|
|
480
|
-
});
|
|
481
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/316
|
|
482
|
-
expect(parseNumber('33612902554', 'FR')).to.deep.equal({
|
|
483
|
-
country: 'FR',
|
|
484
|
-
phone: '612902554'
|
|
485
|
-
});
|
|
486
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/375
|
|
487
|
-
expect(parseNumber('61438331999', 'AU')).to.deep.equal({
|
|
488
|
-
country: 'AU',
|
|
489
|
-
phone: '438331999'
|
|
490
|
-
});
|
|
491
|
-
// A case when `49` is a country calling code of a number without a leading `+`.
|
|
492
|
-
expect(parseNumber('4930123456', 'DE')).to.deep.equal({
|
|
493
|
-
country: 'DE',
|
|
494
|
-
phone: '30123456'
|
|
495
|
-
});
|
|
496
|
-
// A case when `49` is a valid area code.
|
|
497
|
-
expect(parseNumber('4951234567890', 'DE')).to.deep.equal({
|
|
498
|
-
country: 'DE',
|
|
499
|
-
phone: '4951234567890'
|
|
500
|
-
});
|
|
501
|
-
})
|
|
502
|
-
|
|
503
|
-
it('should parse extensions (long extensions with explicitl abels)', () => {
|
|
504
|
-
// Test lower and upper limits of extension lengths for each type of label.
|
|
505
|
-
|
|
506
|
-
// Firstly, when in RFC format: PhoneNumberUtil.extLimitAfterExplicitLabel
|
|
507
|
-
expect(parseNumber('33316005 ext 0', 'NZ').ext).to.equal('0')
|
|
508
|
-
expect(parseNumber('33316005 ext 01234567890123456789', 'NZ').ext).to.equal('01234567890123456789')
|
|
509
|
-
// Extension too long.
|
|
510
|
-
expect(parseNumber('33316005 ext 012345678901234567890', 'NZ').ext).to.be.undefined
|
|
511
|
-
|
|
512
|
-
// Explicit extension label.
|
|
513
|
-
expect(parseNumber('03 3316005ext:1', 'NZ').ext).to.equal('1')
|
|
514
|
-
expect(parseNumber('03 3316005 xtn:12345678901234567890', 'NZ').ext).to.equal('12345678901234567890')
|
|
515
|
-
expect(parseNumber('03 3316005 extension\t12345678901234567890', 'NZ').ext).to.equal('12345678901234567890')
|
|
516
|
-
expect(parseNumber('03 3316005 xtensio:12345678901234567890', 'NZ').ext).to.equal('12345678901234567890')
|
|
517
|
-
expect(parseNumber('03 3316005 xtensión, 12345678901234567890#', 'NZ').ext).to.equal('12345678901234567890')
|
|
518
|
-
expect(parseNumber('03 3316005extension.12345678901234567890', 'NZ').ext).to.equal('12345678901234567890')
|
|
519
|
-
expect(parseNumber('03 3316005 доб:12345678901234567890', 'NZ').ext).to.equal('12345678901234567890')
|
|
520
|
-
|
|
521
|
-
// Extension too long.
|
|
522
|
-
expect(parseNumber('03 3316005 extension 123456789012345678901', 'NZ').ext).to.be.undefined
|
|
523
|
-
})
|
|
524
|
-
|
|
525
|
-
it('should parse extensions (long extensions with auto dialling labels)', () => {
|
|
526
|
-
expect(parseNumber('+12679000000,,123456789012345#').ext).to.equal('123456789012345')
|
|
527
|
-
expect(parseNumber('+12679000000;123456789012345#').ext).to.equal('123456789012345')
|
|
528
|
-
expect(parseNumber('+442034000000,,123456789#').ext).to.equal('123456789')
|
|
529
|
-
// Extension too long.
|
|
530
|
-
expect(parseNumber('+12679000000,,1234567890123456#').ext).to.be.undefined
|
|
531
|
-
})
|
|
532
|
-
|
|
533
|
-
it('should parse extensions (short extensions with ambiguous characters)', () => {
|
|
534
|
-
expect(parseNumber('03 3316005 x 123456789', 'NZ').ext).to.equal('123456789')
|
|
535
|
-
expect(parseNumber('03 3316005 x. 123456789', 'NZ').ext).to.equal('123456789')
|
|
536
|
-
expect(parseNumber('03 3316005 #123456789#', 'NZ').ext).to.equal('123456789')
|
|
537
|
-
expect(parseNumber('03 3316005 ~ 123456789', 'NZ').ext).to.equal('123456789')
|
|
538
|
-
// Extension too long.
|
|
539
|
-
expect(parseNumber('03 3316005 ~ 1234567890', 'NZ').ext).to.be.undefined
|
|
540
|
-
})
|
|
541
|
-
|
|
542
|
-
it('should parse extensions (short extensions when not sure of label)', () => {
|
|
543
|
-
expect(parseNumber('+1123-456-7890 666666#', { v2: true }).ext).to.equal('666666')
|
|
544
|
-
expect(parseNumber('+11234567890-6#', { v2: true }).ext).to.equal('6')
|
|
545
|
-
// Extension too long.
|
|
546
|
-
expect(() => parseNumber('+1123-456-7890 7777777#', { v2: true })).to.throw('NOT_A_NUMBER')
|
|
547
|
-
})
|
|
548
|
-
|
|
549
|
-
it('should not choose `defaultCountry` over the "main" one when both the `defaultCountry` and the "main" one match the phone number', function() {
|
|
550
|
-
// This phone number matches both US and CA because they have the same
|
|
551
|
-
// regular expression for some weird reason.
|
|
552
|
-
// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/103
|
|
553
|
-
const phoneNumber = parseNumber('8004001000', { defaultCountry: 'CA', v2: true })
|
|
554
|
-
expect(phoneNumber.country).not.to.equal('CA')
|
|
555
|
-
expect(phoneNumber.country).to.equal('US')
|
|
556
|
-
|
|
557
|
-
// This phone number is specific to CA.
|
|
558
|
-
const phoneNumber2 = parseNumber('4389999999', { defaultCountry: 'US', v2: true })
|
|
559
|
-
expect(phoneNumber2.country).to.equal('CA')
|
|
560
|
-
})
|
|
561
|
-
})
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import parseIncompletePhoneNumber, { parsePhoneNumberCharacter } from './parseIncompletePhoneNumber.js'
|
|
5
|
-
|
|
6
|
-
describe('parseIncompletePhoneNumber', () => {
|
|
7
|
-
it('should fix `for ... of` loop coverage', () => {
|
|
8
|
-
// For some weird reason, "istanbul" doesn't know how to properly cover
|
|
9
|
-
// a `for ... of` loop that has been transpiled with Babel.
|
|
10
|
-
// For some reason, it attempts to cover the `for ... of` polyfill coode too,
|
|
11
|
-
// meaning that it complains if that polyfill's edge case is not covered.
|
|
12
|
-
// This test case works around that weird bug by covering that edge case of the polyfill.
|
|
13
|
-
//
|
|
14
|
-
// When it runs `npm test` command, it does so without `babel` transpilation,
|
|
15
|
-
// so the error is gonna be "string.split is not a function or its return value is not iterable".
|
|
16
|
-
//
|
|
17
|
-
// When it runs `npm run test-coverage` command, it does so with `babel` transpilation,
|
|
18
|
-
// so the error is gonna be "Invalid attempt to iterate non-iterable instance.".
|
|
19
|
-
//
|
|
20
|
-
expect(() => {
|
|
21
|
-
parseIncompletePhoneNumber({
|
|
22
|
-
split: () => 123
|
|
23
|
-
})
|
|
24
|
-
}).to.throw(/(not iterable|non-iterable)/)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('should parse phone number character', () => {
|
|
28
|
-
// Accepts leading `+`.
|
|
29
|
-
expect(parsePhoneNumberCharacter('+')).to.equal('+')
|
|
30
|
-
|
|
31
|
-
// Doesn't accept non-leading `+`.
|
|
32
|
-
expect(parsePhoneNumberCharacter('+', '+')).to.be.undefined
|
|
33
|
-
|
|
34
|
-
// Parses digits.
|
|
35
|
-
expect(parsePhoneNumberCharacter('1')).to.equal('1')
|
|
36
|
-
|
|
37
|
-
// Parses non-European digits.
|
|
38
|
-
expect(parsePhoneNumberCharacter('٤')).to.equal('4')
|
|
39
|
-
|
|
40
|
-
// Dismisses other characters.
|
|
41
|
-
expect(parsePhoneNumberCharacter('-')).to.be.undefined
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('should parse incomplete phone number', () => {
|
|
45
|
-
expect(parseIncompletePhoneNumber('')).to.equal('')
|
|
46
|
-
|
|
47
|
-
// Doesn't accept non-leading `+`.
|
|
48
|
-
expect(parseIncompletePhoneNumber('++')).to.equal('+')
|
|
49
|
-
|
|
50
|
-
// Accepts leading `+`.
|
|
51
|
-
expect(parseIncompletePhoneNumber('+7 800 555')).to.equal('+7800555')
|
|
52
|
-
|
|
53
|
-
// Parses digits.
|
|
54
|
-
expect(parseIncompletePhoneNumber('8 (800) 555')).to.equal('8800555')
|
|
55
|
-
|
|
56
|
-
// Parses non-European digits.
|
|
57
|
-
expect(parseIncompletePhoneNumber('+٤٤٢٣٢٣٢٣٤')).to.equal('+442323234')
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('should work with a new `context` argument in `parsePhoneNumberCharacter()` function (international number)', () => {
|
|
61
|
-
let stopped = false
|
|
62
|
-
|
|
63
|
-
const emit = (event) => {
|
|
64
|
-
switch (event) {
|
|
65
|
-
case 'end':
|
|
66
|
-
stopped = true
|
|
67
|
-
break
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
expect(parsePhoneNumberCharacter('+', undefined, emit)).to.equal('+')
|
|
72
|
-
expect(stopped).to.equal(false)
|
|
73
|
-
|
|
74
|
-
expect(parsePhoneNumberCharacter('1', '+', emit)).to.equal('1')
|
|
75
|
-
expect(stopped).to.equal(false)
|
|
76
|
-
|
|
77
|
-
expect(parsePhoneNumberCharacter('+', '+1', emit)).to.be.undefined
|
|
78
|
-
expect(stopped).to.equal(true)
|
|
79
|
-
|
|
80
|
-
expect(parsePhoneNumberCharacter('2', '+1', emit)).to.equal('2')
|
|
81
|
-
expect(stopped).to.equal(true)
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('should work with a new `context` argument in `parsePhoneNumberCharacter()` function (national number)', () => {
|
|
85
|
-
let stopped = false
|
|
86
|
-
|
|
87
|
-
const emit = (event) => {
|
|
88
|
-
switch (event) {
|
|
89
|
-
case 'end':
|
|
90
|
-
stopped = true
|
|
91
|
-
break
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
expect(parsePhoneNumberCharacter('2', undefined, emit)).to.equal('2')
|
|
96
|
-
expect(stopped).to.equal(false)
|
|
97
|
-
|
|
98
|
-
expect(parsePhoneNumberCharacter('+', '2', emit)).to.be.undefined
|
|
99
|
-
expect(stopped).to.equal(true)
|
|
100
|
-
|
|
101
|
-
expect(parsePhoneNumberCharacter('1', '2', emit)).to.equal('1')
|
|
102
|
-
expect(stopped).to.equal(true)
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('should call `eventListener` when the input ends abruptly', () => {
|
|
106
|
-
let parsingEnded = false
|
|
107
|
-
const eventListener = (event) => {
|
|
108
|
-
parsingEnded = true;
|
|
109
|
-
if (event !== 'end') {
|
|
110
|
-
throw new Error(`Unexpected event: ${event}`)
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Doesn't accept non-leading `+`.
|
|
115
|
-
expect(parsePhoneNumberCharacter('+', '+123', eventListener)).to.be.undefined
|
|
116
|
-
expect(parsingEnded).to.equal(true)
|
|
117
|
-
})
|
|
118
|
-
})
|