libphonenumber-js 1.12.40 → 1.12.42

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 +32 -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,336 +0,0 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
- import { describe, it } from 'mocha';
8
- import { expect } from 'chai';
9
- import metadata from '../metadata.min.json' with { type: 'json' };
10
- import formatNumber_ from './format.js';
11
- import parsePhoneNumber from './parsePhoneNumber.js';
12
- function formatNumber() {
13
- var v2;
14
- for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
15
- parameters[_key] = arguments[_key];
16
- }
17
- if (parameters.length < 1) {
18
- // `input` parameter.
19
- parameters.push(undefined);
20
- } else {
21
- // Convert string `input` to a `PhoneNumber` instance.
22
- if (typeof parameters[0] === 'string') {
23
- v2 = true;
24
- parameters[0] = parsePhoneNumber(parameters[0], _objectSpread(_objectSpread({}, parameters[2]), {}, {
25
- extract: false
26
- }), metadata);
27
- }
28
- }
29
- if (parameters.length < 2) {
30
- // `format` parameter.
31
- parameters.push(undefined);
32
- }
33
- if (parameters.length < 3) {
34
- // `options` parameter.
35
- parameters.push(undefined);
36
- }
37
- // Set `v2` flag.
38
- parameters[2] = _objectSpread({
39
- v2: v2
40
- }, parameters[2]);
41
- // Add `metadata` parameter.
42
- parameters.push(metadata);
43
- // Call the function.
44
- return formatNumber_.apply(this, parameters);
45
- }
46
- describe('format', function () {
47
- it('should work with the first argument being a E.164 number', function () {
48
- expect(formatNumber('+12133734253', 'NATIONAL')).to.equal('(213) 373-4253');
49
- expect(formatNumber('+12133734253', 'INTERNATIONAL')).to.equal('+1 213 373 4253');
50
-
51
- // Invalid number.
52
- expect(formatNumber('+12111111111', 'NATIONAL')).to.equal('(211) 111-1111');
53
-
54
- // Formatting invalid E.164 numbers.
55
- expect(formatNumber('+11111', 'INTERNATIONAL')).to.equal('+1 1111');
56
- expect(formatNumber('+11111', 'NATIONAL')).to.equal('1111');
57
- });
58
- it('should work with the first object argument expanded', function () {
59
- expect(formatNumber('2133734253', 'NATIONAL', {
60
- defaultCountry: 'US'
61
- })).to.equal('(213) 373-4253');
62
- expect(formatNumber('2133734253', 'INTERNATIONAL', {
63
- defaultCountry: 'US'
64
- })).to.equal('+1 213 373 4253');
65
- });
66
- it('should format using formats with no leading digits (`format.leadingDigitsPatterns().length === 0`)', function () {
67
- expect(formatNumber({
68
- phone: '12345678901',
69
- countryCallingCode: 888
70
- }, 'INTERNATIONAL')).to.equal('+888 123 456 78901');
71
- });
72
- it('should sort out the arguments', function () {
73
- var options = {
74
- formatExtension: function formatExtension(number, extension) {
75
- return "".concat(number, " \u0434\u043E\u0431. ").concat(extension);
76
- }
77
- };
78
- expect(formatNumber({
79
- phone: '8005553535',
80
- country: 'RU',
81
- ext: '123'
82
- }, 'NATIONAL', options)).to.equal('8 (800) 555-35-35 доб. 123');
83
-
84
- // Parse number from string.
85
- expect(formatNumber('+78005553535', 'NATIONAL', options)).to.equal('8 (800) 555-35-35');
86
- expect(formatNumber('8005553535', 'NATIONAL', _objectSpread(_objectSpread({}, options), {}, {
87
- defaultCountry: 'RU'
88
- }))).to.equal('8 (800) 555-35-35');
89
- });
90
- it('should format with national prefix when specifically instructed', function () {
91
- // With national prefix.
92
- expect(formatNumber('88005553535', 'NATIONAL', {
93
- defaultCountry: 'RU'
94
- })).to.equal('8 (800) 555-35-35');
95
- // Without national prefix via an explicitly set option.
96
- expect(formatNumber('88005553535', 'NATIONAL', {
97
- nationalPrefix: false,
98
- defaultCountry: 'RU'
99
- })).to.equal('800 555-35-35');
100
- });
101
- it('should format valid phone numbers', function () {
102
- // Switzerland
103
- expect(formatNumber({
104
- country: 'CH',
105
- phone: '446681800'
106
- }, 'INTERNATIONAL')).to.equal('+41 44 668 18 00');
107
- expect(formatNumber({
108
- country: 'CH',
109
- phone: '446681800'
110
- }, 'E.164')).to.equal('+41446681800');
111
- expect(formatNumber({
112
- country: 'CH',
113
- phone: '446681800'
114
- }, 'RFC3966')).to.equal('tel:+41446681800');
115
- expect(formatNumber({
116
- country: 'CH',
117
- phone: '446681800'
118
- }, 'NATIONAL')).to.equal('044 668 18 00');
119
-
120
- // France
121
- expect(formatNumber({
122
- country: 'FR',
123
- phone: '169454850'
124
- }, 'NATIONAL')).to.equal('01 69 45 48 50');
125
-
126
- // Kazakhstan
127
- expect(formatNumber('+7 702 211 1111', 'NATIONAL')).to.equal('8 (702) 211 1111');
128
- });
129
- it('should format national numbers with national prefix even if it\'s optional', function () {
130
- // Russia
131
- expect(formatNumber({
132
- country: 'RU',
133
- phone: '9991234567'
134
- }, 'NATIONAL')).to.equal('8 (999) 123-45-67');
135
- });
136
- it('should work in edge cases', function () {
137
- var thrower;
138
-
139
- // // No phone number
140
- // formatNumber('', 'INTERNATIONAL', { defaultCountry: 'RU' }).should.equal('')
141
- // formatNumber('', 'NATIONAL', { defaultCountry: 'RU' }).should.equal('')
142
-
143
- expect(formatNumber({
144
- country: 'RU',
145
- phone: ''
146
- }, 'INTERNATIONAL')).to.equal('+7');
147
- expect(formatNumber({
148
- country: 'RU',
149
- phone: ''
150
- }, 'NATIONAL')).to.equal('');
151
-
152
- // No suitable format
153
- expect(formatNumber('+121337342530', 'NATIONAL', {
154
- defaultCountry: 'US'
155
- })).to.equal('21337342530');
156
- // No suitable format (leading digits mismatch)
157
- expect(formatNumber('28199999', 'NATIONAL', {
158
- defaultCountry: 'AD'
159
- })).to.equal('28199999');
160
-
161
- // // Numerical `value`
162
- // thrower = () => formatNumber(89150000000, 'NATIONAL', { defaultCountry: 'RU' })
163
- // thrower.should.throw('A phone number must either be a string or an object of shape { phone, [country] }.')
164
-
165
- // // No metadata for country
166
- // expect(() => formatNumber('+121337342530', 'NATIONAL', { defaultCountry: 'USA' })).to.throw('Unknown country')
167
- // expect(() => formatNumber('21337342530', 'NATIONAL', { defaultCountry: 'USA' })).to.throw('Unknown country')
168
-
169
- // No format type
170
- thrower = function thrower() {
171
- return formatNumber('+123');
172
- };
173
- expect(thrower).to["throw"]('Unknown "format" argument');
174
-
175
- // Unknown format type
176
- thrower = function thrower() {
177
- return formatNumber('123', 'Gay', {
178
- defaultCountry: 'US'
179
- });
180
- };
181
- expect(thrower).to["throw"]('Unknown "format" argument');
182
-
183
- // // No metadata
184
- // thrower = () => _formatNumber('123', 'E.164', { defaultCountry: 'RU' })
185
- // thrower.should.throw('`metadata`')
186
-
187
- // No formats
188
- expect(formatNumber('012345', 'NATIONAL', {
189
- defaultCountry: 'AC'
190
- })).to.equal('012345');
191
-
192
- // No `fromCountry` for `IDD` format.
193
- expect(formatNumber('+78005553535', 'IDD')).to.be.undefined;
194
-
195
- // `fromCountry` has no default IDD prefix.
196
- expect(formatNumber('+78005553535', 'IDD', {
197
- fromCountry: 'BO'
198
- })).to.be.undefined;
199
-
200
- // No such country.
201
- expect(function () {
202
- return formatNumber({
203
- phone: '123',
204
- country: 'USA'
205
- }, 'NATIONAL');
206
- }).to["throw"]('Unknown country');
207
- });
208
- it('should format phone number extensions', function () {
209
- // National
210
- expect(formatNumber({
211
- country: 'US',
212
- phone: '2133734253',
213
- ext: '123'
214
- }, 'NATIONAL')).to.equal('(213) 373-4253 ext. 123');
215
-
216
- // International
217
- expect(formatNumber({
218
- country: 'US',
219
- phone: '2133734253',
220
- ext: '123'
221
- }, 'INTERNATIONAL')).to.equal('+1 213 373 4253 ext. 123');
222
-
223
- // International
224
- expect(formatNumber({
225
- country: 'US',
226
- phone: '2133734253',
227
- ext: '123'
228
- }, 'INTERNATIONAL')).to.equal('+1 213 373 4253 ext. 123');
229
-
230
- // E.164
231
- expect(formatNumber({
232
- country: 'US',
233
- phone: '2133734253',
234
- ext: '123'
235
- }, 'E.164')).to.equal('+12133734253');
236
-
237
- // RFC3966
238
- expect(formatNumber({
239
- country: 'US',
240
- phone: '2133734253',
241
- ext: '123'
242
- }, 'RFC3966')).to.equal('tel:+12133734253;ext=123');
243
-
244
- // Custom ext prefix.
245
- expect(formatNumber({
246
- country: 'GB',
247
- phone: '7912345678',
248
- ext: '123'
249
- }, 'INTERNATIONAL')).to.equal('+44 7912 345678 x123');
250
- });
251
- it('should work with Argentina numbers', function () {
252
- // The same mobile number is written differently
253
- // in different formats in Argentina:
254
- // `9` gets prepended in international format.
255
- expect(formatNumber({
256
- country: 'AR',
257
- phone: '3435551212'
258
- }, 'INTERNATIONAL')).to.equal('+54 3435 55 1212');
259
- expect(formatNumber({
260
- country: 'AR',
261
- phone: '3435551212'
262
- }, 'NATIONAL')).to.equal('03435 55-1212');
263
- });
264
- it('should work with Mexico numbers', function () {
265
- // Fixed line.
266
- expect(formatNumber({
267
- country: 'MX',
268
- phone: '4499780001'
269
- }, 'INTERNATIONAL')).to.equal('+52 449 978 0001');
270
- expect(formatNumber({
271
- country: 'MX',
272
- phone: '4499780001'
273
- }, 'NATIONAL')).to.equal('449 978 0001');
274
- // or '(449)978-0001'.
275
- // Mobile.
276
- // `1` is prepended before area code to mobile numbers in international format.
277
- expect(formatNumber({
278
- country: 'MX',
279
- phone: '3312345678'
280
- }, 'INTERNATIONAL')).to.equal('+52 33 1234 5678');
281
- expect(formatNumber({
282
- country: 'MX',
283
- phone: '3312345678'
284
- }, 'NATIONAL')).to.equal('33 1234 5678');
285
- // or '045 33 1234-5678'.
286
- });
287
- it('should format possible numbers', function () {
288
- expect(formatNumber({
289
- countryCallingCode: '7',
290
- phone: '1111111111'
291
- }, 'E.164')).to.equal('+71111111111');
292
- expect(formatNumber({
293
- countryCallingCode: '7',
294
- phone: '1111111111'
295
- }, 'NATIONAL')).to.equal('1111111111');
296
- expect(formatNumber({
297
- countryCallingCode: '7',
298
- phone: '1111111111'
299
- }, 'INTERNATIONAL')).to.equal('+7 1111111111');
300
- });
301
- it('should format IDD-prefixed number', function () {
302
- // No `fromCountry`.
303
- expect(formatNumber('+78005553535', 'IDD')).to.be.undefined;
304
-
305
- // No default IDD prefix.
306
- expect(formatNumber('+78005553535', 'IDD', {
307
- fromCountry: 'BO'
308
- })).to.be.undefined;
309
-
310
- // Same country calling code.
311
- expect(formatNumber('+12133734253', 'IDD', {
312
- fromCountry: 'CA'
313
- })).to.equal('1 (213) 373-4253');
314
- expect(formatNumber('+78005553535', 'IDD', {
315
- fromCountry: 'KZ'
316
- })).to.equal('8 (800) 555-35-35');
317
-
318
- // formatNumber('+78005553535', 'IDD', { fromCountry: 'US' }).should.equal('01178005553535')
319
- expect(formatNumber('+78005553535', 'IDD', {
320
- fromCountry: 'US'
321
- })).to.equal('011 7 800 555 35 35');
322
- });
323
- it('should format non-geographic numbering plan phone numbers', function () {
324
- // https://github.com/catamphetamine/libphonenumber-js/issues/323
325
- expect(formatNumber('+870773111632', 'INTERNATIONAL')).to.equal('+870 773 111 632');
326
- expect(formatNumber('+870773111632', 'NATIONAL')).to.equal('773 111 632');
327
- });
328
- it('should use the default IDD prefix when formatting a phone number', function () {
329
- // Testing preferred international prefixes with ~ are supported.
330
- // ("~" designates waiting on a line until proceeding with the input).
331
- expect(formatNumber('+390236618300', 'IDD', {
332
- fromCountry: 'BY'
333
- })).to.equal('8~10 39 02 3661 8300');
334
- });
335
- });
336
- //# sourceMappingURL=format.test.js.map
@@ -1,30 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import formatIncompletePhoneNumber from './formatIncompletePhoneNumber.js';
4
- import metadata from '../metadata.min.json' with { type: 'json' };
5
- describe('formatIncompletePhoneNumber', function () {
6
- it('should format parsed input value', function () {
7
- var result;
8
-
9
- // National input.
10
- expect(formatIncompletePhoneNumber('880055535', 'RU', metadata)).to.equal('8 (800) 555-35');
11
-
12
- // International input, no country.
13
- expect(formatIncompletePhoneNumber('+780055535', null, metadata)).to.equal('+7 800 555 35');
14
-
15
- // International input, no country argument.
16
- expect(formatIncompletePhoneNumber('+780055535', metadata)).to.equal('+7 800 555 35');
17
-
18
- // International input, with country.
19
- expect(formatIncompletePhoneNumber('+780055535', 'RU', metadata)).to.equal('+7 800 555 35');
20
- });
21
- it('should support an object argument', function () {
22
- expect(formatIncompletePhoneNumber('880055535', {
23
- defaultCountry: 'RU'
24
- }, metadata)).to.equal('8 (800) 555-35');
25
- expect(formatIncompletePhoneNumber('880055535', {
26
- defaultCallingCode: '7'
27
- }, metadata)).to.equal('8 (800) 555-35');
28
- });
29
- });
30
- //# sourceMappingURL=formatIncompletePhoneNumber.test.js.map
@@ -1,10 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import metadata from '../metadata.min.json' with { type: 'json' };
4
- import getCountries from './getCountries.js';
5
- describe('getCountries', function () {
6
- it('should get countries list', function () {
7
- expect(getCountries(metadata).indexOf('RU') > 0).to.equal(true);
8
- });
9
- });
10
- //# sourceMappingURL=getCountries.test.js.map
@@ -1,15 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import metadata from '../metadata.min.json' with { type: 'json' };
4
- import getCountryCallingCode from './getCountryCallingCode.js';
5
- describe('getCountryCallingCode', function () {
6
- it('should get country calling code', function () {
7
- expect(getCountryCallingCode('US', metadata)).to.equal('1');
8
- });
9
- it('should throw if country is unknown', function () {
10
- expect(function () {
11
- return getCountryCallingCode('ZZ', metadata);
12
- }).to["throw"]('Unknown country: ZZ');
13
- });
14
- });
15
- //# sourceMappingURL=getCountryCallingCode.test.js.map
@@ -1,18 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import examples from '../examples.mobile.json' with { type: 'json' };
4
- import metadata from '../metadata.min.json' with { type: 'json' };
5
- import getExampleNumber from './getExampleNumber.js';
6
- describe('getExampleNumber', function () {
7
- it('should get an example number', function () {
8
- var phoneNumber = getExampleNumber('RU', examples, metadata);
9
- expect(phoneNumber.nationalNumber).to.equal('9123456789');
10
- expect(phoneNumber.number).to.equal('+79123456789');
11
- expect(phoneNumber.countryCallingCode).to.equal('7');
12
- expect(phoneNumber.country).to.equal('RU');
13
- });
14
- it('should handle a non-existing country', function () {
15
- expect(getExampleNumber('XX', examples, metadata)).to.be.undefined;
16
- });
17
- });
18
- //# sourceMappingURL=getExampleNumber.test.js.map
@@ -1,45 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import { parseRFC3966, formatRFC3966 } from './RFC3966.js';
4
- describe('RFC3966', function () {
5
- it('should format', function () {
6
- expect(function () {
7
- return formatRFC3966({
8
- number: '123'
9
- });
10
- }).to["throw"]('expects "number" to be in E.164 format');
11
- expect(formatRFC3966({})).to.equal('');
12
- expect(formatRFC3966({
13
- number: '+78005553535'
14
- })).to.equal('tel:+78005553535');
15
- expect(formatRFC3966({
16
- number: '+78005553535',
17
- ext: '123'
18
- })).to.equal('tel:+78005553535;ext=123');
19
- });
20
- it('should parse', function () {
21
- expect(parseRFC3966('tel:+78005553535')).to.deep.equal({
22
- number: '+78005553535'
23
- });
24
- expect(parseRFC3966('tel:+78005553535;ext=123')).to.deep.equal({
25
- number: '+78005553535',
26
- ext: '123'
27
- });
28
-
29
- // With `phone-context`
30
- expect(parseRFC3966('tel:8005553535;ext=123;phone-context=+7')).to.deep.equal({
31
- number: '+78005553535',
32
- ext: '123'
33
- });
34
-
35
- // "Domain contexts" are ignored
36
- expect(parseRFC3966('tel:8005553535;ext=123;phone-context=www.leningrad.spb.ru')).to.deep.equal({
37
- number: '8005553535',
38
- ext: '123'
39
- });
40
-
41
- // Not a viable phone number.
42
- expect(parseRFC3966('tel:3')).to.deep.equal({});
43
- });
44
- });
45
- //# sourceMappingURL=RFC3966.test.js.map
@@ -1,10 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import applyInternationalSeparatorStyle from './applyInternationalSeparatorStyle.js';
4
- describe('applyInternationalSeparatorStyle', function () {
5
- it('should change Google\'s international format style', function () {
6
- expect(applyInternationalSeparatorStyle('(xxx) xxx-xx-xx')).to.equal('xxx xxx xx xx');
7
- expect(applyInternationalSeparatorStyle('(xxx)xxx')).to.equal('xxx xxx');
8
- });
9
- });
10
- //# sourceMappingURL=applyInternationalSeparatorStyle.test.js.map
@@ -1,76 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import Metadata from '../metadata.js';
4
- import metadata from '../../metadata.max.json' with { type: 'json' };
5
- import oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' with { type: 'json' };
6
- import checkNumberLength, { checkNumberLengthForType } from './checkNumberLength.js';
7
- describe('checkNumberLength', function () {
8
- it('should check phone number length', function () {
9
- // Too short.
10
- expect(checkNumberLengthWithCountry('800555353', 'RU', 'FIXED_LINE')).to.equal('TOO_SHORT');
11
- // Normal.
12
- expect(checkNumberLengthWithCountry('8005553535', 'RU', 'FIXED_LINE')).to.equal('IS_POSSIBLE');
13
- // Too long.
14
- expect(checkNumberLengthWithCountry('80055535355', 'RU', 'FIXED_LINE')).to.equal('TOO_LONG');
15
-
16
- // No such type.
17
- expect(checkNumberLengthWithCountry('169454850', 'AC', 'VOIP')).to.equal('INVALID_LENGTH');
18
- // No such possible length.
19
- expect(checkNumberLengthWithCountry('1694548', 'AD', undefined)).to.equal('INVALID_LENGTH');
20
-
21
- // FIXED_LINE_OR_MOBILE
22
- expect(checkNumberLengthWithCountry('1694548', 'AD', 'FIXED_LINE_OR_MOBILE')).to.equal('INVALID_LENGTH');
23
- // No mobile phones.
24
- expect(checkNumberLengthWithCountry('8123', 'TA', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE');
25
- // No "possible lengths" for "mobile".
26
- expect(checkNumberLengthWithCountry('81234567', 'SZ', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE');
27
- });
28
- it('should check phone number length (no `country` specified)', function () {
29
- // Too short.
30
- expect(checkNumberLengthWithoutCountry('800555353', 'RU', 'FIXED_LINE')).to.equal('TOO_SHORT');
31
- // Normal.
32
- expect(checkNumberLengthWithoutCountry('8005553535', 'RU', 'FIXED_LINE')).to.equal('IS_POSSIBLE');
33
- // Too long.
34
- expect(checkNumberLengthWithoutCountry('80055535355', 'RU', 'FIXED_LINE')).to.equal('TOO_LONG');
35
-
36
- // No such type.
37
- expect(checkNumberLengthWithoutCountry('169454850', 'AC', 'VOIP')).to.equal('INVALID_LENGTH');
38
- // No such possible length.
39
- expect(checkNumberLengthWithoutCountry('1694548', 'AD', undefined)).to.equal('INVALID_LENGTH');
40
-
41
- // FIXED_LINE_OR_MOBILE
42
- expect(checkNumberLengthWithoutCountry('1694548', 'AD', 'FIXED_LINE_OR_MOBILE')).to.equal('INVALID_LENGTH');
43
- // No mobile phones.
44
- expect(checkNumberLengthWithoutCountry('8123', 'TA', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE');
45
- // No "possible lengths" for "mobile".
46
- expect(checkNumberLengthWithoutCountry('81234567', 'SZ', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE');
47
- });
48
- it('should work for old metadata', function () {
49
- var _oldMetadata = new Metadata(oldMetadata);
50
- _oldMetadata.country('RU');
51
- expect(checkNumberLengthForType('8005553535', 'RU', 'FIXED_LINE', _oldMetadata)).to.equal('IS_POSSIBLE');
52
- });
53
- it('should work for old metadata (no `country` specified)', function () {
54
- var _oldMetadata = new Metadata(oldMetadata);
55
- _oldMetadata.country('RU');
56
- expect(checkNumberLengthForType('8005553535', undefined, 'FIXED_LINE', _oldMetadata)).to.equal('IS_POSSIBLE');
57
- });
58
- 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', function () {
59
- var _metadata = new Metadata(metadata);
60
- _metadata.country('US');
61
- expect(checkNumberLength('3100000', undefined, _metadata)).to.equal('TOO_SHORT');
62
- expect(checkNumberLength('3100000', 'US', _metadata)).to.equal('TOO_SHORT');
63
- expect(checkNumberLength('3100000', 'CA', _metadata)).to.equal('IS_POSSIBLE');
64
- });
65
- });
66
- function checkNumberLengthWithCountry(number, country, type) {
67
- var _metadata = new Metadata(metadata);
68
- _metadata.country(country);
69
- return checkNumberLengthForType(number, country, type, _metadata);
70
- }
71
- function checkNumberLengthWithoutCountry(number, country, type) {
72
- var _metadata = new Metadata(metadata);
73
- _metadata.country(country);
74
- return checkNumberLengthForType(number, undefined, type, _metadata);
75
- }
76
- //# sourceMappingURL=checkNumberLength.test.js.map
@@ -1,20 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import extractCountryCallingCode from './extractCountryCallingCode.js';
4
- import metadata from '../../metadata.min.json' with { type: 'json' };
5
- describe('extractCountryCallingCode', function () {
6
- it('should extract country calling code from a number', function () {
7
- expect(extractCountryCallingCode('+78005553535', null, null, null, metadata)).to.deep.equal({
8
- countryCallingCodeSource: 'FROM_NUMBER_WITH_PLUS_SIGN',
9
- countryCallingCode: '7',
10
- number: '8005553535'
11
- });
12
- expect(extractCountryCallingCode('+7800', null, null, null, metadata)).to.deep.equal({
13
- countryCallingCodeSource: 'FROM_NUMBER_WITH_PLUS_SIGN',
14
- countryCallingCode: '7',
15
- number: '800'
16
- });
17
- expect(extractCountryCallingCode('', null, null, null, metadata)).to.deep.equal({});
18
- });
19
- });
20
- //# sourceMappingURL=extractCountryCallingCode.test.js.map
@@ -1,24 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import extractNationalNumber from './extractNationalNumber.js';
4
- import Metadata from '../metadata.js';
5
- import oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' with { type: 'json' };
6
- describe('extractNationalNumber', function () {
7
- it('should extract a national number when using old metadata (no `country` or `defaultCountry` specified)', function () {
8
- var _oldMetadata = new Metadata(oldMetadata);
9
- _oldMetadata.selectNumberingPlan('RU');
10
- expect(extractNationalNumber('88005553535', undefined, _oldMetadata)).to.deep.equal({
11
- nationalNumber: '8005553535',
12
- carrierCode: undefined
13
- });
14
- });
15
- it('should extract a national number when using old metadata (`country` is specified)', function () {
16
- var _oldMetadata = new Metadata(oldMetadata);
17
- _oldMetadata.selectNumberingPlan('RU');
18
- expect(extractNationalNumber('88005553535', 'RU', _oldMetadata)).to.deep.equal({
19
- nationalNumber: '8005553535',
20
- carrierCode: undefined
21
- });
22
- });
23
- });
24
- //# sourceMappingURL=extractNationalNumber.test.js.map
@@ -1,17 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import Metadata from '../metadata.js';
4
- import metadata from '../../metadata.min.json' with { type: 'json' };
5
- import extractNationalNumberFromPossiblyIncompleteNumber from './extractNationalNumberFromPossiblyIncompleteNumber.js';
6
- describe('extractNationalNumberFromPossiblyIncompleteNumber', function () {
7
- it('should parse a carrier code when there is no national prefix transform rule', function () {
8
- var meta = new Metadata(metadata);
9
- meta.country('AU');
10
- expect(extractNationalNumberFromPossiblyIncompleteNumber('18311800123', meta)).to.deep.equal({
11
- nationalPrefix: undefined,
12
- carrierCode: '1831',
13
- nationalNumber: '1800123'
14
- });
15
- });
16
- });
17
- //# sourceMappingURL=extractNationalNumberFromPossiblyIncompleteNumber.test.js.map