libphonenumber-js 1.12.22 → 1.12.24

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 (73) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +18 -26
  3. package/build/format.js +46 -17
  4. package/build/format.js.map +1 -1
  5. package/build/legacy/PhoneNumberSearch.js +128 -0
  6. package/build/legacy/PhoneNumberSearch.js.map +1 -0
  7. package/build/legacy/findPhoneNumbers.test.js +4 -4
  8. package/build/legacy/findPhoneNumbers.test.js.map +1 -1
  9. package/build/legacy/findPhoneNumbersInitialImplementation.js +20 -127
  10. package/build/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
  11. package/build/legacy/format.js +12 -13
  12. package/build/legacy/format.js.map +1 -1
  13. package/build/legacy/getNumberType.js +11 -12
  14. package/build/legacy/getNumberType.js.map +1 -1
  15. package/build/parseIncompletePhoneNumber.test.js +34 -0
  16. package/build/parseIncompletePhoneNumber.test.js.map +1 -1
  17. package/build-scripts/check-for-metadata-changes-and-create-pull-request.js +4 -3
  18. package/build-scripts/check-for-metadata-changes-and-release.js +10 -35
  19. package/build-scripts/check-for-uncommitted-files.js +10 -8
  20. package/build-scripts/helpers/commit.js +1 -2
  21. package/build-scripts/helpers/exec.js +3 -4
  22. package/build-scripts/helpers/getUncommittedChanges.js +3 -3
  23. package/build-scripts/helpers/sendEmail.js +62 -0
  24. package/build-scripts/helpers/{update-metadata-from-google-metadata.js → updateMetadataFromGoogleMetadata.js} +5 -9
  25. package/bundle/libphonenumber-js.min.js +1 -1
  26. package/bundle/libphonenumber-js.min.js.map +1 -1
  27. package/bundle/libphonenumber-max.js +1 -1
  28. package/bundle/libphonenumber-max.js.map +1 -1
  29. package/bundle/libphonenumber-min.js +1 -1
  30. package/bundle/libphonenumber-min.js.map +1 -1
  31. package/bundle/libphonenumber-mobile.js +1 -1
  32. package/bundle/libphonenumber-mobile.js.map +1 -1
  33. package/custom.js +1 -1
  34. package/es6/format.js +43 -17
  35. package/es6/format.js.map +1 -1
  36. package/es6/legacy/PhoneNumberSearch.js +126 -0
  37. package/es6/legacy/PhoneNumberSearch.js.map +1 -0
  38. package/es6/legacy/findPhoneNumbers.test.js +1 -1
  39. package/es6/legacy/findPhoneNumbers.test.js.map +1 -1
  40. package/es6/legacy/findPhoneNumbersInitialImplementation.js +15 -124
  41. package/es6/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
  42. package/es6/legacy/format.js +12 -13
  43. package/es6/legacy/format.js.map +1 -1
  44. package/es6/legacy/getNumberType.js +11 -12
  45. package/es6/legacy/getNumberType.js.map +1 -1
  46. package/es6/parseIncompletePhoneNumber.test.js +34 -0
  47. package/es6/parseIncompletePhoneNumber.test.js.map +1 -1
  48. package/index.cjs +1 -1
  49. package/index.cjs.js +1 -1
  50. package/index.es6.exports/PhoneNumberSearch.js +1 -1
  51. package/index.js +1 -1
  52. package/max/metadata/metadata.max.json +1 -1
  53. package/max/metadata/metadata.max.json.js +1 -1
  54. package/metadata.full.json +1 -1
  55. package/metadata.full.json.js +1 -1
  56. package/metadata.max.json +1 -1
  57. package/metadata.max.json.js +1 -1
  58. package/metadata.min.json +1 -1
  59. package/metadata.min.json.js +1 -1
  60. package/metadata.mobile.json +1 -1
  61. package/metadata.mobile.json.js +1 -1
  62. package/min/metadata/metadata.min.json +1 -1
  63. package/min/metadata/metadata.min.json.js +1 -1
  64. package/mobile/metadata/metadata.mobile.json +1 -1
  65. package/mobile/metadata/metadata.mobile.json.js +1 -1
  66. package/package.json +1 -1
  67. package/source/format.js +42 -7
  68. package/source/legacy/PhoneNumberSearch.js +122 -0
  69. package/source/legacy/findPhoneNumbers.test.js +1 -1
  70. package/source/legacy/findPhoneNumbersInitialImplementation.js +24 -134
  71. package/source/legacy/format.js +12 -1
  72. package/source/legacy/getNumberType.js +11 -1
  73. package/source/parseIncompletePhoneNumber.test.js +34 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libphonenumber-js",
3
- "version": "1.12.22",
3
+ "version": "1.12.24",
4
4
  "description": "A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript",
5
5
  "main": "index.cjs",
6
6
  "module": "index.js",
package/source/format.js CHANGED
@@ -31,7 +31,14 @@ const DEFAULT_OPTIONS = {
31
31
  export default function formatNumber(input, format, options, metadata) {
32
32
  // Apply default options.
33
33
  if (options) {
34
- options = { ...DEFAULT_OPTIONS, ...options }
34
+ // Using ES6 "rest spread" syntax here didn't work with `babel`/`istanbul`
35
+ // for some weird reason: this line of code would cause the code coverage
36
+ // to show as not 100%. That's because `babel`/`istanbul`, for some weird reason,
37
+ // apparently doesn't know how to properly exclude Babel polyfills from code coverage.
38
+ //
39
+ // options = { ...DEFAULT_OPTIONS, ...options }
40
+ //
41
+ options = merge({}, DEFAULT_OPTIONS, options)
35
42
  } else {
36
43
  options = DEFAULT_OPTIONS
37
44
  }
@@ -129,7 +136,14 @@ function formatNationalNumber(number, carrierCode, formatAs, metadata, options)
129
136
  }
130
137
 
131
138
  export function chooseFormatForNumber(availableFormats, nationalNumber) {
132
- for (const format of availableFormats) {
139
+ // Using a `for ... of` loop here didn't work with `babel`/`istanbul`:
140
+ // for some weird reason, it showed code coverage less than 100%.
141
+ // That's because `babel`/`istanbul`, for some weird reason,
142
+ // apparently doesn't know how to properly exclude Babel polyfills from code coverage.
143
+ //
144
+ // for (const format of availableFormats) { ... }
145
+ //
146
+ return pickFirstMatchingElement(availableFormats, (format) => {
133
147
  // Validate leading digits.
134
148
  // The test case for "else path" could be found by searching for
135
149
  // "format.leadingDigitsPatterns().length === 0".
@@ -138,14 +152,12 @@ export function chooseFormatForNumber(availableFormats, nationalNumber) {
138
152
  const lastLeadingDigitsPattern = format.leadingDigitsPatterns()[format.leadingDigitsPatterns().length - 1]
139
153
  // If leading digits don't match then move on to the next phone number format
140
154
  if (nationalNumber.search(lastLeadingDigitsPattern) !== 0) {
141
- continue
155
+ return false
142
156
  }
143
157
  }
144
158
  // Check that the national number matches the phone number format regular expression
145
- if (matchesEntirely(nationalNumber, format.pattern())) {
146
- return format
147
- }
148
- }
159
+ return matchesEntirely(nationalNumber, format.pattern())
160
+ })
149
161
  }
150
162
 
151
163
  function addExtension(formattedNumber, ext, metadata, formatExtension) {
@@ -183,4 +195,27 @@ function formatIDD(
183
195
  if (iddPrefix) {
184
196
  return `${iddPrefix} ${countryCallingCode} ${formatNationalNumber(nationalNumber, null, 'INTERNATIONAL', metadata)}`
185
197
  }
198
+ }
199
+
200
+ function merge(...objects) {
201
+ let i = 1
202
+ while (i < objects.length) {
203
+ if (objects[i]) {
204
+ for (const key in objects[i]) {
205
+ objects[0][key] = objects[i][key]
206
+ }
207
+ }
208
+ i++
209
+ }
210
+ return objects[0]
211
+ }
212
+
213
+ function pickFirstMatchingElement(elements, testFunction) {
214
+ let i = 0
215
+ while (i < elements.length) {
216
+ if (testFunction(elements[i])) {
217
+ return elements[i]
218
+ }
219
+ i++
220
+ }
186
221
  }
@@ -0,0 +1,122 @@
1
+ import parse from '../parse.js'
2
+ import { VALID_PHONE_NUMBER_WITH_EXTENSION } from '../helpers/isViablePhoneNumber.js'
3
+
4
+ import parsePreCandidate from '../findNumbers/parsePreCandidate.js'
5
+ import isValidPreCandidate from '../findNumbers/isValidPreCandidate.js'
6
+ import isValidCandidate from '../findNumbers/isValidCandidate.js'
7
+
8
+ import {
9
+ // PLUS_CHARS,
10
+ VALID_PUNCTUATION,
11
+ // VALID_DIGITS,
12
+ WHITESPACE
13
+ } from '../constants.js'
14
+
15
+ const WHITESPACE_IN_THE_BEGINNING_PATTERN = new RegExp('^[' + WHITESPACE + ']+')
16
+ const PUNCTUATION_IN_THE_END_PATTERN = new RegExp('[' + VALID_PUNCTUATION + ']+$')
17
+
18
+ /**
19
+ * Extracts a parseable phone number including any opening brackets, etc.
20
+ * @param {string} text - Input.
21
+ * @return {object} `{ ?number, ?startsAt, ?endsAt }`.
22
+ */
23
+ export default class PhoneNumberSearch {
24
+ constructor(text, options, metadata) {
25
+ this.text = text
26
+ // If assigning the `{}` default value is moved to the arguments above,
27
+ // code coverage would decrease for some weird reason.
28
+ this.options = options || {}
29
+ this.metadata = metadata
30
+
31
+ // Iteration tristate.
32
+ this.state = 'NOT_READY'
33
+
34
+ this.regexp = new RegExp(VALID_PHONE_NUMBER_WITH_EXTENSION, 'ig')
35
+ }
36
+
37
+ find() {
38
+ const matches = this.regexp.exec(this.text)
39
+ if (!matches) {
40
+ return
41
+ }
42
+
43
+ let number = matches[0]
44
+ let startsAt = matches.index
45
+
46
+ number = number.replace(WHITESPACE_IN_THE_BEGINNING_PATTERN, '')
47
+ startsAt += matches[0].length - number.length
48
+ // Fixes not parsing numbers with whitespace in the end.
49
+ // Also fixes not parsing numbers with opening parentheses in the end.
50
+ // https://github.com/catamphetamine/libphonenumber-js/issues/252
51
+ number = number.replace(PUNCTUATION_IN_THE_END_PATTERN, '')
52
+
53
+ number = parsePreCandidate(number)
54
+
55
+ const result = this.parseCandidate(number, startsAt)
56
+ if (result) {
57
+ return result
58
+ }
59
+
60
+ // Tail recursion.
61
+ // Try the next one if this one is not a valid phone number.
62
+ return this.find()
63
+ }
64
+
65
+ parseCandidate(number, startsAt) {
66
+ if (!isValidPreCandidate(number, startsAt, this.text)) {
67
+ return
68
+ }
69
+
70
+ // Don't parse phone numbers which are non-phone numbers
71
+ // due to being part of something else (e.g. a UUID).
72
+ // https://github.com/catamphetamine/libphonenumber-js/issues/213
73
+ // Copy-pasted from Google's `PhoneNumberMatcher.js` (`.parseAndValidate()`).
74
+ if (!isValidCandidate(number, startsAt, this.text, this.options.extended ? 'POSSIBLE' : 'VALID')) {
75
+ return
76
+ }
77
+
78
+ // // Prepend any opening brackets left behind by the
79
+ // // `PHONE_NUMBER_START_PATTERN` regexp.
80
+ // const text_before_number = text.slice(this.searching_from, startsAt)
81
+ // const full_number_starts_at = text_before_number.search(BEFORE_NUMBER_DIGITS_PUNCTUATION)
82
+ // if (full_number_starts_at >= 0) {
83
+ // number = text_before_number.slice(full_number_starts_at) + number
84
+ // startsAt = full_number_starts_at
85
+ // }
86
+ //
87
+ // this.searching_from = matches.lastIndex
88
+
89
+ const result = parse(number, this.options, this.metadata)
90
+ if (!result.phone) {
91
+ return
92
+ }
93
+
94
+ result.startsAt = startsAt
95
+ result.endsAt = startsAt + number.length
96
+ return result
97
+ }
98
+
99
+ hasNext() {
100
+ if (this.state === 'NOT_READY') {
101
+ this.last_match = this.find()
102
+ if (this.last_match) {
103
+ this.state = 'READY'
104
+ } else {
105
+ this.state = 'DONE'
106
+ }
107
+ }
108
+ return this.state === 'READY'
109
+ }
110
+
111
+ next() {
112
+ // Check the state and find the next match as a side-effect if necessary.
113
+ if (!this.hasNext()) {
114
+ throw new Error('No next element')
115
+ }
116
+ // Don't retain that memory any longer than necessary.
117
+ const result = this.last_match
118
+ this.last_match = null
119
+ this.state = 'NOT_READY'
120
+ return result
121
+ }
122
+ }
@@ -2,7 +2,7 @@
2
2
  // Use `findNumbers()` instead.
3
3
 
4
4
  import findNumbers, { searchPhoneNumbers } from './findPhoneNumbers.js'
5
- import { PhoneNumberSearch } from './findPhoneNumbersInitialImplementation.js'
5
+ import PhoneNumberSearch from './PhoneNumberSearch.js'
6
6
  import metadata from '../../metadata.min.json' with { type: 'json' }
7
7
 
8
8
  describe('findPhoneNumbers', () => {
@@ -1,20 +1,9 @@
1
1
  // This is a legacy function.
2
2
  // Use `findNumbers()` instead.
3
3
 
4
- import {
5
- PLUS_CHARS,
6
- VALID_PUNCTUATION,
7
- VALID_DIGITS,
8
- WHITESPACE
9
- } from '../constants.js'
10
-
11
- import parse from '../parse.js'
12
- import { VALID_PHONE_NUMBER_WITH_EXTENSION } from '../helpers/isViablePhoneNumber.js'
13
4
  import createExtensionPattern from '../helpers/extension/createExtensionPattern.js'
14
5
 
15
- import parsePreCandidate from '../findNumbers/parsePreCandidate.js'
16
- import isValidPreCandidate from '../findNumbers/isValidPreCandidate.js'
17
- import isValidCandidate from '../findNumbers/isValidCandidate.js'
6
+ import PhoneNumberSearch from './PhoneNumberSearch.js'
18
7
 
19
8
  /**
20
9
  * Regexp of all possible ways to write extensions, for use when parsing. This
@@ -33,14 +22,11 @@ import isValidCandidate from '../findNumbers/isValidCandidate.js'
33
22
  */
34
23
  export const EXTN_PATTERNS_FOR_PARSING = createExtensionPattern('parsing')
35
24
 
36
- const WHITESPACE_IN_THE_BEGINNING_PATTERN = new RegExp('^[' + WHITESPACE + ']+')
37
- const PUNCTUATION_IN_THE_END_PATTERN = new RegExp('[' + VALID_PUNCTUATION + ']+$')
38
-
39
25
  // // Regular expression for getting opening brackets for a valid number
40
26
  // // found using `PHONE_NUMBER_START_PATTERN` for prepending those brackets to the number.
41
27
  // const BEFORE_NUMBER_DIGITS_PUNCTUATION = new RegExp('[' + OPENING_BRACKETS + ']+' + '[' + WHITESPACE + ']*' + '$')
42
28
 
43
- const VALID_PRECEDING_CHARACTER_PATTERN = /[^a-zA-Z0-9]/
29
+ // const VALID_PRECEDING_CHARACTER_PATTERN = /[^a-zA-Z0-9]/
44
30
 
45
31
  export default function findPhoneNumbers(text, options, metadata) {
46
32
  /* istanbul ignore if */
@@ -63,129 +49,33 @@ export function searchPhoneNumbers(text, options, metadata) {
63
49
  if (options === undefined) {
64
50
  options = {}
65
51
  }
52
+
66
53
  const search = new PhoneNumberSearch(text, options, metadata)
67
- return {
68
- [Symbol.iterator]() {
69
- return {
70
- next: () => {
71
- if (search.hasNext()) {
72
- return {
73
- done: false,
74
- value: search.next()
75
- }
76
- }
54
+
55
+ const iterator = () => {
56
+ return {
57
+ next: () => {
58
+ if (search.hasNext()) {
77
59
  return {
78
- done: true
60
+ done: false,
61
+ value: search.next()
79
62
  }
80
- }
63
+ }
64
+ return {
65
+ done: true
66
+ }
81
67
  }
82
68
  }
83
69
  }
84
- }
85
-
86
- /**
87
- * Extracts a parseable phone number including any opening brackets, etc.
88
- * @param {string} text - Input.
89
- * @return {object} `{ ?number, ?startsAt, ?endsAt }`.
90
- */
91
- export class PhoneNumberSearch {
92
- constructor(text, options, metadata) {
93
- this.text = text
94
- // If assigning the `{}` default value is moved to the arguments above,
95
- // code coverage would decrease for some weird reason.
96
- this.options = options || {}
97
- this.metadata = metadata
98
-
99
- // Iteration tristate.
100
- this.state = 'NOT_READY'
101
-
102
- this.regexp = new RegExp(VALID_PHONE_NUMBER_WITH_EXTENSION, 'ig')
103
- }
104
-
105
- find() {
106
- const matches = this.regexp.exec(this.text)
107
- if (!matches) {
108
- return
109
- }
110
-
111
- let number = matches[0]
112
- let startsAt = matches.index
113
-
114
- number = number.replace(WHITESPACE_IN_THE_BEGINNING_PATTERN, '')
115
- startsAt += matches[0].length - number.length
116
- // Fixes not parsing numbers with whitespace in the end.
117
- // Also fixes not parsing numbers with opening parentheses in the end.
118
- // https://github.com/catamphetamine/libphonenumber-js/issues/252
119
- number = number.replace(PUNCTUATION_IN_THE_END_PATTERN, '')
120
-
121
- number = parsePreCandidate(number)
122
-
123
- const result = this.parseCandidate(number, startsAt)
124
- if (result) {
125
- return result
126
- }
127
-
128
- // Tail recursion.
129
- // Try the next one if this one is not a valid phone number.
130
- return this.find()
131
- }
132
-
133
- parseCandidate(number, startsAt) {
134
- if (!isValidPreCandidate(number, startsAt, this.text)) {
135
- return
136
- }
137
-
138
- // Don't parse phone numbers which are non-phone numbers
139
- // due to being part of something else (e.g. a UUID).
140
- // https://github.com/catamphetamine/libphonenumber-js/issues/213
141
- // Copy-pasted from Google's `PhoneNumberMatcher.js` (`.parseAndValidate()`).
142
- if (!isValidCandidate(number, startsAt, this.text, this.options.extended ? 'POSSIBLE' : 'VALID')) {
143
- return
144
- }
145
-
146
- // // Prepend any opening brackets left behind by the
147
- // // `PHONE_NUMBER_START_PATTERN` regexp.
148
- // const text_before_number = text.slice(this.searching_from, startsAt)
149
- // const full_number_starts_at = text_before_number.search(BEFORE_NUMBER_DIGITS_PUNCTUATION)
150
- // if (full_number_starts_at >= 0)
151
- // {
152
- // number = text_before_number.slice(full_number_starts_at) + number
153
- // startsAt = full_number_starts_at
154
- // }
155
- //
156
- // this.searching_from = matches.lastIndex
157
-
158
- const result = parse(number, this.options, this.metadata)
159
- if (!result.phone) {
160
- return
161
- }
162
-
163
- result.startsAt = startsAt
164
- result.endsAt = startsAt + number.length
165
- return result
166
- }
167
70
 
168
- hasNext() {
169
- if (this.state === 'NOT_READY') {
170
- this.last_match = this.find()
171
- if (this.last_match) {
172
- this.state = 'READY'
173
- } else {
174
- this.state = 'DONE'
175
- }
176
- }
177
- return this.state === 'READY'
178
- }
71
+ // This line of code didn't really work with `babel`/`istanbul`:
72
+ // for some weird reason, it showed code coverage less than 100%.
73
+ // That's because `babel`/`istanbul`, for some weird reason,
74
+ // apparently doesn't know how to properly exclude Babel polyfills from code coverage.
75
+ //
76
+ // const iterable = { [Symbol.iterator]: iterator }
179
77
 
180
- next() {
181
- // Check the state and find the next match as a side-effect if necessary.
182
- if (!this.hasNext()) {
183
- throw new Error('No next element')
184
- }
185
- // Don't retain that memory any longer than necessary.
186
- const result = this.last_match
187
- this.last_match = null
188
- this.state = 'NOT_READY'
189
- return result
190
- }
191
- }
78
+ const iterable = {}
79
+ iterable[Symbol.iterator] = iterator
80
+ return iterable
81
+ }
@@ -16,7 +16,18 @@ export default function formatNumber() {
16
16
  // Sort out arguments
17
17
  function normalizeArguments(args)
18
18
  {
19
- const [arg_1, arg_2, arg_3, arg_4, arg_5] = Array.prototype.slice.call(args)
19
+ // This line of code appeared to not work correctly with `babel`/`istanbul`:
20
+ // for some weird reason, it caused coverage less than 100%.
21
+ // That's because `babel`/`istanbul`, for some weird reason,
22
+ // apparently doesn't know how to properly exclude Babel polyfills from code coverage.
23
+ //
24
+ // const [arg_1, arg_2, arg_3, arg_4, arg_5] = Array.prototype.slice.call(args)
25
+
26
+ const arg_1 = args[0]
27
+ const arg_2 = args[1]
28
+ const arg_3 = args[2]
29
+ const arg_4 = args[3]
30
+ const arg_5 = args[4]
20
31
 
21
32
  let input
22
33
  let format
@@ -16,7 +16,17 @@ export default function getNumberType() {
16
16
  // Sort out arguments
17
17
  export function normalizeArguments(args)
18
18
  {
19
- const [arg_1, arg_2, arg_3, arg_4] = Array.prototype.slice.call(args)
19
+ // This line of code appeared to not work correctly with `babel`/`istanbul`:
20
+ // for some weird reason, it caused coverage less than 100%.
21
+ // That's because `babel`/`istanbul`, for some weird reason,
22
+ // apparently doesn't know how to properly exclude Babel polyfills from code coverage.
23
+ //
24
+ // const [arg_1, arg_2, arg_3, arg_4] = Array.prototype.slice.call(args)
25
+
26
+ const arg_1 = args[0]
27
+ const arg_2 = args[1]
28
+ const arg_3 = args[2]
29
+ const arg_4 = args[3]
20
30
 
21
31
  let input
22
32
  let options = {}
@@ -1,6 +1,26 @@
1
1
  import parseIncompletePhoneNumber, { parsePhoneNumberCharacter } from './parseIncompletePhoneNumber.js'
2
2
 
3
3
  describe('parseIncompletePhoneNumber', () => {
4
+ it('should fix `for ... of` loop coverage', () => {
5
+ // For some weird reason, "istanbul" doesn't know how to properly cover
6
+ // a `for ... of` loop that has been transpiled with Babel.
7
+ // For some reason, it attempts to cover the `for ... of` polyfill coode too,
8
+ // meaning that it complains if that polyfill's edge case is not covered.
9
+ // This test case works around that weird bug by covering that edge case of the polyfill.
10
+ //
11
+ // When it runs `npm test` command, it does so without `babel` transpilation,
12
+ // so the error is gonna be "string.split is not a function or its return value is not iterable".
13
+ //
14
+ // When it runs `npm run test-coverage` command, it does so with `babel` transpilation,
15
+ // so the error is gonna be "Invalid attempt to iterate non-iterable instance.".
16
+ //
17
+ expect(() => {
18
+ parseIncompletePhoneNumber({
19
+ split: () => 123
20
+ })
21
+ }).to.throw(/(not iterable|non-iterable)/)
22
+ })
23
+
4
24
  it('should parse phone number character', () => {
5
25
  // Accepts leading `+`.
6
26
  expect(parsePhoneNumberCharacter('+')).to.equal('+')
@@ -78,4 +98,18 @@ describe('parseIncompletePhoneNumber', () => {
78
98
  expect(parsePhoneNumberCharacter('1', '2', emit)).to.equal('1')
79
99
  expect(stopped).to.equal(true)
80
100
  })
101
+
102
+ it('should call `eventListener` when the input ends abruptly', () => {
103
+ let parsingEnded = false
104
+ const eventListener = (event) => {
105
+ parsingEnded = true;
106
+ if (event !== 'end') {
107
+ throw new Error(`Unexpected event: ${event}`)
108
+ }
109
+ }
110
+
111
+ // Doesn't accept non-leading `+`.
112
+ expect(parsePhoneNumberCharacter('+', '+123', eventListener)).to.be.undefined
113
+ expect(parsingEnded).to.equal(true)
114
+ })
81
115
  })