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,252 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
// This is a legacy function.
|
|
5
|
-
// Use `findNumbers()` instead.
|
|
6
|
-
|
|
7
|
-
import findNumbers, { searchPhoneNumbers } from './findPhoneNumbers.js'
|
|
8
|
-
import PhoneNumberSearch from './PhoneNumberSearch.js'
|
|
9
|
-
import metadata from '../../metadata.min.json' with { type: 'json' }
|
|
10
|
-
|
|
11
|
-
describe('findPhoneNumbers', () => {
|
|
12
|
-
it('should find numbers', () => {
|
|
13
|
-
expect(findNumbers('2133734253', 'US', metadata)).to.deep.equal([{
|
|
14
|
-
phone : '2133734253',
|
|
15
|
-
country : 'US',
|
|
16
|
-
startsAt : 0,
|
|
17
|
-
endsAt : 10
|
|
18
|
-
}])
|
|
19
|
-
|
|
20
|
-
expect(findNumbers('(213) 373-4253', 'US', metadata)).to.deep.equal([{
|
|
21
|
-
phone : '2133734253',
|
|
22
|
-
country : 'US',
|
|
23
|
-
startsAt : 0,
|
|
24
|
-
endsAt : 14
|
|
25
|
-
}])
|
|
26
|
-
|
|
27
|
-
expect(
|
|
28
|
-
findNumbers('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', metadata)
|
|
29
|
-
).to.deep.equal([{
|
|
30
|
-
phone : '8005553535',
|
|
31
|
-
country : 'RU',
|
|
32
|
-
startsAt : 14,
|
|
33
|
-
endsAt : 32
|
|
34
|
-
}, {
|
|
35
|
-
phone : '2133734253',
|
|
36
|
-
country : 'US',
|
|
37
|
-
startsAt : 41,
|
|
38
|
-
endsAt : 55
|
|
39
|
-
}])
|
|
40
|
-
|
|
41
|
-
// Opening parenthesis issue.
|
|
42
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/252
|
|
43
|
-
expect(
|
|
44
|
-
findNumbers('The number is +7 (800) 555-35-35 and not (213) 373-4253 (that\'s not even in the same country!) as written in the document.', 'US', metadata)
|
|
45
|
-
).to.deep.equal([{
|
|
46
|
-
phone : '8005553535',
|
|
47
|
-
country : 'RU',
|
|
48
|
-
startsAt : 14,
|
|
49
|
-
endsAt : 32
|
|
50
|
-
}, {
|
|
51
|
-
phone : '2133734253',
|
|
52
|
-
country : 'US',
|
|
53
|
-
startsAt : 41,
|
|
54
|
-
endsAt : 55
|
|
55
|
-
}])
|
|
56
|
-
|
|
57
|
-
// No default country.
|
|
58
|
-
expect(
|
|
59
|
-
findNumbers('The number is +7 (800) 555-35-35 as written in the document.', metadata)
|
|
60
|
-
).to.deep.equal([{
|
|
61
|
-
phone : '8005553535',
|
|
62
|
-
country : 'RU',
|
|
63
|
-
startsAt : 14,
|
|
64
|
-
endsAt : 32
|
|
65
|
-
}])
|
|
66
|
-
|
|
67
|
-
// Passing `options` and default country.
|
|
68
|
-
expect(
|
|
69
|
-
findNumbers('The number is +7 (800) 555-35-35 as written in the document.', 'US', { leniency: 'VALID' }, metadata)
|
|
70
|
-
).to.deep.equal([{
|
|
71
|
-
phone : '8005553535',
|
|
72
|
-
country : 'RU',
|
|
73
|
-
startsAt : 14,
|
|
74
|
-
endsAt : 32
|
|
75
|
-
}])
|
|
76
|
-
|
|
77
|
-
// Passing `options`.
|
|
78
|
-
expect(
|
|
79
|
-
findNumbers('The number is +7 (800) 555-35-35 as written in the document.', { leniency: 'VALID' }, metadata)
|
|
80
|
-
).to.deep.equal([{
|
|
81
|
-
phone : '8005553535',
|
|
82
|
-
country : 'RU',
|
|
83
|
-
startsAt : 14,
|
|
84
|
-
endsAt : 32
|
|
85
|
-
}])
|
|
86
|
-
|
|
87
|
-
// Not a phone number and a phone number.
|
|
88
|
-
expect(
|
|
89
|
-
findNumbers('Digits 12 are not a number, but +7 (800) 555-35-35 is.', { leniency: 'VALID' }, metadata)
|
|
90
|
-
).to.deep.equal([{
|
|
91
|
-
phone : '8005553535',
|
|
92
|
-
country : 'RU',
|
|
93
|
-
startsAt : 32,
|
|
94
|
-
endsAt : 50
|
|
95
|
-
}])
|
|
96
|
-
|
|
97
|
-
// Phone number extension.
|
|
98
|
-
expect(
|
|
99
|
-
findNumbers('Date 02/17/2018 is not a number, but +7 (800) 555-35-35 ext. 123 is.', { leniency: 'VALID' }, metadata)
|
|
100
|
-
).to.deep.equal([{
|
|
101
|
-
phone : '8005553535',
|
|
102
|
-
country : 'RU',
|
|
103
|
-
ext : '123',
|
|
104
|
-
startsAt : 37,
|
|
105
|
-
endsAt : 64
|
|
106
|
-
}])
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('shouldn\'t find non-valid numbers', () => {
|
|
110
|
-
// Not a valid phone number for US.
|
|
111
|
-
expect(findNumbers('1111111111', 'US', metadata)).to.deep.equal([])
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
it('should find non-European digits', () => {
|
|
115
|
-
// E.g. in Iraq they don't write `+442323234` but rather `+٤٤٢٣٢٣٢٣٤`.
|
|
116
|
-
expect(findNumbers('العَرَبِيَّة +٤٤٣٣٣٣٣٣٣٣٣٣عَرَبِيّ', metadata)).to.deep.equal([{
|
|
117
|
-
country : 'GB',
|
|
118
|
-
phone : '3333333333',
|
|
119
|
-
startsAt : 14,
|
|
120
|
-
endsAt : 27
|
|
121
|
-
}])
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
it('should iterate', () => {
|
|
125
|
-
const expected_numbers = [{
|
|
126
|
-
country : 'RU',
|
|
127
|
-
phone : '8005553535',
|
|
128
|
-
// number : '+7 (800) 555-35-35',
|
|
129
|
-
startsAt : 14,
|
|
130
|
-
endsAt : 32
|
|
131
|
-
}, {
|
|
132
|
-
country : 'US',
|
|
133
|
-
phone : '2133734253',
|
|
134
|
-
// number : '(213) 373-4253',
|
|
135
|
-
startsAt : 41,
|
|
136
|
-
endsAt : 55
|
|
137
|
-
}]
|
|
138
|
-
|
|
139
|
-
for (const number of searchPhoneNumbers('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', metadata)) {
|
|
140
|
-
expect(number).to.deep.equal(expected_numbers.shift())
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
expect(expected_numbers.length).to.equal(0)
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
it('should work in edge cases', () => {
|
|
147
|
-
let thrower
|
|
148
|
-
|
|
149
|
-
// No input
|
|
150
|
-
expect(findNumbers('', metadata)).to.deep.equal([])
|
|
151
|
-
|
|
152
|
-
// No country metadata for this `require` country code
|
|
153
|
-
thrower = () => findNumbers('123', 'ZZ', metadata)
|
|
154
|
-
expect(thrower).to.throw('Unknown country')
|
|
155
|
-
|
|
156
|
-
// Numerical `value`
|
|
157
|
-
thrower = () => findNumbers(2141111111, 'US')
|
|
158
|
-
expect(thrower).to.throw('A text for parsing must be a string.')
|
|
159
|
-
|
|
160
|
-
// // No metadata
|
|
161
|
-
// thrower = () => findNumbers('')
|
|
162
|
-
// thrower.should.throw('`metadata` argument not passed')
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
it('shouldn\'t find phone numbers which are not phone numbers', () => {
|
|
166
|
-
// A timestamp.
|
|
167
|
-
expect(findNumbers('2012-01-02 08:00', 'US', metadata)).to.deep.equal([])
|
|
168
|
-
|
|
169
|
-
// A valid number (not a complete timestamp).
|
|
170
|
-
expect(findNumbers('2012-01-02 08', 'US', metadata)).to.deep.equal([{
|
|
171
|
-
country : 'US',
|
|
172
|
-
phone : '2012010208',
|
|
173
|
-
startsAt : 0,
|
|
174
|
-
endsAt : 13
|
|
175
|
-
}])
|
|
176
|
-
|
|
177
|
-
// Invalid parens.
|
|
178
|
-
expect(findNumbers('213(3734253', 'US', metadata)).to.deep.equal([])
|
|
179
|
-
|
|
180
|
-
// Letters after phone number.
|
|
181
|
-
expect(findNumbers('2133734253a', 'US', metadata)).to.deep.equal([])
|
|
182
|
-
|
|
183
|
-
// Valid phone (same as the one found in the UUID below).
|
|
184
|
-
expect(findNumbers('The phone number is 231354125.', 'FR', metadata)).to.deep.equal([{
|
|
185
|
-
country : 'FR',
|
|
186
|
-
phone : '231354125',
|
|
187
|
-
startsAt : 20,
|
|
188
|
-
endsAt : 29
|
|
189
|
-
}])
|
|
190
|
-
|
|
191
|
-
// Not a phone number (part of a UUID).
|
|
192
|
-
// Should parse in `{ extended: true }` mode.
|
|
193
|
-
const possibleNumbers = findNumbers('The UUID is CA801c26f98cd16e231354125ad046e40b.', 'FR', { extended: true }, metadata)
|
|
194
|
-
expect(possibleNumbers.length).to.equal(3)
|
|
195
|
-
expect(possibleNumbers[1].country).to.equal('FR')
|
|
196
|
-
expect(possibleNumbers[1].phone).to.equal('231354125')
|
|
197
|
-
|
|
198
|
-
// Not a phone number (part of a UUID).
|
|
199
|
-
// Shouldn't parse by default.
|
|
200
|
-
expect(
|
|
201
|
-
findNumbers('The UUID is CA801c26f98cd16e231354125ad046e40b.', 'FR', metadata)
|
|
202
|
-
).to.deep.equal([])
|
|
203
|
-
})
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
describe('PhoneNumberSearch', () => {
|
|
207
|
-
it('should search for phone numbers', () => {
|
|
208
|
-
const finder = new PhoneNumberSearch('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', { defaultCountry: 'US' }, metadata)
|
|
209
|
-
|
|
210
|
-
expect(finder.hasNext()).to.equal(true)
|
|
211
|
-
expect(finder.next()).to.deep.equal({
|
|
212
|
-
country : 'RU',
|
|
213
|
-
phone : '8005553535',
|
|
214
|
-
// number : '+7 (800) 555-35-35',
|
|
215
|
-
startsAt : 14,
|
|
216
|
-
endsAt : 32
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
expect(finder.hasNext()).to.equal(true)
|
|
220
|
-
expect(finder.next()).to.deep.equal({
|
|
221
|
-
country : 'US',
|
|
222
|
-
phone : '2133734253',
|
|
223
|
-
// number : '(213) 373-4253',
|
|
224
|
-
startsAt : 41,
|
|
225
|
-
endsAt : 55
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
expect(finder.hasNext()).to.equal(false)
|
|
229
|
-
})
|
|
230
|
-
|
|
231
|
-
it('should search for phone numbers (no options)', () => {
|
|
232
|
-
const finder = new PhoneNumberSearch('The number is +7 (800) 555-35-35', undefined, metadata)
|
|
233
|
-
expect(finder.hasNext()).to.equal(true)
|
|
234
|
-
expect(finder.next()).to.deep.equal({
|
|
235
|
-
country : 'RU',
|
|
236
|
-
phone : '8005553535',
|
|
237
|
-
// number : '+7 (800) 555-35-35',
|
|
238
|
-
startsAt : 14,
|
|
239
|
-
endsAt : 32
|
|
240
|
-
})
|
|
241
|
-
expect(finder.hasNext()).to.equal(false)
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
it('should work in edge cases', () => {
|
|
245
|
-
// No options
|
|
246
|
-
const search = new PhoneNumberSearch('', undefined, metadata)
|
|
247
|
-
|
|
248
|
-
// No next element
|
|
249
|
-
let thrower = () => search.next()
|
|
250
|
-
expect(thrower).to.throw('No next element')
|
|
251
|
-
})
|
|
252
|
-
})
|
|
@@ -1,246 +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
|
-
|
|
7
|
-
function formatNumber(...parameters) {
|
|
8
|
-
parameters.push(metadata)
|
|
9
|
-
return _formatNumber.apply(this, parameters)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
describe('format', () => {
|
|
13
|
-
it('should work with the first argument being a E.164 number', () => {
|
|
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
|
-
|
|
25
|
-
it('should work with the first object argument expanded', () => {
|
|
26
|
-
expect(formatNumber('2133734253', 'US', 'NATIONAL')).to.equal('(213) 373-4253')
|
|
27
|
-
expect(formatNumber('2133734253', 'US', 'INTERNATIONAL')).to.equal('+1 213 373 4253')
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('should support legacy "National" / "International" formats', () => {
|
|
31
|
-
expect(formatNumber('2133734253', 'US', 'National')).to.equal('(213) 373-4253')
|
|
32
|
-
expect(formatNumber('2133734253', 'US', 'International')).to.equal('+1 213 373 4253')
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('should format using formats with no leading digits (`format.leadingDigitsPatterns().length === 0`)', () => {
|
|
36
|
-
expect(
|
|
37
|
-
formatNumber({ phone: '12345678901', countryCallingCode: 888 }, 'INTERNATIONAL')
|
|
38
|
-
).to.equal('+888 123 456 78901')
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('should sort out the arguments', () => {
|
|
42
|
-
const options = {
|
|
43
|
-
formatExtension: (number, extension) => `${number} доб. ${extension}`
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
expect(formatNumber({
|
|
47
|
-
phone : '8005553535',
|
|
48
|
-
country : 'RU',
|
|
49
|
-
ext : '123'
|
|
50
|
-
},
|
|
51
|
-
'NATIONAL', options)).to.equal('8 (800) 555-35-35 доб. 123')
|
|
52
|
-
|
|
53
|
-
// Parse number from string.
|
|
54
|
-
expect(formatNumber('+78005553535', 'NATIONAL', options)).to.equal('8 (800) 555-35-35')
|
|
55
|
-
expect(formatNumber('8005553535', 'RU', 'NATIONAL', options)).to.equal('8 (800) 555-35-35')
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('should format with national prefix when specifically instructed', () => {
|
|
59
|
-
// With national prefix.
|
|
60
|
-
expect(formatNumber('88005553535', 'RU', 'NATIONAL')).to.equal('8 (800) 555-35-35')
|
|
61
|
-
// Without national prefix via an explicitly set option.
|
|
62
|
-
expect(formatNumber('88005553535', 'RU', 'NATIONAL', { nationalPrefix: false })).to.equal('800 555-35-35')
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
it('should format valid phone numbers', () => {
|
|
66
|
-
// Switzerland
|
|
67
|
-
expect(formatNumber({ country: 'CH', phone: '446681800' }, 'INTERNATIONAL')).to.equal('+41 44 668 18 00')
|
|
68
|
-
expect(formatNumber({ country: 'CH', phone: '446681800' }, 'E.164')).to.equal('+41446681800')
|
|
69
|
-
expect(formatNumber({ country: 'CH', phone: '446681800' }, 'RFC3966')).to.equal('tel:+41446681800')
|
|
70
|
-
expect(formatNumber({ country: 'CH', phone: '446681800' }, 'NATIONAL')).to.equal('044 668 18 00')
|
|
71
|
-
|
|
72
|
-
// France
|
|
73
|
-
expect(formatNumber({ country: 'FR', phone: '169454850' }, 'NATIONAL')).to.equal('01 69 45 48 50')
|
|
74
|
-
|
|
75
|
-
// Kazakhstan
|
|
76
|
-
expect(formatNumber('+7 702 211 1111', 'NATIONAL')).to.equal('8 (702) 211 1111')
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('should format national numbers with national prefix even if it\'s optional', () => {
|
|
80
|
-
// Russia
|
|
81
|
-
expect(formatNumber({ country: 'RU', phone: '9991234567' }, 'NATIONAL')).to.equal('8 (999) 123-45-67')
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('should work in edge cases', () => {
|
|
85
|
-
let thrower
|
|
86
|
-
|
|
87
|
-
// No phone number
|
|
88
|
-
expect(formatNumber('', 'RU', 'INTERNATIONAL')).to.equal('')
|
|
89
|
-
expect(formatNumber('', 'RU', 'NATIONAL')).to.equal('')
|
|
90
|
-
|
|
91
|
-
expect(formatNumber({ country: 'RU', phone: '' }, 'INTERNATIONAL')).to.equal('+7')
|
|
92
|
-
expect(formatNumber({ country: 'RU', phone: '' }, 'NATIONAL')).to.equal('')
|
|
93
|
-
|
|
94
|
-
// No suitable format
|
|
95
|
-
expect(formatNumber('+121337342530', 'US', 'NATIONAL')).to.equal('21337342530')
|
|
96
|
-
// No suitable format (leading digits mismatch)
|
|
97
|
-
expect(formatNumber('28199999', 'AD', 'NATIONAL')).to.equal('28199999')
|
|
98
|
-
|
|
99
|
-
// Numerical `value`
|
|
100
|
-
thrower = () => formatNumber(89150000000, 'RU', 'NATIONAL')
|
|
101
|
-
expect(thrower).to.throw(
|
|
102
|
-
'A phone number must either be a string or an object of shape { phone, [country] }.'
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
// No metadata for country
|
|
106
|
-
expect(() => formatNumber('+121337342530', 'USA', 'NATIONAL')).to.throw('Unknown country')
|
|
107
|
-
expect(() => formatNumber('21337342530', 'USA', 'NATIONAL')).to.throw('Unknown country')
|
|
108
|
-
|
|
109
|
-
// No format type
|
|
110
|
-
thrower = () => formatNumber('+123')
|
|
111
|
-
expect(thrower).to.throw('`format` argument not passed')
|
|
112
|
-
|
|
113
|
-
// Unknown format type
|
|
114
|
-
thrower = () => formatNumber('123', 'US', 'Gay')
|
|
115
|
-
expect(thrower).to.throw('Unknown "format" argument')
|
|
116
|
-
|
|
117
|
-
// No metadata
|
|
118
|
-
thrower = () => _formatNumber('123', 'US', 'E.164')
|
|
119
|
-
expect(thrower).to.throw('`metadata`')
|
|
120
|
-
|
|
121
|
-
// No formats
|
|
122
|
-
expect(formatNumber('012345', 'AC', 'NATIONAL')).to.equal('012345')
|
|
123
|
-
|
|
124
|
-
// No `fromCountry` for `IDD` format.
|
|
125
|
-
expect(formatNumber('+78005553535', 'IDD')).to.be.undefined
|
|
126
|
-
|
|
127
|
-
// `fromCountry` has no default IDD prefix.
|
|
128
|
-
expect(formatNumber('+78005553535', 'IDD', { fromCountry: 'BO' })).to.be.undefined
|
|
129
|
-
|
|
130
|
-
// No such country.
|
|
131
|
-
expect(() => formatNumber({ phone: '123', country: 'USA' }, 'NATIONAL')).to.throw('Unknown country')
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it('should format phone number extensions', () => {
|
|
135
|
-
// National
|
|
136
|
-
expect(formatNumber({
|
|
137
|
-
country: 'US',
|
|
138
|
-
phone: '2133734253',
|
|
139
|
-
ext: '123'
|
|
140
|
-
},
|
|
141
|
-
'NATIONAL')).to.equal('(213) 373-4253 ext. 123')
|
|
142
|
-
|
|
143
|
-
// International
|
|
144
|
-
expect(formatNumber({
|
|
145
|
-
country : 'US',
|
|
146
|
-
phone : '2133734253',
|
|
147
|
-
ext : '123'
|
|
148
|
-
},
|
|
149
|
-
'INTERNATIONAL')).to.equal('+1 213 373 4253 ext. 123')
|
|
150
|
-
|
|
151
|
-
// International
|
|
152
|
-
expect(formatNumber({
|
|
153
|
-
country : 'US',
|
|
154
|
-
phone : '2133734253',
|
|
155
|
-
ext : '123'
|
|
156
|
-
},
|
|
157
|
-
'INTERNATIONAL')).to.equal('+1 213 373 4253 ext. 123')
|
|
158
|
-
|
|
159
|
-
// E.164
|
|
160
|
-
expect(formatNumber({
|
|
161
|
-
country : 'US',
|
|
162
|
-
phone : '2133734253',
|
|
163
|
-
ext : '123'
|
|
164
|
-
},
|
|
165
|
-
'E.164')).to.equal('+12133734253')
|
|
166
|
-
|
|
167
|
-
// RFC3966
|
|
168
|
-
expect(formatNumber({
|
|
169
|
-
country : 'US',
|
|
170
|
-
phone : '2133734253',
|
|
171
|
-
ext : '123'
|
|
172
|
-
},
|
|
173
|
-
'RFC3966')).to.equal('tel:+12133734253;ext=123')
|
|
174
|
-
|
|
175
|
-
// Custom ext prefix.
|
|
176
|
-
expect(formatNumber({
|
|
177
|
-
country : 'GB',
|
|
178
|
-
phone : '7912345678',
|
|
179
|
-
ext : '123'
|
|
180
|
-
},
|
|
181
|
-
'INTERNATIONAL')).to.equal('+44 7912 345678 x123')
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
it('should work with Argentina numbers', () => {
|
|
185
|
-
// The same mobile number is written differently
|
|
186
|
-
// in different formats in Argentina:
|
|
187
|
-
// `9` gets prepended in international format.
|
|
188
|
-
expect(formatNumber({ country: 'AR', phone: '3435551212' }, 'INTERNATIONAL')).to.equal('+54 3435 55 1212')
|
|
189
|
-
expect(formatNumber({ country: 'AR', phone: '3435551212' }, 'NATIONAL')).to.equal('03435 55-1212')
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
it('should work with Mexico numbers', () => {
|
|
193
|
-
// Fixed line.
|
|
194
|
-
expect(formatNumber({ country: 'MX', phone: '4499780001' }, 'INTERNATIONAL')).to.equal('+52 449 978 0001')
|
|
195
|
-
expect(formatNumber({ country: 'MX', phone: '4499780001' }, 'NATIONAL')).to.equal('449 978 0001')
|
|
196
|
-
// or '(449)978-0001'.
|
|
197
|
-
// Mobile.
|
|
198
|
-
// `1` is prepended before area code to mobile numbers in international format.
|
|
199
|
-
expect(formatNumber({ country: 'MX', phone: '3312345678' }, 'INTERNATIONAL')).to.equal('+52 33 1234 5678')
|
|
200
|
-
expect(formatNumber({ country: 'MX', phone: '3312345678' }, 'NATIONAL')).to.equal('33 1234 5678')
|
|
201
|
-
// or '045 33 1234-5678'.
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
it('should format possible numbers', () => {
|
|
205
|
-
expect(formatNumber({ countryCallingCode: '7', phone: '1111111111' }, 'E.164')).to.equal('+71111111111')
|
|
206
|
-
|
|
207
|
-
expect(formatNumber({ countryCallingCode: '7', phone: '1111111111' }, 'NATIONAL')).to.equal('1111111111')
|
|
208
|
-
|
|
209
|
-
expect(
|
|
210
|
-
formatNumber({ countryCallingCode: '7', phone: '1111111111' }, 'INTERNATIONAL')
|
|
211
|
-
).to.equal('+7 1111111111')
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
it('should format IDD-prefixed number', () => {
|
|
215
|
-
// No `fromCountry`.
|
|
216
|
-
expect(formatNumber('+78005553535', 'IDD')).to.be.undefined
|
|
217
|
-
|
|
218
|
-
// No default IDD prefix.
|
|
219
|
-
expect(formatNumber('+78005553535', 'IDD', { fromCountry: 'BO' })).to.be.undefined
|
|
220
|
-
|
|
221
|
-
// Same country calling code.
|
|
222
|
-
expect(
|
|
223
|
-
formatNumber('+12133734253', 'IDD', { fromCountry: 'CA' })
|
|
224
|
-
).to.equal('1 (213) 373-4253')
|
|
225
|
-
expect(
|
|
226
|
-
formatNumber('+78005553535', 'IDD', { fromCountry: 'KZ' })
|
|
227
|
-
).to.equal('8 (800) 555-35-35')
|
|
228
|
-
|
|
229
|
-
// formatNumber('+78005553535', 'IDD', { fromCountry: 'US' }).should.equal('01178005553535')
|
|
230
|
-
expect(
|
|
231
|
-
formatNumber('+78005553535', 'IDD', { fromCountry: 'US' })
|
|
232
|
-
).to.equal('011 7 800 555 35 35')
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
it('should format non-geographic numbering plan phone numbers', () => {
|
|
236
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/323
|
|
237
|
-
expect(formatNumber('+870773111632', 'INTERNATIONAL')).to.equal('+870 773 111 632')
|
|
238
|
-
expect(formatNumber('+870773111632', 'NATIONAL')).to.equal('773 111 632')
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
it('should use the default IDD prefix when formatting a phone number', () => {
|
|
242
|
-
// Testing preferred international prefixes with ~ are supported.
|
|
243
|
-
// ("~" designates waiting on a line until proceeding with the input).
|
|
244
|
-
expect(formatNumber('+390236618300', 'IDD', { fromCountry: 'BY' })).to.equal('8~10 39 02 3661 8300')
|
|
245
|
-
})
|
|
246
|
-
})
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import metadata from '../../metadata.max.json' with { type: 'json' }
|
|
5
|
-
import Metadata from '../metadata.js'
|
|
6
|
-
import _getNumberType from './getNumberType.js'
|
|
7
|
-
|
|
8
|
-
function getNumberType(...parameters) {
|
|
9
|
-
parameters.push(metadata)
|
|
10
|
-
return _getNumberType.apply(this, parameters)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
describe('getNumberType', () => {
|
|
14
|
-
it('should infer phone number type MOBILE', () => {
|
|
15
|
-
expect(getNumberType('9150000000', 'RU')).to.equal('MOBILE')
|
|
16
|
-
expect(getNumberType('7912345678', 'GB')).to.equal('MOBILE')
|
|
17
|
-
expect(getNumberType('51234567', 'EE')).to.equal('MOBILE')
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('should infer phone number types', () => {
|
|
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
|
-
|
|
26
|
-
expect(getNumberType('2133734253', 'US')).to.equal('FIXED_LINE_OR_MOBILE')
|
|
27
|
-
expect(getNumberType('5002345678', 'US')).to.equal('PERSONAL_NUMBER')
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('should work when no country is passed', () => {
|
|
31
|
-
expect(getNumberType('+79150000000')).to.equal('MOBILE')
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('should return FIXED_LINE_OR_MOBILE when there is ambiguity', () => {
|
|
35
|
-
// (no such country in the metadata, therefore no unit test for this `if`)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('should work in edge cases', function() {
|
|
39
|
-
let thrower
|
|
40
|
-
|
|
41
|
-
// // No metadata
|
|
42
|
-
// thrower = () => _getNumberType({ phone: '+78005553535' })
|
|
43
|
-
// thrower.should.throw('`metadata` argument not passed')
|
|
44
|
-
|
|
45
|
-
// Parsed phone number
|
|
46
|
-
expect(getNumberType({ phone: '8005553535', country: 'RU' })).to.equal('TOLL_FREE')
|
|
47
|
-
|
|
48
|
-
// Invalid phone number
|
|
49
|
-
expect(type(getNumberType('123', 'RU'))).to.equal('undefined')
|
|
50
|
-
|
|
51
|
-
// Invalid country
|
|
52
|
-
thrower = () => getNumberType({ phone: '8005553535', country: 'RUS' })
|
|
53
|
-
expect(thrower).to.throw('Unknown country')
|
|
54
|
-
|
|
55
|
-
// Numerical `value`
|
|
56
|
-
thrower = () => getNumberType(89150000000, 'RU')
|
|
57
|
-
expect(thrower).to.throw(
|
|
58
|
-
'A phone number must either be a string or an object of shape { phone, [country] }.'
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
// When `options` argument is passed.
|
|
62
|
-
expect(getNumberType('8005553535', 'RU', {})).to.equal('TOLL_FREE')
|
|
63
|
-
expect(getNumberType('+78005553535', {})).to.equal('TOLL_FREE')
|
|
64
|
-
expect(getNumberType({ phone: '8005553535', country: 'RU' }, {})).to.equal('TOLL_FREE')
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
function type(something) {
|
|
69
|
-
return typeof something
|
|
70
|
-
}
|
|
@@ -1,49 +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 _isPossibleNumber from './isPossibleNumber.js'
|
|
6
|
-
|
|
7
|
-
function isPossibleNumber(...parameters) {
|
|
8
|
-
parameters.push(metadata)
|
|
9
|
-
return _isPossibleNumber.apply(this, parameters)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
describe('isPossibleNumber', () => {
|
|
13
|
-
it('should work', function()
|
|
14
|
-
{
|
|
15
|
-
expect(isPossibleNumber('+79992223344')).to.equal(true)
|
|
16
|
-
|
|
17
|
-
expect(isPossibleNumber({ phone: '1112223344', country: 'RU' })).to.equal(true)
|
|
18
|
-
expect(isPossibleNumber({ phone: '111222334', country: 'RU' })).to.equal(false)
|
|
19
|
-
expect(isPossibleNumber({ phone: '11122233445', country: 'RU' })).to.equal(false)
|
|
20
|
-
|
|
21
|
-
expect(isPossibleNumber({ phone: '1112223344', countryCallingCode: 7 })).to.equal(true)
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('should work v2', () => {
|
|
25
|
-
expect(
|
|
26
|
-
isPossibleNumber({ nationalNumber: '111222334', countryCallingCode: 7 }, { v2: true })
|
|
27
|
-
).to.equal(false)
|
|
28
|
-
expect(
|
|
29
|
-
isPossibleNumber({ nationalNumber: '1112223344', countryCallingCode: 7 }, { v2: true })
|
|
30
|
-
).to.equal(true)
|
|
31
|
-
expect(
|
|
32
|
-
isPossibleNumber({ nationalNumber: '11122233445', countryCallingCode: 7 }, { v2: true })
|
|
33
|
-
).to.equal(false)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('should work in edge cases', () => {
|
|
37
|
-
// Invalid `PhoneNumber` argument.
|
|
38
|
-
expect(() => isPossibleNumber({}, { v2: true })).to.throw('Invalid phone number object passed')
|
|
39
|
-
|
|
40
|
-
// Empty input is passed.
|
|
41
|
-
// This is just to support `isValidNumber({})`
|
|
42
|
-
// for cases when `parseNumber()` returns `{}`.
|
|
43
|
-
expect(isPossibleNumber({})).to.equal(false)
|
|
44
|
-
expect(() => isPossibleNumber({ phone: '1112223344' })).to.throw('Invalid phone number object passed')
|
|
45
|
-
|
|
46
|
-
// Incorrect country.
|
|
47
|
-
expect(() => isPossibleNumber({ phone: '1112223344', country: 'XX' })).to.throw('Unknown country')
|
|
48
|
-
})
|
|
49
|
-
})
|