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,68 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import parsePhoneNumber_ from '../parsePhoneNumber.js';
4
- import PhoneNumber from '../PhoneNumber.js';
5
- import metadata from '../../metadata.min.json' with { type: 'json' };
6
- function parsePhoneNumber() {
7
- for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
8
- parameters[_key] = arguments[_key];
9
- }
10
- parameters.push(metadata);
11
- return parsePhoneNumber_.apply(this, parameters);
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
- var NZ_NUMBER = new PhoneNumber('64', '33316005', metadata);
19
-
20
- // Valid global-phone-digits
21
- expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+64'), NZ_NUMBER);
22
- expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+64;{this isn\'t part of phone-context anymore!}'), NZ_NUMBER);
23
- var nzFromPhoneContext = new PhoneNumber('64', '3033316005', metadata);
24
- expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+64-3'), nzFromPhoneContext);
25
- var brFromPhoneContext = new PhoneNumber('55', '5033316005', metadata);
26
- expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+(555)'), brFromPhoneContext);
27
- var usFromPhoneContext = new PhoneNumber('1', '23033316005', metadata);
28
- expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+-1-2.3()'), usFromPhoneContext);
29
-
30
- // Valid domainname.
31
- expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=abc.nz', 'NZ'), NZ_NUMBER);
32
- expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=www.PHONE-numb3r.com', 'NZ'), NZ_NUMBER);
33
- expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=a', 'NZ'), NZ_NUMBER);
34
- expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=3phone.J.', 'NZ'), NZ_NUMBER);
35
- expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=a--z', 'NZ'), NZ_NUMBER);
36
-
37
- // Should strip ISDN subaddress.
38
- expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;isub=/@;phone-context=+64', 'NZ'), NZ_NUMBER);
39
-
40
- // // Should support incorrectly-written RFC 3966 phone numbers:
41
- // // the ones written without a `tel:` prefix.
42
- // expectPhoneNumbersToBeEqual(
43
- // parsePhoneNumber('033316005;phone-context=+64', 'NZ'),
44
- // NZ_NUMBER
45
- // )
46
-
47
- // Invalid descriptor.
48
- expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=');
49
- expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=+');
50
- expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=64');
51
- expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=++64');
52
- expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=+abc');
53
- expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=.');
54
- expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=3phone');
55
- expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=a-.nz');
56
- expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=a{b}c');
57
- });
58
- });
59
- function expectToThrowForInvalidPhoneContext(string) {
60
- expect(parsePhoneNumber(string)).to.be.undefined;
61
- }
62
- function expectPhoneNumbersToBeEqual(phoneNumber1, phoneNumber2) {
63
- if (!phoneNumber1 || !phoneNumber2) {
64
- return false;
65
- }
66
- return phoneNumber1.number === phoneNumber2.number && phoneNumber1.ext === phoneNumber2.ext;
67
- }
68
- //# sourceMappingURL=extractPhoneContext.test.js.map
@@ -1,20 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import getNumberType from './getNumberType.js';
4
- import oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' with { type: 'json' };
5
- describe('getNumberType', function () {
6
- it('should get number type when using old metadata', function () {
7
- expect(getNumberType({
8
- nationalNumber: '2133734253',
9
- country: 'US'
10
- }, {
11
- v2: true
12
- }, oldMetadata)).to.equal('FIXED_LINE_OR_MOBILE');
13
- });
14
- it('should return `undefined` when the phone number is a malformed one', function () {
15
- expect(getNumberType({}, {
16
- v2: true
17
- }, oldMetadata)).to.be.undefined;
18
- });
19
- });
20
- //# sourceMappingURL=getNumberType.test.js.map
@@ -1,13 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import matchesEntirely from './matchesEntirely.js';
4
- describe('matchesEntirely', function () {
5
- it('should work in edge cases', function () {
6
- // No text.
7
- expect(matchesEntirely(undefined, '')).to.equal(true);
8
-
9
- // "OR" in regexp.
10
- expect(matchesEntirely('911231231', '4\d{8}|[1-9]\d{7}')).to.equal(false);
11
- });
12
- });
13
- //# sourceMappingURL=matchesEntirely.test.js.map
@@ -1,9 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import mergeArrays from './mergeArrays.js';
4
- describe('mergeArrays', function () {
5
- it('should merge arrays', function () {
6
- expect(mergeArrays([1, 2], [2, 3])).to.deep.equal([1, 2, 3]);
7
- });
8
- });
9
- //# sourceMappingURL=mergeArrays.test.js.map
@@ -1,9 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import parseDigits from './parseDigits.js';
4
- describe('parseDigits', function () {
5
- it('should parse digits', function () {
6
- expect(parseDigits('+٤٤٢٣٢٣٢٣٤')).to.equal('442323234');
7
- });
8
- });
9
- //# sourceMappingURL=parseDigits.test.js.map
@@ -1,19 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import stripIddPrefix from './stripIddPrefix.js';
4
- import metadata from '../../metadata.min.json' with { type: 'json' };
5
- describe('stripIddPrefix', function () {
6
- it('should strip a valid IDD prefix', function () {
7
- expect(stripIddPrefix('01178005553535', 'US', '1', metadata)).to.equal('78005553535');
8
- });
9
- it('should strip a valid IDD prefix (no country calling code)', function () {
10
- expect(stripIddPrefix('011', 'US', '1', metadata)).to.equal('');
11
- });
12
- it('should strip a valid IDD prefix (valid country calling code)', function () {
13
- expect(stripIddPrefix('0117', 'US', '1', metadata)).to.equal('7');
14
- });
15
- it('should strip a valid IDD prefix (not a valid country calling code)', function () {
16
- expect(stripIddPrefix('0110', 'US', '1', metadata)).to.be.undefined;
17
- });
18
- });
19
- //# sourceMappingURL=stripIddPrefix.test.js.map
@@ -1,118 +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 _isPossibleNumber from './isPossible.js';
11
- import parsePhoneNumber from './parsePhoneNumber.js';
12
- function isPossibleNumber() {
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[1]), {}, {
25
- extract: false
26
- }), metadata);
27
- }
28
- }
29
- if (parameters.length < 2) {
30
- // `options` parameter.
31
- parameters.push(undefined);
32
- }
33
- // Set `v2` flag.
34
- parameters[1] = _objectSpread({
35
- v2: v2
36
- }, parameters[1]);
37
- // Add `metadata` parameter.
38
- parameters.push(metadata);
39
- // Call the function.
40
- return _isPossibleNumber.apply(this, parameters);
41
- }
42
- describe('isPossible', function () {
43
- it('should work', function () {
44
- expect(isPossibleNumber('+79992223344')).to.equal(true);
45
- expect(isPossibleNumber({
46
- phone: '1112223344',
47
- country: 'RU'
48
- })).to.equal(true);
49
- expect(isPossibleNumber({
50
- phone: '111222334',
51
- country: 'RU'
52
- })).to.equal(false);
53
- expect(isPossibleNumber({
54
- phone: '11122233445',
55
- country: 'RU'
56
- })).to.equal(false);
57
- expect(isPossibleNumber({
58
- phone: '1112223344',
59
- countryCallingCode: 7
60
- })).to.equal(true);
61
- });
62
- it('should work v2', function () {
63
- expect(isPossibleNumber({
64
- nationalNumber: '111222334',
65
- countryCallingCode: 7
66
- }, {
67
- v2: true
68
- })).to.equal(false);
69
- expect(isPossibleNumber({
70
- nationalNumber: '1112223344',
71
- countryCallingCode: 7
72
- }, {
73
- v2: true
74
- })).to.equal(true);
75
- expect(isPossibleNumber({
76
- nationalNumber: '11122233445',
77
- countryCallingCode: 7
78
- }, {
79
- v2: true
80
- })).to.equal(false);
81
- });
82
- it('should work in edge cases', function () {
83
- // Invalid `PhoneNumber` argument.
84
- expect(function () {
85
- return isPossibleNumber({}, {
86
- v2: true
87
- });
88
- }).to["throw"]('Invalid phone number object passed');
89
-
90
- // Empty input is passed.
91
- // This is just to support `isValidNumber({})`
92
- // for cases when `parseNumber()` returns `{}`.
93
- expect(isPossibleNumber({})).to.equal(false);
94
- expect(function () {
95
- return isPossibleNumber({
96
- phone: '1112223344'
97
- });
98
- }).to["throw"]('Invalid phone number object passed');
99
-
100
- // Incorrect country.
101
- expect(function () {
102
- return isPossibleNumber({
103
- phone: '1112223344',
104
- country: 'XX'
105
- });
106
- }).to["throw"]('Unknown country');
107
- });
108
- 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 () {
109
- // Tests that Californian numbers `+1310xxxx` are considered possible.
110
- // https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
111
- var phoneNumber = parsePhoneNumber('+13100000', undefined, metadata);
112
- expect(phoneNumber.country).to.equal('CA');
113
- expect(phoneNumber.isPossible()).to.equal(true);
114
- expect(phoneNumber.isValid()).to.equal(true);
115
- expect(phoneNumber.nationalNumber).to.equal('3100000');
116
- });
117
- });
118
- //# sourceMappingURL=isPossible.test.js.map
@@ -1,39 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import _isPossiblePhoneNumber from './isPossiblePhoneNumber.js';
4
- import metadata from '../metadata.min.json' with { type: 'json' };
5
- import oldMetadata from '../test/metadata/1.0.0/metadata.min.json' with { type: 'json' };
6
- function isPossiblePhoneNumber() {
7
- for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
8
- parameters[_key] = arguments[_key];
9
- }
10
- parameters.push(metadata);
11
- return _isPossiblePhoneNumber.apply(this, parameters);
12
- }
13
- describe('isPossiblePhoneNumber', function () {
14
- it('should detect whether a phone number is possible', function () {
15
- expect(isPossiblePhoneNumber('8 (800) 555 35 35', 'RU')).to.equal(true);
16
- expect(isPossiblePhoneNumber('8 (800) 555 35 35 0', 'RU')).to.equal(false);
17
- expect(isPossiblePhoneNumber('Call: 8 (800) 555 35 35', 'RU')).to.equal(false);
18
- expect(isPossiblePhoneNumber('8 (800) 555 35 35', {
19
- defaultCountry: 'RU'
20
- })).to.equal(true);
21
- expect(isPossiblePhoneNumber('+7 (800) 555 35 35')).to.equal(true);
22
- expect(isPossiblePhoneNumber('+7 1 (800) 555 35 35')).to.equal(false);
23
- expect(isPossiblePhoneNumber(' +7 (800) 555 35 35')).to.equal(false);
24
- expect(isPossiblePhoneNumber(' ')).to.equal(false);
25
- });
26
- it('should detect whether a phone number is possible when using old metadata', function () {
27
- expect(function () {
28
- return _isPossiblePhoneNumber('8 (800) 555 35 35', 'RU', oldMetadata);
29
- }).to["throw"]('Missing "possibleLengths" in metadata.');
30
- expect(_isPossiblePhoneNumber('+888 123 456 78901', oldMetadata)).to.equal(true);
31
- });
32
- 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 () {
33
- // Tests that Californian numbers `+1310xxxx` are considered possible.
34
- // https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
35
- expect(isPossiblePhoneNumber('+13100000', 'CA')).to.equal(true);
36
- expect(isPossiblePhoneNumber('3100000', 'CA')).to.equal(true);
37
- });
38
- });
39
- //# sourceMappingURL=isPossiblePhoneNumber.test.js.map
@@ -1,141 +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 _isValidNumber from './isValid.js';
11
- import parsePhoneNumber from './parsePhoneNumber.js';
12
- function isValidNumber() {
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[1]), {}, {
25
- extract: false
26
- }), metadata);
27
- }
28
- }
29
- if (parameters.length < 2) {
30
- // `options` parameter.
31
- parameters.push(undefined);
32
- }
33
- // Set `v2` flag.
34
- parameters[1] = _objectSpread({
35
- v2: v2
36
- }, parameters[1]);
37
- // Add `metadata` parameter.
38
- parameters.push(metadata);
39
- // Call the function.
40
- return _isValidNumber.apply(this, parameters);
41
- }
42
- describe('validate', function () {
43
- it('should validate phone numbers', function () {
44
- expect(isValidNumber('+1-213-373-4253')).to.equal(true);
45
- expect(isValidNumber('+1-213-373')).to.equal(false);
46
- expect(isValidNumber('+1-213-373-4253', undefined)).to.equal(true);
47
- expect(isValidNumber('(213) 373-4253', {
48
- defaultCountry: 'US'
49
- })).to.equal(true);
50
- expect(isValidNumber('(213) 37', {
51
- defaultCountry: 'US'
52
- })).to.equal(false);
53
- expect(isValidNumber({
54
- country: 'US',
55
- phone: '2133734253'
56
- })).to.equal(true);
57
-
58
- // No "types" info: should return `true`.
59
- expect(isValidNumber('+380972423740')).to.equal(true);
60
- expect(isValidNumber('0912345678', {
61
- defaultCountry: 'TW'
62
- })).to.equal(true);
63
-
64
- // Moible numbers starting 07624* are Isle of Man
65
- // which has its own "country code" "IM"
66
- // which is in the "GB" "country calling code" zone.
67
- // So while this number is for "IM" it's still supposed to
68
- // be valid when passed "GB" as a default country.
69
- expect(isValidNumber('07624369230', {
70
- defaultCountry: 'GB'
71
- })).to.equal(true);
72
- });
73
- it('should refine phone number validation in case extended regular expressions are set for a country', function () {
74
- // Germany general validation must pass
75
- expect(isValidNumber('961111111', {
76
- defaultCountry: 'UZ'
77
- })).to.equal(true);
78
- var phoneNumberTypePatterns = metadata.countries.UZ[11];
79
-
80
- // Different regular expressions for precise national number validation.
81
- // `types` index in compressed array is `9` for v1.
82
- // For v2 it's 10.
83
- // For v3 it's 11.
84
- metadata.countries.UZ[11] = [["(?:6(?:1(?:22|3[124]|4[1-4]|5[123578]|64)|2(?:22|3[0-57-9]|41)|5(?:22|3[3-7]|5[024-8])|6\\d{2}|7(?:[23]\\d|7[69])|9(?:22|4[1-8]|6[135]))|7(?:0(?:5[4-9]|6[0146]|7[12456]|9[135-8])|1[12]\\d|2(?:22|3[1345789]|4[123579]|5[14])|3(?:2\\d|3[1578]|4[1-35-7]|5[1-57]|61)|4(?:2\\d|3[1-579]|7[1-79])|5(?:22|5[1-9]|6[1457])|6(?:22|3[12457]|4[13-8])|9(?:22|5[1-9])))\\d{5}"], ["6(?:1(?:2(?:98|2[01])|35[0-4]|50\\d|61[23]|7(?:[01][017]|4\\d|55|9[5-9]))|2(?:11\\d|2(?:[12]1|9[01379])|5(?:[126]\\d|3[0-4])|7\\d{2})|5(?:19[01]|2(?:27|9[26])|30\\d|59\\d|7\\d{2})|6(?:2(?:1[5-9]|2[0367]|38|41|52|60)|3[79]\\d|4(?:56|83)|7(?:[07]\\d|1[017]|3[07]|4[047]|5[057]|67|8[0178]|9[79])|9[0-3]\\d)|7(?:2(?:24|3[237]|4[5-9]|7[15-8])|5(?:7[12]|8[0589])|7(?:0\\d|[39][07])|9(?:0\\d|7[079]))|9(?:2(?:1[1267]|5\\d|3[01]|7[0-4])|5[67]\\d|6(?:2[0-26]|8\\d)|7\\d{2}))\\d{4}|7(?:0\\d{3}|1(?:13[01]|6(?:0[47]|1[67]|66)|71[3-69]|98\\d)|2(?:2(?:2[79]|95)|3(?:2[5-9]|6[0-6])|57\\d|7(?:0\\d|1[17]|2[27]|3[37]|44|5[057]|66|88))|3(?:2(?:1[0-6]|21|3[469]|7[159])|33\\d|5(?:0[0-4]|5[579]|9\\d)|7(?:[0-3579]\\d|4[0467]|6[67]|8[078])|9[4-6]\\d)|4(?:2(?:29|5[0257]|6[0-7]|7[1-57])|5(?:1[0-4]|8\\d|9[5-9])|7(?:0\\d|1[024589]|2[0127]|3[0137]|[46][07]|5[01]|7[5-9]|9[079])|9(?:7[015-9]|[89]\\d))|5(?:112|2(?:0\\d|2[29]|[49]4)|3[1568]\\d|52[6-9]|7(?:0[01578]|1[017]|[23]7|4[047]|[5-7]\\d|8[78]|9[079]))|6(?:2(?:2[1245]|4[2-4])|39\\d|41[179]|5(?:[349]\\d|5[0-2])|7(?:0[017]|[13]\\d|22|44|55|67|88))|9(?:22[128]|3(?:2[0-4]|7\\d)|57[05629]|7(?:2[05-9]|3[37]|4\\d|60|7[2579]|87|9[07])))\\d{4}|9[0-57-9]\\d{7}"]];
85
-
86
- // Extended validation must not pass for an invalid phone number
87
- expect(isValidNumber('961111111', {
88
- defaultCountry: 'UZ'
89
- })).to.equal(false);
90
-
91
- // Extended validation must pass for a valid phone number
92
- expect(isValidNumber('912345678', {
93
- defaultCountry: 'UZ'
94
- })).to.equal(true);
95
- metadata.countries.UZ[11] = phoneNumberTypePatterns;
96
- });
97
- it('should work in edge cases', function () {
98
- // No metadata
99
- var thrower = function thrower() {
100
- return _isValidNumber('+78005553535');
101
- };
102
- expect(thrower).to["throw"]('`metadata` argument not passed');
103
-
104
- // // Non-phone-number characters in a phone number
105
- // isValidNumber('+499821958a').should.equal(false)
106
- // isValidNumber('88005553535x', { defaultCountry: 'RU' }).should.equal(false)
107
-
108
- // Doesn't have `types` regexps in default metadata.
109
- expect(isValidNumber({
110
- country: 'UA',
111
- phone: '300000000'
112
- })).to.equal(true);
113
- expect(isValidNumber({
114
- country: 'UA',
115
- phone: '200000000'
116
- })).to.equal(false);
117
-
118
- // // Numerical `value`
119
- // thrower = () => isValidNumber(88005553535, { defaultCountry: 'RU' })
120
- // thrower.should.throw('A phone number must either be a string or an object of shape { phone, [country] }.')
121
-
122
- // Long country phone code
123
- expect(isValidNumber('+3725555555')).to.equal(true);
124
-
125
- // // Invalid country
126
- // thrower = () => isValidNumber({ phone: '8005553535', country: 'RUS' })
127
- // thrower.should.throw('Unknown country')
128
- });
129
- it('should accept phone number extensions', function () {
130
- // International
131
- expect(isValidNumber('+12133734253 ext. 123')).to.equal(true);
132
- // National
133
- expect(isValidNumber('88005553535 x123', {
134
- defaultCountry: 'RU'
135
- })).to.equal(true);
136
- });
137
- it('should validate non-geographic toll-free phone numbers', function () {
138
- expect(isValidNumber('+80074454123')).to.equal(true);
139
- });
140
- });
141
- //# sourceMappingURL=isValid.test.js.map
@@ -1,26 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import _isValidPhoneNumber from './isValidPhoneNumber.js';
4
- import metadata from '../metadata.min.json' with { type: 'json' };
5
- function isValidPhoneNumber() {
6
- for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
7
- parameters[_key] = arguments[_key];
8
- }
9
- parameters.push(metadata);
10
- return _isValidPhoneNumber.apply(this, parameters);
11
- }
12
- describe('isValidPhoneNumber', function () {
13
- it('should detect whether a phone number is valid', function () {
14
- expect(isValidPhoneNumber('8 (800) 555 35 35', 'RU')).to.equal(true);
15
- expect(isValidPhoneNumber('8 (800) 555 35 35 0', 'RU')).to.equal(false);
16
- expect(isValidPhoneNumber('Call: 8 (800) 555 35 35', 'RU')).to.equal(false);
17
- expect(isValidPhoneNumber('8 (800) 555 35 35', {
18
- defaultCountry: 'RU'
19
- })).to.equal(true);
20
- expect(isValidPhoneNumber('+7 (800) 555 35 35')).to.equal(true);
21
- expect(isValidPhoneNumber('+7 1 (800) 555 35 35')).to.equal(false);
22
- expect(isValidPhoneNumber(' +7 (800) 555 35 35')).to.equal(false);
23
- expect(isValidPhoneNumber(' ')).to.equal(false);
24
- });
25
- });
26
- //# sourceMappingURL=isValidPhoneNumber.test.js.map