libphonenumber-js 1.12.28 → 1.12.30
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.
- package/CHANGELOG.md +111 -94
- package/README.md +36 -22
- package/build/PhoneNumberMatcher.js +18 -11
- package/build/PhoneNumberMatcher.js.map +1 -1
- package/build/PhoneNumberMatcher.test.js +15 -0
- package/build/PhoneNumberMatcher.test.js.map +1 -1
- package/bundle/libphonenumber-js.min.js +1 -1
- package/bundle/libphonenumber-js.min.js.map +1 -1
- package/bundle/libphonenumber-max.js +1 -1
- package/bundle/libphonenumber-max.js.map +1 -1
- package/bundle/libphonenumber-min.js +1 -1
- package/bundle/libphonenumber-min.js.map +1 -1
- package/bundle/libphonenumber-mobile.js +1 -1
- package/bundle/libphonenumber-mobile.js.map +1 -1
- package/es6/PhoneNumberMatcher.js +18 -11
- package/es6/PhoneNumberMatcher.js.map +1 -1
- package/es6/PhoneNumberMatcher.test.js +15 -0
- package/es6/PhoneNumberMatcher.test.js.map +1 -1
- package/max/metadata/metadata.max.json +1 -1
- package/max/metadata/metadata.max.json.js +1 -1
- package/metadata.full.json +1 -1
- package/metadata.full.json.js +1 -1
- package/metadata.max.json +1 -1
- package/metadata.max.json.js +1 -1
- package/metadata.min.json +1 -1
- package/metadata.min.json.js +1 -1
- package/metadata.mobile.json +1 -1
- package/metadata.mobile.json.js +1 -1
- package/min/metadata/metadata.min.json +1 -1
- package/min/metadata/metadata.min.json.js +1 -1
- package/mobile/metadata/metadata.mobile.json +1 -1
- package/mobile/metadata/metadata.mobile.json.js +1 -1
- package/package.json +1 -1
- package/source/PhoneNumberMatcher.js +12 -8
- package/source/PhoneNumberMatcher.test.js +16 -0
package/package.json
CHANGED
|
@@ -53,7 +53,7 @@ const EXTN_PATTERNS_FOR_MATCHING = createExtensionPattern('matching')
|
|
|
53
53
|
const INNER_MATCHES =
|
|
54
54
|
[
|
|
55
55
|
// Breaks on the slash - e.g. "651-234-2345/332-445-1234"
|
|
56
|
-
'
|
|
56
|
+
'/+(.*)',
|
|
57
57
|
|
|
58
58
|
// Note that the bracket here is inside the capturing group, since we consider it part of the
|
|
59
59
|
// phone number. Will match a pattern like "(650) 223 3345 (754) 223 3321".
|
|
@@ -185,7 +185,9 @@ export default class PhoneNumberMatcher
|
|
|
185
185
|
/** The maximum number of retries after matching an invalid number. */
|
|
186
186
|
this.maxTries = options.maxTries
|
|
187
187
|
|
|
188
|
+
// Compile regular expressions.
|
|
188
189
|
this.PATTERN = new RegExp(PATTERN, 'ig')
|
|
190
|
+
this.INNER_MATCHES = INNER_MATCHES.map(pattern => new RegExp(pattern, 'g'))
|
|
189
191
|
|
|
190
192
|
/** The iteration tristate. */
|
|
191
193
|
this.state = 'NOT_READY'
|
|
@@ -207,9 +209,9 @@ export default class PhoneNumberMatcher
|
|
|
207
209
|
* @param index the search index to start searching at
|
|
208
210
|
* @return the phone number match found, null if none can be found
|
|
209
211
|
*/
|
|
210
|
-
find() {
|
|
211
|
-
//
|
|
212
|
-
|
|
212
|
+
find(index) {
|
|
213
|
+
// Reset the regular expression.
|
|
214
|
+
this.PATTERN.lastIndex = index
|
|
213
215
|
|
|
214
216
|
let matches
|
|
215
217
|
while ((this.maxTries > 0) && (matches = this.PATTERN.exec(this.text)) !== null) {
|
|
@@ -271,10 +273,12 @@ export default class PhoneNumberMatcher
|
|
|
271
273
|
* if the substring itself does not qualify as a match.
|
|
272
274
|
*/
|
|
273
275
|
extractInnerMatch(substring, offset, text) {
|
|
274
|
-
for (const
|
|
276
|
+
for (const innerMatchRegExp of this.INNER_MATCHES) {
|
|
277
|
+
// Reset regular expression.
|
|
278
|
+
innerMatchRegExp.lastIndex = 0
|
|
279
|
+
|
|
275
280
|
let isFirstMatch = true
|
|
276
281
|
let candidateMatch
|
|
277
|
-
const innerMatchRegExp = new RegExp(innerMatchPattern, 'g')
|
|
278
282
|
while (this.maxTries > 0 && (candidateMatch = innerMatchRegExp.exec(substring)) !== null) {
|
|
279
283
|
if (isFirstMatch) {
|
|
280
284
|
// We should handle any group before this one too.
|
|
@@ -362,11 +366,11 @@ export default class PhoneNumberMatcher
|
|
|
362
366
|
{
|
|
363
367
|
if (this.state === 'NOT_READY')
|
|
364
368
|
{
|
|
365
|
-
this.lastMatch = this.find(
|
|
369
|
+
this.lastMatch = this.find(this.searchIndex)
|
|
366
370
|
|
|
367
371
|
if (this.lastMatch)
|
|
368
372
|
{
|
|
369
|
-
|
|
373
|
+
this.searchIndex = this.lastMatch.endsAt
|
|
370
374
|
this.state = 'READY'
|
|
371
375
|
}
|
|
372
376
|
else
|
|
@@ -90,4 +90,20 @@ describe('PhoneNumberMatcher', () => {
|
|
|
90
90
|
matcher.next()
|
|
91
91
|
expect(() => matcher.next()).to.throw('No next element')
|
|
92
92
|
})
|
|
93
|
+
|
|
94
|
+
it('should find phone numbers that are separated by a slash', function() {
|
|
95
|
+
const matcher = new PhoneNumberMatcher('651-234-2345/332-445-1234', { defaultCountry: 'US', v2: true }, metadata)
|
|
96
|
+
|
|
97
|
+
expect(matcher.hasNext()).to.equal(true)
|
|
98
|
+
const number1 = matcher.next()
|
|
99
|
+
expect(number1.startsAt).to.equal(0)
|
|
100
|
+
expect(number1.number.number).to.equal('+16512342345')
|
|
101
|
+
|
|
102
|
+
expect(matcher.hasNext()).to.equal(true)
|
|
103
|
+
const number2 = matcher.next()
|
|
104
|
+
expect(number2.startsAt).to.equal(13)
|
|
105
|
+
expect(number2.number.number).to.equal('+13324451234')
|
|
106
|
+
|
|
107
|
+
expect(matcher.hasNext()).to.equal(false)
|
|
108
|
+
})
|
|
93
109
|
})
|