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.
Files changed (183) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/bundle/libphonenumber-js.min.js +1 -1
  3. package/bundle/libphonenumber-js.min.js.map +1 -1
  4. package/bundle/libphonenumber-max.js +1 -1
  5. package/bundle/libphonenumber-max.js.map +1 -1
  6. package/bundle/libphonenumber-min.js +1 -1
  7. package/bundle/libphonenumber-min.js.map +1 -1
  8. package/bundle/libphonenumber-mobile.js +1 -1
  9. package/bundle/libphonenumber-mobile.js.map +1 -1
  10. package/max/metadata/metadata.max.json +1 -1
  11. package/max/metadata/metadata.max.json.js +1 -1
  12. package/metadata.full.json +1 -1
  13. package/metadata.full.json.js +1 -1
  14. package/metadata.max.json +1 -1
  15. package/metadata.max.json.js +1 -1
  16. package/metadata.min.json +1 -1
  17. package/metadata.min.json.js +1 -1
  18. package/metadata.mobile.json +1 -1
  19. package/metadata.mobile.json.js +1 -1
  20. package/min/metadata/metadata.min.json +1 -1
  21. package/min/metadata/metadata.min.json.js +1 -1
  22. package/mobile/metadata/metadata.mobile.json +1 -1
  23. package/mobile/metadata/metadata.mobile.json.js +1 -1
  24. package/package.json +1 -1
  25. package/.babelrc +0 -21
  26. package/.nycrc +0 -27
  27. package/METADATA.md +0 -155
  28. package/autoupdate.cmd +0 -6
  29. package/autoupdate.sh +0 -16
  30. package/build/AsYouType.test.js +0 -1339
  31. package/build/AsYouTypeFormatter.PatternMatcher.test.js +0 -502
  32. package/build/AsYouTypeFormatter.PatternParser.test.js +0 -49
  33. package/build/AsYouTypeFormatter.util.test.js +0 -24
  34. package/build/PhoneNumber.test.js +0 -141
  35. package/build/PhoneNumberMatcher.test.js +0 -122
  36. package/build/findNumbers/util.test.js +0 -34
  37. package/build/findPhoneNumbersInText.test.js +0 -300
  38. package/build/format.test.js +0 -339
  39. package/build/formatIncompletePhoneNumber.test.js +0 -33
  40. package/build/getCountries.test.js +0 -13
  41. package/build/getCountryCallingCode.test.js +0 -18
  42. package/build/getExampleNumber.test.js +0 -21
  43. package/build/helpers/RFC3966.test.js +0 -47
  44. package/build/helpers/applyInternationalSeparatorStyle.test.js +0 -13
  45. package/build/helpers/checkNumberLength.test.js +0 -81
  46. package/build/helpers/extractCountryCallingCode.test.js +0 -23
  47. package/build/helpers/extractNationalNumber.test.js +0 -27
  48. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -20
  49. package/build/helpers/extractPhoneContext.test.js +0 -71
  50. package/build/helpers/getNumberType.test.js +0 -23
  51. package/build/helpers/matchesEntirely.test.js +0 -16
  52. package/build/helpers/mergeArrays.test.js +0 -12
  53. package/build/helpers/parseDigits.test.js +0 -12
  54. package/build/helpers/stripIddPrefix.test.js +0 -22
  55. package/build/isPossible.test.js +0 -121
  56. package/build/isPossiblePhoneNumber.test.js +0 -42
  57. package/build/isValid.test.js +0 -144
  58. package/build/isValidPhoneNumber.test.js +0 -29
  59. package/build/legacy/findNumbers.test.js +0 -210
  60. package/build/legacy/findPhoneNumbers.test.js +0 -245
  61. package/build/legacy/format.test.js +0 -299
  62. package/build/legacy/getNumberType.test.js +0 -80
  63. package/build/legacy/isPossibleNumber.test.js +0 -82
  64. package/build/legacy/isValidNumber.test.js +0 -102
  65. package/build/legacy/isValidNumberForRegion.test.js +0 -40
  66. package/build/legacy/parse.test.js +0 -617
  67. package/build/legacy/searchNumbers.test.js +0 -33
  68. package/build/metadata.test.js +0 -170
  69. package/build/parse.test.js +0 -653
  70. package/build/parseIncompletePhoneNumber.test.js +0 -109
  71. package/build/parsePhoneNumber.test.js +0 -98
  72. package/build/parsePhoneNumberWithError.test.js +0 -140
  73. package/build/searchPhoneNumbersInText.test.js +0 -51
  74. package/build/tools/semver-compare.test.js +0 -13
  75. package/build/validatePhoneNumberLength.test.js +0 -37
  76. package/build-scripts/check-for-metadata-changes-and-create-pull-request.js +0 -88
  77. package/build-scripts/check-for-metadata-changes-and-release.js +0 -67
  78. package/build-scripts/check-for-uncommitted-files.js +0 -13
  79. package/build-scripts/create-commonjs-package-json-file.js +0 -11
  80. package/build-scripts/create-js-file-for-json-file.js +0 -14
  81. package/build-scripts/create-metadata-update-branch.js +0 -31
  82. package/build-scripts/generate-country-codes-list-in-typescript.js +0 -14
  83. package/build-scripts/generate-metadata-from-google-metadata.js +0 -75
  84. package/build-scripts/helpers/commit.js +0 -14
  85. package/build-scripts/helpers/exec.js +0 -6
  86. package/build-scripts/helpers/getUncommittedChanges.js +0 -33
  87. package/build-scripts/helpers/sendEmail.js +0 -62
  88. package/build-scripts/helpers/updateMetadataFromGoogleMetadata.js +0 -130
  89. package/build-scripts/pull-google-metadata.js +0 -29
  90. package/es6/AsYouType.test.js +0 -1336
  91. package/es6/AsYouTypeFormatter.PatternMatcher.test.js +0 -499
  92. package/es6/AsYouTypeFormatter.PatternParser.test.js +0 -46
  93. package/es6/AsYouTypeFormatter.util.test.js +0 -22
  94. package/es6/PhoneNumber.test.js +0 -138
  95. package/es6/PhoneNumberMatcher.test.js +0 -119
  96. package/es6/findNumbers/util.test.js +0 -32
  97. package/es6/findPhoneNumbersInText.test.js +0 -297
  98. package/es6/format.test.js +0 -336
  99. package/es6/formatIncompletePhoneNumber.test.js +0 -30
  100. package/es6/getCountries.test.js +0 -10
  101. package/es6/getCountryCallingCode.test.js +0 -15
  102. package/es6/getExampleNumber.test.js +0 -18
  103. package/es6/helpers/RFC3966.test.js +0 -45
  104. package/es6/helpers/applyInternationalSeparatorStyle.test.js +0 -10
  105. package/es6/helpers/checkNumberLength.test.js +0 -76
  106. package/es6/helpers/extractCountryCallingCode.test.js +0 -20
  107. package/es6/helpers/extractNationalNumber.test.js +0 -24
  108. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -17
  109. package/es6/helpers/extractPhoneContext.test.js +0 -68
  110. package/es6/helpers/getNumberType.test.js +0 -20
  111. package/es6/helpers/matchesEntirely.test.js +0 -13
  112. package/es6/helpers/mergeArrays.test.js +0 -9
  113. package/es6/helpers/parseDigits.test.js +0 -9
  114. package/es6/helpers/stripIddPrefix.test.js +0 -19
  115. package/es6/isPossible.test.js +0 -118
  116. package/es6/isPossiblePhoneNumber.test.js +0 -39
  117. package/es6/isValid.test.js +0 -141
  118. package/es6/isValidPhoneNumber.test.js +0 -26
  119. package/es6/legacy/findNumbers.test.js +0 -207
  120. package/es6/legacy/findPhoneNumbers.test.js +0 -243
  121. package/es6/legacy/format.test.js +0 -296
  122. package/es6/legacy/getNumberType.test.js +0 -77
  123. package/es6/legacy/isPossibleNumber.test.js +0 -79
  124. package/es6/legacy/isValidNumber.test.js +0 -99
  125. package/es6/legacy/isValidNumberForRegion.test.js +0 -37
  126. package/es6/legacy/parse.test.js +0 -614
  127. package/es6/legacy/searchNumbers.test.js +0 -30
  128. package/es6/metadata.test.js +0 -166
  129. package/es6/parse.test.js +0 -650
  130. package/es6/parseIncompletePhoneNumber.test.js +0 -105
  131. package/es6/parsePhoneNumber.test.js +0 -95
  132. package/es6/parsePhoneNumberWithError.test.js +0 -137
  133. package/es6/searchPhoneNumbersInText.test.js +0 -48
  134. package/es6/tools/semver-compare.test.js +0 -10
  135. package/es6/validatePhoneNumberLength.test.js +0 -34
  136. package/jest.config.json +0 -26
  137. package/rollup.config.mjs +0 -57
  138. package/source/AsYouType.test.js +0 -1409
  139. package/source/AsYouTypeFormatter.PatternMatcher.test.js +0 -644
  140. package/source/AsYouTypeFormatter.PatternParser.test.js +0 -70
  141. package/source/AsYouTypeFormatter.util.test.js +0 -25
  142. package/source/PhoneNumber.test.js +0 -138
  143. package/source/PhoneNumberMatcher.test.js +0 -112
  144. package/source/findNumbers/util.test.js +0 -37
  145. package/source/findPhoneNumbersInText.test.js +0 -316
  146. package/source/format.test.js +0 -273
  147. package/source/formatIncompletePhoneNumber.test.js +0 -33
  148. package/source/getCountries.test.js +0 -12
  149. package/source/getCountryCallingCode.test.js +0 -16
  150. package/source/getExampleNumber.test.js +0 -20
  151. package/source/helpers/RFC3966.test.js +0 -39
  152. package/source/helpers/applyInternationalSeparatorStyle.test.js +0 -11
  153. package/source/helpers/checkNumberLength.test.js +0 -85
  154. package/source/helpers/extractCountryCallingCode.test.js +0 -23
  155. package/source/helpers/extractNationalNumber.test.js +0 -27
  156. package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -18
  157. package/source/helpers/extractPhoneContext.test.js +0 -107
  158. package/source/helpers/getNumberType.test.js +0 -27
  159. package/source/helpers/matchesEntirely.test.js +0 -14
  160. package/source/helpers/mergeArrays.test.js +0 -10
  161. package/source/helpers/parseDigits.test.js +0 -10
  162. package/source/helpers/stripIddPrefix.test.js +0 -24
  163. package/source/isPossible.test.js +0 -86
  164. package/source/isPossiblePhoneNumber.test.js +0 -36
  165. package/source/isValid.test.js +0 -123
  166. package/source/isValidPhoneNumber.test.js +0 -23
  167. package/source/legacy/findNumbers.test.js +0 -220
  168. package/source/legacy/findPhoneNumbers.test.js +0 -252
  169. package/source/legacy/format.test.js +0 -246
  170. package/source/legacy/getNumberType.test.js +0 -70
  171. package/source/legacy/isPossibleNumber.test.js +0 -49
  172. package/source/legacy/isValidNumber.test.js +0 -95
  173. package/source/legacy/isValidNumberForRegion.test.js +0 -31
  174. package/source/legacy/parse.test.js +0 -533
  175. package/source/legacy/searchNumbers.test.js +0 -29
  176. package/source/metadata.test.js +0 -178
  177. package/source/parse.test.js +0 -561
  178. package/source/parseIncompletePhoneNumber.test.js +0 -118
  179. package/source/parsePhoneNumber.test.js +0 -99
  180. package/source/parsePhoneNumberWithError.test.js +0 -115
  181. package/source/searchPhoneNumbersInText.test.js +0 -47
  182. package/source/tools/semver-compare.test.js +0 -43
  183. package/source/validatePhoneNumberLength.test.js +0 -33
@@ -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
- }