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,99 +0,0 @@
1
- import { describe, it } from 'mocha'
2
- import { expect } from 'chai'
3
-
4
- import _parsePhoneNumber from './parsePhoneNumber.js'
5
- import metadata from '../metadata.min.json' with { type: 'json' }
6
-
7
- function parsePhoneNumber(...parameters) {
8
- parameters.push(metadata)
9
- return _parsePhoneNumber.apply(this, parameters)
10
- }
11
-
12
- const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
13
-
14
- describe('parsePhoneNumber', () => {
15
- it('should parse phone numbers from string', () => {
16
- expect(parsePhoneNumber('Phone: 8 (800) 555 35 35.', 'RU').nationalNumber).to.equal('8005553535')
17
- expect(parsePhoneNumber('3', 'RU')).to.be.undefined
18
- })
19
-
20
- it('should work in edge cases', () => {
21
- expect(parsePhoneNumber('')).to.be.undefined
22
- })
23
-
24
- it('should parse phone numbers when invalid country code is passed', () => {
25
- expect(parsePhoneNumber('Phone: +7 (800) 555 35 35.', 'XX').nationalNumber).to.equal('8005553535')
26
- expect(parsePhoneNumber('Phone: 8 (800) 555-35-35.', 'XX')).to.be.undefined
27
- })
28
-
29
- it('should parse non-geographic numbering plan phone numbers (extended)', () => {
30
- const phoneNumber = parsePhoneNumber('+870773111632')
31
- expect(phoneNumber.number).to.equal('+870773111632')
32
- if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
33
- expect(phoneNumber.country).to.equal('001')
34
- } else {
35
- expect(phoneNumber.country).to.be.undefined
36
- }
37
- expect(phoneNumber.countryCallingCode).to.equal('870')
38
- })
39
-
40
- it('should parse non-geographic numbering plan phone numbers (default country code) (extended)', () => {
41
- const phoneNumber = parsePhoneNumber('773111632', { defaultCallingCode: '870' })
42
- expect(phoneNumber.number).to.equal('+870773111632')
43
- if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
44
- expect(phoneNumber.country).to.equal('001')
45
- } else {
46
- expect(phoneNumber.country).to.be.undefined
47
- }
48
- expect(phoneNumber.countryCallingCode).to.equal('870')
49
- })
50
-
51
- it('should determine the possibility of non-geographic phone numbers', () => {
52
- const phoneNumber = parsePhoneNumber('+870773111632')
53
- expect(phoneNumber.isPossible()).to.equal(true)
54
- const phoneNumber2 = parsePhoneNumber('+8707731116321')
55
- expect(phoneNumber2.isPossible()).to.equal(false)
56
- })
57
-
58
- it('should support `extract: false` flag', () => {
59
- const testCorrectness = (number, expectedResult) => {
60
- const result = expect(parsePhoneNumber(number, { extract: false, defaultCountry: 'US' }))
61
- if (expectedResult) {
62
- result.to.not.be.undefined
63
- } else {
64
- result.to.be.undefined
65
- }
66
- }
67
- testCorrectness('Call: (213) 373-4253', false)
68
- testCorrectness('(213) 373-4253x', false)
69
- testCorrectness('(213) 373-4253', true)
70
- testCorrectness('- (213) 373-4253 -', true)
71
- testCorrectness('+1 (213) 373-4253', true)
72
- testCorrectness(' +1 (213) 373-4253', false)
73
- })
74
-
75
- it('should not prematurely strip a possible national prefix from Chinese numbers', () => {
76
- // https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/57
77
- const phoneNumber = parsePhoneNumber('+86123456789')
78
- expect(phoneNumber.isPossible()).to.equal(true)
79
- expect(phoneNumber.isValid()).to.equal(false)
80
- expect(phoneNumber.nationalNumber).to.equal('123456789')
81
- })
82
-
83
- 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', () => {
84
- // Tests that Californian numbers `+1310xxxx` are considered possible.
85
- // https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
86
-
87
- const phoneNumber = parsePhoneNumber('+13100000')
88
- expect(phoneNumber.country).to.equal('CA')
89
- expect(phoneNumber.isPossible()).to.equal(true)
90
- expect(phoneNumber.isValid()).to.equal(true)
91
- expect(phoneNumber.nationalNumber).to.equal('3100000')
92
-
93
- const phoneNumberLocal = parsePhoneNumber('3100000', 'CA')
94
- expect(phoneNumberLocal.country).to.equal('CA')
95
- expect(phoneNumberLocal.isPossible()).to.equal(true)
96
- expect(phoneNumberLocal.isValid()).to.equal(true)
97
- expect(phoneNumberLocal.nationalNumber).to.equal('3100000')
98
- })
99
- })
@@ -1,115 +0,0 @@
1
- import { describe, it } from 'mocha'
2
- import { expect } from 'chai'
3
-
4
- import _parsePhoneNumber from './parsePhoneNumberWithError.js'
5
- import metadata from '../metadata.min.json' with { type: 'json' }
6
- import metadataFull from '../metadata.max.json' with { type: 'json' }
7
-
8
- function parsePhoneNumber(...parameters) {
9
- parameters.push(metadata)
10
- return _parsePhoneNumber.apply(this, parameters)
11
- }
12
-
13
- function parsePhoneNumberFull(...parameters) {
14
- parameters.push(metadataFull)
15
- return _parsePhoneNumber.apply(this, parameters)
16
- }
17
-
18
- describe('parsePhoneNumberWithError', () => {
19
- it('should parse phone numbers', () => {
20
- const phoneNumber = parsePhoneNumber('The phone number is: 8 (800) 555 35 35. Some other text.', 'RU')
21
- expect(phoneNumber.country).to.equal('RU')
22
- expect(phoneNumber.countryCallingCode).to.equal('7')
23
- expect(phoneNumber.nationalNumber).to.equal('8005553535')
24
- expect(phoneNumber.number).to.equal('+78005553535')
25
- expect(phoneNumber.isPossible()).to.equal(true)
26
- expect(phoneNumber.isValid()).to.equal(true)
27
- // phoneNumber.isValidForRegion('RU').should.equal(true)
28
- // Russian phone type regexps aren't included in default metadata.
29
- expect(parsePhoneNumberFull('Phone: 8 (800) 555 35 35.', 'RU').getType()).to.equal('TOLL_FREE')
30
- })
31
-
32
- it('shouldn\'t set country when it\'s non-derivable', () => {
33
- const phoneNumber = parsePhoneNumber('+7 111 555 35 35')
34
- expect(phoneNumber.country).to.be.undefined
35
- expect(phoneNumber.countryCallingCode).to.equal('7')
36
- expect(phoneNumber.nationalNumber).to.equal('1115553535')
37
- })
38
-
39
- it('should parse carrier code', () => {
40
- const phoneNumber = parsePhoneNumber('0 15 21 5555-5555', 'BR')
41
- expect(phoneNumber.carrierCode).to.equal('15')
42
- })
43
-
44
- it('should parse phone extension', () => {
45
- const phoneNumber = parsePhoneNumber('Phone: 8 (800) 555 35 35 ext. 1234.', 'RU')
46
- expect(phoneNumber.ext).to.equal('1234')
47
- })
48
-
49
- it('should validate numbers for countries with no type regular expressions', () => {
50
- expect(parsePhoneNumber('+380391234567').isValid()).to.equal(true)
51
- expect(parsePhoneNumber('+380191234567').isValid()).to.equal(false)
52
- })
53
-
54
- it('should format numbers', () => {
55
- const phoneNumber = parsePhoneNumber('Phone: 8 (800) 555 35 35.', 'RU')
56
- expect(phoneNumber.format('NATIONAL')).to.equal('8 (800) 555-35-35')
57
- expect(phoneNumber.formatNational()).to.equal('8 (800) 555-35-35')
58
- expect(phoneNumber.format('INTERNATIONAL')).to.equal('+7 800 555 35 35')
59
- expect(phoneNumber.formatInternational()).to.equal('+7 800 555 35 35')
60
- })
61
-
62
- it('should get tel: URI', () => {
63
- const phoneNumber = parsePhoneNumber('Phone: 8 (800) 555 35 35 ext. 1234.', 'RU')
64
- expect(phoneNumber.getURI()).to.equal('tel:+78005553535;ext=1234')
65
- })
66
-
67
- it('should work in edge cases', () => {
68
- expect(() => parsePhoneNumber('+78005553535', -1, {})).to.throw('Invalid second argument')
69
- })
70
-
71
- it('should throw parse errors', () => {
72
- expect(() => parsePhoneNumber('8005553535', 'XX')).to.throw('INVALID_COUNTRY')
73
- expect(() => parsePhoneNumber('+', 'RU')).to.throw('NOT_A_NUMBER')
74
- expect(() => parsePhoneNumber('a', 'RU')).to.throw('NOT_A_NUMBER')
75
- expect(() => parsePhoneNumber('1', 'RU')).to.throw('TOO_SHORT')
76
- expect(() => parsePhoneNumber('+4')).to.throw('TOO_SHORT')
77
- expect(() => parsePhoneNumber('+44')).to.throw('TOO_SHORT')
78
- expect(() => parsePhoneNumber('+443')).to.throw('TOO_SHORT')
79
- expect(() => parsePhoneNumber('+370')).to.throw('TOO_SHORT')
80
- expect(() => parsePhoneNumber('88888888888888888888', 'RU')).to.throw('TOO_LONG')
81
- expect(() => parsePhoneNumber('8 (800) 555 35 35')).to.throw('INVALID_COUNTRY')
82
- expect(() => parsePhoneNumber('+9991112233')).to.throw('INVALID_COUNTRY')
83
- expect(() => parsePhoneNumber('+9991112233', 'US')).to.throw('INVALID_COUNTRY')
84
- expect(() => parsePhoneNumber('8005553535 ', 'RU')).to.throw('TOO_LONG')
85
- })
86
-
87
- it('should parse incorrect international phone numbers', () => {
88
- // Parsing national prefixes and carrier codes
89
- // is only required for local phone numbers
90
- // but some people don't understand that
91
- // and sometimes write international phone numbers
92
- // with national prefixes (or maybe even carrier codes).
93
- // http://ucken.blogspot.ru/2016/03/trunk-prefixes-in-skype4b.html
94
- // Google's original library forgives such mistakes
95
- // and so does this library, because it has been requested:
96
- // https://github.com/catamphetamine/libphonenumber-js/issues/127
97
-
98
- let phoneNumber
99
-
100
- // For complete numbers it should strip national prefix.
101
- phoneNumber = parsePhoneNumber('+1 1877 215 5230')
102
- expect(phoneNumber.nationalNumber).to.equal('8772155230')
103
- expect(phoneNumber.country).to.equal('US')
104
-
105
- // For complete numbers it should strip national prefix.
106
- phoneNumber = parsePhoneNumber('+7 8800 555 3535')
107
- expect(phoneNumber.nationalNumber).to.equal('8005553535')
108
- expect(phoneNumber.country).to.equal('RU')
109
-
110
- // For incomplete numbers it shouldn't strip national prefix.
111
- phoneNumber = parsePhoneNumber('+7 8800 555 353')
112
- expect(phoneNumber.nationalNumber).to.equal('8800555353')
113
- expect(phoneNumber.country).to.equal('RU')
114
- })
115
- })
@@ -1,47 +0,0 @@
1
- import { describe, it } from 'mocha'
2
- import { expect } from 'chai'
3
-
4
- import searchPhoneNumbersInText from './searchPhoneNumbersInText.js'
5
- import metadata from '../metadata.min.json' with { type: 'json' }
6
-
7
- describe('searchPhoneNumbersInText', () => {
8
- it('should find phone numbers (with default country)', () => {
9
- const NUMBERS = ['+78005553535', '+12133734253']
10
- for (const number of searchPhoneNumbersInText('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', metadata)) {
11
- expect(number.number.number).to.equal(NUMBERS[0])
12
- NUMBERS.shift()
13
- }
14
- })
15
-
16
- it('should find phone numbers', () => {
17
- const NUMBERS = ['+78005553535', '+12133734253']
18
- for (const number of searchPhoneNumbersInText('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', metadata)) {
19
- expect(number.number.number).to.equal(NUMBERS[0])
20
- NUMBERS.shift()
21
- }
22
- })
23
-
24
- it('should find phone numbers in text', () => {
25
- const expectedNumbers = [{
26
- country: 'RU',
27
- nationalNumber: '8005553535',
28
- startsAt: 14,
29
- endsAt: 32
30
- }, {
31
- country: 'US',
32
- nationalNumber: '2133734253',
33
- startsAt: 41,
34
- endsAt: 55
35
- }]
36
-
37
- for (const number of searchPhoneNumbersInText('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', metadata)) {
38
- const expected = expectedNumbers.shift()
39
- expect(number.startsAt).to.equal(expected.startsAt)
40
- expect(number.endsAt).to.equal(expected.endsAt)
41
- expect(number.number.nationalNumber).to.equal(expected.nationalNumber)
42
- expect(number.number.country).to.equal(expected.country)
43
- }
44
-
45
- expect(expectedNumbers.length).to.equal(0)
46
- })
47
- })
@@ -1,43 +0,0 @@
1
- import { describe, it } from 'mocha'
2
- import { expect } from 'chai'
3
-
4
- import semverCompare from './semver-compare.js'
5
-
6
- describe('semver-compare', () => {
7
- it('should compare versions', () => {
8
- const versions = [
9
- '1.2.3',
10
- '4.11.6',
11
- '4.2.0',
12
- '1.5.19',
13
- '1.5.6',
14
- '1.5.4',
15
- '1.5.5-alpha.beta',
16
- '1.5.5-alpha',
17
- '1.5.5',
18
- '1.5.5-rc.1',
19
- '1.5.5-beta.0',
20
- '4.1.3',
21
- '2.3.1',
22
- '10.5.5',
23
- '11.3.0'
24
- ]
25
- expect(versions.sort(semverCompare)).to.deep.equal([
26
- '1.2.3',
27
- '1.5.4',
28
- '1.5.5-alpha',
29
- '1.5.5-alpha.beta',
30
- '1.5.5-beta.0',
31
- '1.5.5-rc.1',
32
- '1.5.5',
33
- '1.5.6',
34
- '1.5.19',
35
- '2.3.1',
36
- '4.1.3',
37
- '4.2.0',
38
- '4.11.6',
39
- '10.5.5',
40
- '11.3.0'
41
- ])
42
- })
43
- })
@@ -1,33 +0,0 @@
1
- import { describe, it } from 'mocha'
2
- import { expect } from 'chai'
3
-
4
- import _validatePhoneNumberLength from './validatePhoneNumberLength.js'
5
- import metadata from '../metadata.min.json' with { type: 'json' }
6
-
7
- function validatePhoneNumberLength(...parameters) {
8
- parameters.push(metadata)
9
- return _validatePhoneNumberLength.apply(this, parameters)
10
- }
11
-
12
- describe('validatePhoneNumberLength', () => {
13
- it('should detect whether a phone number length is valid', () => {
14
- // Not a phone number.
15
- expect(validatePhoneNumberLength('+')).to.equal('NOT_A_NUMBER')
16
- expect(validatePhoneNumberLength('abcde')).to.equal('NOT_A_NUMBER')
17
-
18
- // No country supplied for a national number.
19
- expect(validatePhoneNumberLength('123')).to.equal('INVALID_COUNTRY')
20
-
21
- // Too short while the number is not considered "viable"
22
- // by Google's `libphonenumber`.
23
- expect(validatePhoneNumberLength('2', 'US')).to.equal('TOO_SHORT')
24
- expect(validatePhoneNumberLength('+1', 'US')).to.equal('TOO_SHORT')
25
- expect(validatePhoneNumberLength('+12', 'US')).to.equal('TOO_SHORT')
26
-
27
- // Test national (significant) number length.
28
- expect(validatePhoneNumberLength('444 1 44', 'TR')).to.equal('TOO_SHORT')
29
- expect(validatePhoneNumberLength('444 1 444', 'TR')).to.be.undefined
30
- expect(validatePhoneNumberLength('444 1 4444', 'TR')).to.equal('INVALID_LENGTH')
31
- expect(validatePhoneNumberLength('444 1 4444444444', 'TR')).to.equal('TOO_LONG')
32
- })
33
- })