libphonenumber-js 1.12.39 → 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.
- package/CHANGELOG.md +23 -0
- 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/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/.babelrc +0 -21
- package/.nycrc +0 -27
- package/METADATA.md +0 -155
- package/autoupdate.cmd +0 -6
- package/autoupdate.sh +0 -16
- package/build/AsYouType.test.js +0 -1339
- package/build/AsYouTypeFormatter.PatternMatcher.test.js +0 -502
- package/build/AsYouTypeFormatter.PatternParser.test.js +0 -49
- package/build/AsYouTypeFormatter.util.test.js +0 -24
- package/build/PhoneNumber.test.js +0 -141
- package/build/PhoneNumberMatcher.test.js +0 -122
- package/build/findNumbers/util.test.js +0 -34
- package/build/findPhoneNumbersInText.test.js +0 -300
- package/build/format.test.js +0 -339
- package/build/formatIncompletePhoneNumber.test.js +0 -33
- package/build/getCountries.test.js +0 -13
- package/build/getCountryCallingCode.test.js +0 -18
- package/build/getExampleNumber.test.js +0 -21
- package/build/helpers/RFC3966.test.js +0 -47
- package/build/helpers/applyInternationalSeparatorStyle.test.js +0 -13
- package/build/helpers/checkNumberLength.test.js +0 -81
- package/build/helpers/extractCountryCallingCode.test.js +0 -23
- package/build/helpers/extractNationalNumber.test.js +0 -27
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -20
- package/build/helpers/extractPhoneContext.test.js +0 -71
- package/build/helpers/getNumberType.test.js +0 -23
- package/build/helpers/matchesEntirely.test.js +0 -16
- package/build/helpers/mergeArrays.test.js +0 -12
- package/build/helpers/parseDigits.test.js +0 -12
- package/build/helpers/stripIddPrefix.test.js +0 -22
- package/build/isPossible.test.js +0 -121
- package/build/isPossiblePhoneNumber.test.js +0 -42
- package/build/isValid.test.js +0 -144
- package/build/isValidPhoneNumber.test.js +0 -29
- package/build/legacy/findNumbers.test.js +0 -210
- package/build/legacy/findPhoneNumbers.test.js +0 -245
- package/build/legacy/format.test.js +0 -299
- package/build/legacy/getNumberType.test.js +0 -80
- package/build/legacy/isPossibleNumber.test.js +0 -82
- package/build/legacy/isValidNumber.test.js +0 -102
- package/build/legacy/isValidNumberForRegion.test.js +0 -40
- package/build/legacy/parse.test.js +0 -617
- package/build/legacy/searchNumbers.test.js +0 -33
- package/build/metadata.test.js +0 -170
- package/build/parse.test.js +0 -653
- package/build/parseIncompletePhoneNumber.test.js +0 -109
- package/build/parsePhoneNumber.test.js +0 -98
- package/build/parsePhoneNumberWithError.test.js +0 -140
- package/build/searchPhoneNumbersInText.test.js +0 -51
- package/build/tools/semver-compare.test.js +0 -13
- package/build/validatePhoneNumberLength.test.js +0 -37
- package/build-scripts/check-for-metadata-changes-and-create-pull-request.js +0 -88
- package/build-scripts/check-for-metadata-changes-and-release.js +0 -67
- package/build-scripts/check-for-uncommitted-files.js +0 -13
- package/build-scripts/create-commonjs-package-json-file.js +0 -11
- package/build-scripts/create-js-file-for-json-file.js +0 -14
- package/build-scripts/create-metadata-update-branch.js +0 -31
- package/build-scripts/generate-country-codes-list-in-typescript.js +0 -14
- package/build-scripts/generate-metadata-from-google-metadata.js +0 -75
- package/build-scripts/helpers/commit.js +0 -14
- package/build-scripts/helpers/exec.js +0 -6
- package/build-scripts/helpers/getUncommittedChanges.js +0 -33
- package/build-scripts/helpers/sendEmail.js +0 -62
- package/build-scripts/helpers/updateMetadataFromGoogleMetadata.js +0 -130
- package/build-scripts/pull-google-metadata.js +0 -29
- package/es6/AsYouType.test.js +0 -1336
- package/es6/AsYouTypeFormatter.PatternMatcher.test.js +0 -499
- package/es6/AsYouTypeFormatter.PatternParser.test.js +0 -46
- package/es6/AsYouTypeFormatter.util.test.js +0 -22
- package/es6/PhoneNumber.test.js +0 -138
- package/es6/PhoneNumberMatcher.test.js +0 -119
- package/es6/findNumbers/util.test.js +0 -32
- package/es6/findPhoneNumbersInText.test.js +0 -297
- package/es6/format.test.js +0 -336
- package/es6/formatIncompletePhoneNumber.test.js +0 -30
- package/es6/getCountries.test.js +0 -10
- package/es6/getCountryCallingCode.test.js +0 -15
- package/es6/getExampleNumber.test.js +0 -18
- package/es6/helpers/RFC3966.test.js +0 -45
- package/es6/helpers/applyInternationalSeparatorStyle.test.js +0 -10
- package/es6/helpers/checkNumberLength.test.js +0 -76
- package/es6/helpers/extractCountryCallingCode.test.js +0 -20
- package/es6/helpers/extractNationalNumber.test.js +0 -24
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -17
- package/es6/helpers/extractPhoneContext.test.js +0 -68
- package/es6/helpers/getNumberType.test.js +0 -20
- package/es6/helpers/matchesEntirely.test.js +0 -13
- package/es6/helpers/mergeArrays.test.js +0 -9
- package/es6/helpers/parseDigits.test.js +0 -9
- package/es6/helpers/stripIddPrefix.test.js +0 -19
- package/es6/isPossible.test.js +0 -118
- package/es6/isPossiblePhoneNumber.test.js +0 -39
- package/es6/isValid.test.js +0 -141
- package/es6/isValidPhoneNumber.test.js +0 -26
- package/es6/legacy/findNumbers.test.js +0 -207
- package/es6/legacy/findPhoneNumbers.test.js +0 -243
- package/es6/legacy/format.test.js +0 -296
- package/es6/legacy/getNumberType.test.js +0 -77
- package/es6/legacy/isPossibleNumber.test.js +0 -79
- package/es6/legacy/isValidNumber.test.js +0 -99
- package/es6/legacy/isValidNumberForRegion.test.js +0 -37
- package/es6/legacy/parse.test.js +0 -614
- package/es6/legacy/searchNumbers.test.js +0 -30
- package/es6/metadata.test.js +0 -166
- package/es6/parse.test.js +0 -650
- package/es6/parseIncompletePhoneNumber.test.js +0 -105
- package/es6/parsePhoneNumber.test.js +0 -95
- package/es6/parsePhoneNumberWithError.test.js +0 -137
- package/es6/searchPhoneNumbersInText.test.js +0 -48
- package/es6/tools/semver-compare.test.js +0 -10
- package/es6/validatePhoneNumberLength.test.js +0 -34
- package/jest.config.json +0 -26
- package/rollup.config.mjs +0 -57
- package/source/AsYouType.test.js +0 -1409
- package/source/AsYouTypeFormatter.PatternMatcher.test.js +0 -644
- package/source/AsYouTypeFormatter.PatternParser.test.js +0 -70
- package/source/AsYouTypeFormatter.util.test.js +0 -25
- package/source/PhoneNumber.test.js +0 -138
- package/source/PhoneNumberMatcher.test.js +0 -112
- package/source/findNumbers/util.test.js +0 -37
- package/source/findPhoneNumbersInText.test.js +0 -316
- package/source/format.test.js +0 -273
- package/source/formatIncompletePhoneNumber.test.js +0 -33
- package/source/getCountries.test.js +0 -12
- package/source/getCountryCallingCode.test.js +0 -16
- package/source/getExampleNumber.test.js +0 -20
- package/source/helpers/RFC3966.test.js +0 -39
- package/source/helpers/applyInternationalSeparatorStyle.test.js +0 -11
- package/source/helpers/checkNumberLength.test.js +0 -85
- package/source/helpers/extractCountryCallingCode.test.js +0 -23
- package/source/helpers/extractNationalNumber.test.js +0 -27
- package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -18
- package/source/helpers/extractPhoneContext.test.js +0 -107
- package/source/helpers/getNumberType.test.js +0 -27
- package/source/helpers/matchesEntirely.test.js +0 -14
- package/source/helpers/mergeArrays.test.js +0 -10
- package/source/helpers/parseDigits.test.js +0 -10
- package/source/helpers/stripIddPrefix.test.js +0 -24
- package/source/isPossible.test.js +0 -86
- package/source/isPossiblePhoneNumber.test.js +0 -36
- package/source/isValid.test.js +0 -123
- package/source/isValidPhoneNumber.test.js +0 -23
- package/source/legacy/findNumbers.test.js +0 -220
- package/source/legacy/findPhoneNumbers.test.js +0 -252
- package/source/legacy/format.test.js +0 -246
- package/source/legacy/getNumberType.test.js +0 -70
- package/source/legacy/isPossibleNumber.test.js +0 -49
- package/source/legacy/isValidNumber.test.js +0 -95
- package/source/legacy/isValidNumberForRegion.test.js +0 -31
- package/source/legacy/parse.test.js +0 -533
- package/source/legacy/searchNumbers.test.js +0 -29
- package/source/metadata.test.js +0 -178
- package/source/parse.test.js +0 -561
- package/source/parseIncompletePhoneNumber.test.js +0 -118
- package/source/parsePhoneNumber.test.js +0 -99
- package/source/parsePhoneNumberWithError.test.js +0 -115
- package/source/searchPhoneNumbersInText.test.js +0 -47
- package/source/tools/semver-compare.test.js +0 -43
- package/source/validatePhoneNumberLength.test.js +0 -33
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import getNumberType from './getNumberType.js'
|
|
5
|
-
|
|
6
|
-
import oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }
|
|
7
|
-
|
|
8
|
-
describe('getNumberType', function() {
|
|
9
|
-
it('should get number type when using old metadata', function() {
|
|
10
|
-
expect(getNumberType(
|
|
11
|
-
{
|
|
12
|
-
nationalNumber: '2133734253',
|
|
13
|
-
country: 'US'
|
|
14
|
-
},
|
|
15
|
-
{ v2: true },
|
|
16
|
-
oldMetadata
|
|
17
|
-
)).to.equal('FIXED_LINE_OR_MOBILE')
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('should return `undefined` when the phone number is a malformed one', function() {
|
|
21
|
-
expect(getNumberType(
|
|
22
|
-
{},
|
|
23
|
-
{ v2: true },
|
|
24
|
-
oldMetadata
|
|
25
|
-
)).to.be.undefined
|
|
26
|
-
})
|
|
27
|
-
})
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import matchesEntirely from './matchesEntirely.js'
|
|
5
|
-
|
|
6
|
-
describe('matchesEntirely', () => {
|
|
7
|
-
it('should work in edge cases', () => {
|
|
8
|
-
// No text.
|
|
9
|
-
expect(matchesEntirely(undefined, '')).to.equal(true)
|
|
10
|
-
|
|
11
|
-
// "OR" in regexp.
|
|
12
|
-
expect(matchesEntirely('911231231', '4\d{8}|[1-9]\d{7}')).to.equal(false)
|
|
13
|
-
})
|
|
14
|
-
})
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import mergeArrays from './mergeArrays.js'
|
|
5
|
-
|
|
6
|
-
describe('mergeArrays', () => {
|
|
7
|
-
it('should merge arrays', () => {
|
|
8
|
-
expect(mergeArrays([1, 2], [2, 3])).to.deep.equal([1, 2, 3])
|
|
9
|
-
})
|
|
10
|
-
})
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import stripIddPrefix from './stripIddPrefix.js'
|
|
5
|
-
|
|
6
|
-
import metadata from '../../metadata.min.json' with { type: 'json' }
|
|
7
|
-
|
|
8
|
-
describe('stripIddPrefix', () => {
|
|
9
|
-
it('should strip a valid IDD prefix', () => {
|
|
10
|
-
expect(stripIddPrefix('01178005553535', 'US', '1', metadata)).to.equal('78005553535')
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
it('should strip a valid IDD prefix (no country calling code)', () => {
|
|
14
|
-
expect(stripIddPrefix('011', 'US', '1', metadata)).to.equal('')
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it('should strip a valid IDD prefix (valid country calling code)', () => {
|
|
18
|
-
expect(stripIddPrefix('0117', 'US', '1', metadata)).to.equal('7')
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('should strip a valid IDD prefix (not a valid country calling code)', () => {
|
|
22
|
-
expect(stripIddPrefix('0110', 'US', '1', metadata)).to.be.undefined
|
|
23
|
-
})
|
|
24
|
-
})
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import metadata from '../metadata.min.json' with { type: 'json' }
|
|
5
|
-
import _isPossibleNumber from './isPossible.js'
|
|
6
|
-
import parsePhoneNumber from './parsePhoneNumber.js'
|
|
7
|
-
|
|
8
|
-
function isPossibleNumber(...parameters) {
|
|
9
|
-
let v2
|
|
10
|
-
if (parameters.length < 1) {
|
|
11
|
-
// `input` parameter.
|
|
12
|
-
parameters.push(undefined)
|
|
13
|
-
} else {
|
|
14
|
-
// Convert string `input` to a `PhoneNumber` instance.
|
|
15
|
-
if (typeof parameters[0] === 'string') {
|
|
16
|
-
v2 = true
|
|
17
|
-
parameters[0] = parsePhoneNumber(parameters[0], {
|
|
18
|
-
...parameters[1],
|
|
19
|
-
extract: false
|
|
20
|
-
}, metadata)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (parameters.length < 2) {
|
|
24
|
-
// `options` parameter.
|
|
25
|
-
parameters.push(undefined)
|
|
26
|
-
}
|
|
27
|
-
// Set `v2` flag.
|
|
28
|
-
parameters[1] = {
|
|
29
|
-
v2,
|
|
30
|
-
...parameters[1]
|
|
31
|
-
}
|
|
32
|
-
// Add `metadata` parameter.
|
|
33
|
-
parameters.push(metadata)
|
|
34
|
-
// Call the function.
|
|
35
|
-
return _isPossibleNumber.apply(this, parameters)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
describe('isPossible', () => {
|
|
39
|
-
it('should work', function()
|
|
40
|
-
{
|
|
41
|
-
expect(isPossibleNumber('+79992223344')).to.equal(true)
|
|
42
|
-
|
|
43
|
-
expect(isPossibleNumber({ phone: '1112223344', country: 'RU' })).to.equal(true)
|
|
44
|
-
expect(isPossibleNumber({ phone: '111222334', country: 'RU' })).to.equal(false)
|
|
45
|
-
expect(isPossibleNumber({ phone: '11122233445', country: 'RU' })).to.equal(false)
|
|
46
|
-
|
|
47
|
-
expect(isPossibleNumber({ phone: '1112223344', countryCallingCode: 7 })).to.equal(true)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('should work v2', () => {
|
|
51
|
-
expect(
|
|
52
|
-
isPossibleNumber({ nationalNumber: '111222334', countryCallingCode: 7 }, { v2: true })
|
|
53
|
-
).to.equal(false)
|
|
54
|
-
expect(
|
|
55
|
-
isPossibleNumber({ nationalNumber: '1112223344', countryCallingCode: 7 }, { v2: true })
|
|
56
|
-
).to.equal(true)
|
|
57
|
-
expect(
|
|
58
|
-
isPossibleNumber({ nationalNumber: '11122233445', countryCallingCode: 7 }, { v2: true })
|
|
59
|
-
).to.equal(false)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('should work in edge cases', () => {
|
|
63
|
-
// Invalid `PhoneNumber` argument.
|
|
64
|
-
expect(() => isPossibleNumber({}, { v2: true })).to.throw('Invalid phone number object passed')
|
|
65
|
-
|
|
66
|
-
// Empty input is passed.
|
|
67
|
-
// This is just to support `isValidNumber({})`
|
|
68
|
-
// for cases when `parseNumber()` returns `{}`.
|
|
69
|
-
expect(isPossibleNumber({})).to.equal(false)
|
|
70
|
-
expect(() => isPossibleNumber({ phone: '1112223344' })).to.throw('Invalid phone number object passed')
|
|
71
|
-
|
|
72
|
-
// Incorrect country.
|
|
73
|
-
expect(() => isPossibleNumber({ phone: '1112223344', country: 'XX' })).to.throw('Unknown country')
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
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', () => {
|
|
78
|
-
// Tests that Californian numbers `+1310xxxx` are considered possible.
|
|
79
|
-
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
|
|
80
|
-
const phoneNumber = parsePhoneNumber('+13100000', undefined, metadata)
|
|
81
|
-
expect(phoneNumber.country).to.equal('CA')
|
|
82
|
-
expect(phoneNumber.isPossible()).to.equal(true)
|
|
83
|
-
expect(phoneNumber.isValid()).to.equal(true)
|
|
84
|
-
expect(phoneNumber.nationalNumber).to.equal('3100000')
|
|
85
|
-
})
|
|
86
|
-
})
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import _isPossiblePhoneNumber from './isPossiblePhoneNumber.js'
|
|
5
|
-
import metadata from '../metadata.min.json' with { type: 'json' }
|
|
6
|
-
import oldMetadata from '../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }
|
|
7
|
-
|
|
8
|
-
function isPossiblePhoneNumber(...parameters) {
|
|
9
|
-
parameters.push(metadata)
|
|
10
|
-
return _isPossiblePhoneNumber.apply(this, parameters)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
describe('isPossiblePhoneNumber', () => {
|
|
14
|
-
it('should detect whether a phone number is possible', () => {
|
|
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', { defaultCountry: 'RU' })).to.equal(true)
|
|
19
|
-
expect(isPossiblePhoneNumber('+7 (800) 555 35 35')).to.equal(true)
|
|
20
|
-
expect(isPossiblePhoneNumber('+7 1 (800) 555 35 35')).to.equal(false)
|
|
21
|
-
expect(isPossiblePhoneNumber(' +7 (800) 555 35 35')).to.equal(false)
|
|
22
|
-
expect(isPossiblePhoneNumber(' ')).to.equal(false)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('should detect whether a phone number is possible when using old metadata', () => {
|
|
26
|
-
expect(() => _isPossiblePhoneNumber('8 (800) 555 35 35', 'RU', oldMetadata)).to.throw('Missing "possibleLengths" in metadata.')
|
|
27
|
-
expect(_isPossiblePhoneNumber('+888 123 456 78901', oldMetadata)).to.equal(true)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
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', () => {
|
|
31
|
-
// Tests that Californian numbers `+1310xxxx` are considered possible.
|
|
32
|
-
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
|
|
33
|
-
expect(isPossiblePhoneNumber('+13100000', 'CA')).to.equal(true)
|
|
34
|
-
expect(isPossiblePhoneNumber('3100000', 'CA')).to.equal(true)
|
|
35
|
-
})
|
|
36
|
-
})
|
package/source/isValid.test.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import metadata from '../metadata.min.json' with { type: 'json' }
|
|
5
|
-
import _isValidNumber from './isValid.js'
|
|
6
|
-
import parsePhoneNumber from './parsePhoneNumber.js'
|
|
7
|
-
|
|
8
|
-
function isValidNumber(...parameters) {
|
|
9
|
-
let v2
|
|
10
|
-
if (parameters.length < 1) {
|
|
11
|
-
// `input` parameter.
|
|
12
|
-
parameters.push(undefined)
|
|
13
|
-
} else {
|
|
14
|
-
// Convert string `input` to a `PhoneNumber` instance.
|
|
15
|
-
if (typeof parameters[0] === 'string') {
|
|
16
|
-
v2 = true
|
|
17
|
-
parameters[0] = parsePhoneNumber(parameters[0], {
|
|
18
|
-
...parameters[1],
|
|
19
|
-
extract: false
|
|
20
|
-
}, metadata)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (parameters.length < 2) {
|
|
24
|
-
// `options` parameter.
|
|
25
|
-
parameters.push(undefined)
|
|
26
|
-
}
|
|
27
|
-
// Set `v2` flag.
|
|
28
|
-
parameters[1] = {
|
|
29
|
-
v2,
|
|
30
|
-
...parameters[1]
|
|
31
|
-
}
|
|
32
|
-
// Add `metadata` parameter.
|
|
33
|
-
parameters.push(metadata)
|
|
34
|
-
// Call the function.
|
|
35
|
-
return _isValidNumber.apply(this, parameters)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
describe('validate', () => {
|
|
39
|
-
it('should validate phone numbers', () => {
|
|
40
|
-
expect(isValidNumber('+1-213-373-4253')).to.equal(true)
|
|
41
|
-
expect(isValidNumber('+1-213-373')).to.equal(false)
|
|
42
|
-
|
|
43
|
-
expect(isValidNumber('+1-213-373-4253', undefined)).to.equal(true)
|
|
44
|
-
|
|
45
|
-
expect(isValidNumber('(213) 373-4253', { defaultCountry: 'US' })).to.equal(true)
|
|
46
|
-
expect(isValidNumber('(213) 37', { defaultCountry: 'US' })).to.equal(false)
|
|
47
|
-
|
|
48
|
-
expect(isValidNumber({ country: 'US', phone: '2133734253' })).to.equal(true)
|
|
49
|
-
|
|
50
|
-
// No "types" info: should return `true`.
|
|
51
|
-
expect(isValidNumber('+380972423740')).to.equal(true)
|
|
52
|
-
|
|
53
|
-
expect(isValidNumber('0912345678', { defaultCountry: 'TW' })).to.equal(true)
|
|
54
|
-
|
|
55
|
-
// Moible numbers starting 07624* are Isle of Man
|
|
56
|
-
// which has its own "country code" "IM"
|
|
57
|
-
// which is in the "GB" "country calling code" zone.
|
|
58
|
-
// So while this number is for "IM" it's still supposed to
|
|
59
|
-
// be valid when passed "GB" as a default country.
|
|
60
|
-
expect(isValidNumber('07624369230', { defaultCountry: 'GB' })).to.equal(true)
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('should refine phone number validation in case extended regular expressions are set for a country', () => {
|
|
64
|
-
// Germany general validation must pass
|
|
65
|
-
expect(isValidNumber('961111111', { defaultCountry: 'UZ' })).to.equal(true)
|
|
66
|
-
|
|
67
|
-
const phoneNumberTypePatterns = metadata.countries.UZ[11]
|
|
68
|
-
|
|
69
|
-
// Different regular expressions for precise national number validation.
|
|
70
|
-
// `types` index in compressed array is `9` for v1.
|
|
71
|
-
// For v2 it's 10.
|
|
72
|
-
// For v3 it's 11.
|
|
73
|
-
metadata.countries.UZ[11] =
|
|
74
|
-
[
|
|
75
|
-
["(?: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}"],
|
|
76
|
-
["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}"]
|
|
77
|
-
]
|
|
78
|
-
|
|
79
|
-
// Extended validation must not pass for an invalid phone number
|
|
80
|
-
expect(isValidNumber('961111111', { defaultCountry: 'UZ' })).to.equal(false)
|
|
81
|
-
|
|
82
|
-
// Extended validation must pass for a valid phone number
|
|
83
|
-
expect(isValidNumber('912345678', { defaultCountry: 'UZ' })).to.equal(true)
|
|
84
|
-
|
|
85
|
-
metadata.countries.UZ[11] = phoneNumberTypePatterns
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
it('should work in edge cases', () => {
|
|
89
|
-
// No metadata
|
|
90
|
-
let thrower = () => _isValidNumber('+78005553535')
|
|
91
|
-
expect(thrower).to.throw('`metadata` argument not passed')
|
|
92
|
-
|
|
93
|
-
// // Non-phone-number characters in a phone number
|
|
94
|
-
// isValidNumber('+499821958a').should.equal(false)
|
|
95
|
-
// isValidNumber('88005553535x', { defaultCountry: 'RU' }).should.equal(false)
|
|
96
|
-
|
|
97
|
-
// Doesn't have `types` regexps in default metadata.
|
|
98
|
-
expect(isValidNumber({ country: 'UA', phone: '300000000' })).to.equal(true)
|
|
99
|
-
expect(isValidNumber({ country: 'UA', phone: '200000000' })).to.equal(false)
|
|
100
|
-
|
|
101
|
-
// // Numerical `value`
|
|
102
|
-
// thrower = () => isValidNumber(88005553535, { defaultCountry: 'RU' })
|
|
103
|
-
// thrower.should.throw('A phone number must either be a string or an object of shape { phone, [country] }.')
|
|
104
|
-
|
|
105
|
-
// Long country phone code
|
|
106
|
-
expect(isValidNumber('+3725555555')).to.equal(true)
|
|
107
|
-
|
|
108
|
-
// // Invalid country
|
|
109
|
-
// thrower = () => isValidNumber({ phone: '8005553535', country: 'RUS' })
|
|
110
|
-
// thrower.should.throw('Unknown country')
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
it('should accept phone number extensions', () => {
|
|
114
|
-
// International
|
|
115
|
-
expect(isValidNumber('+12133734253 ext. 123')).to.equal(true)
|
|
116
|
-
// National
|
|
117
|
-
expect(isValidNumber('88005553535 x123', { defaultCountry: 'RU' })).to.equal(true)
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
it('should validate non-geographic toll-free phone numbers', () => {
|
|
121
|
-
expect(isValidNumber('+80074454123')).to.equal(true)
|
|
122
|
-
})
|
|
123
|
-
})
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import _isValidPhoneNumber from './isValidPhoneNumber.js'
|
|
5
|
-
import metadata from '../metadata.min.json' with { type: 'json' }
|
|
6
|
-
|
|
7
|
-
function isValidPhoneNumber(...parameters) {
|
|
8
|
-
parameters.push(metadata)
|
|
9
|
-
return _isValidPhoneNumber.apply(this, parameters)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
describe('isValidPhoneNumber', () => {
|
|
13
|
-
it('should detect whether a phone number is valid', () => {
|
|
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', { defaultCountry: 'RU' })).to.equal(true)
|
|
18
|
-
expect(isValidPhoneNumber('+7 (800) 555 35 35')).to.equal(true)
|
|
19
|
-
expect(isValidPhoneNumber('+7 1 (800) 555 35 35')).to.equal(false)
|
|
20
|
-
expect(isValidPhoneNumber(' +7 (800) 555 35 35')).to.equal(false)
|
|
21
|
-
expect(isValidPhoneNumber(' ')).to.equal(false)
|
|
22
|
-
})
|
|
23
|
-
})
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
import findNumbers from './findNumbers.js'
|
|
5
|
-
import metadata from '../../metadata.max.json' with { type: 'json' }
|
|
6
|
-
|
|
7
|
-
describe('findNumbers', () => {
|
|
8
|
-
it('should find numbers', () => {
|
|
9
|
-
expect(findNumbers('2133734253', 'US', metadata)).to.deep.equal([{
|
|
10
|
-
phone : '2133734253',
|
|
11
|
-
country : 'US',
|
|
12
|
-
startsAt : 0,
|
|
13
|
-
endsAt : 10
|
|
14
|
-
}])
|
|
15
|
-
|
|
16
|
-
expect(findNumbers('(213) 373-4253', 'US', metadata)).to.deep.equal([{
|
|
17
|
-
phone : '2133734253',
|
|
18
|
-
country : 'US',
|
|
19
|
-
startsAt : 0,
|
|
20
|
-
endsAt : 14
|
|
21
|
-
}])
|
|
22
|
-
|
|
23
|
-
expect(
|
|
24
|
-
findNumbers('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', metadata)
|
|
25
|
-
).to.deep.equal([{
|
|
26
|
-
phone : '8005553535',
|
|
27
|
-
country : 'RU',
|
|
28
|
-
startsAt : 14,
|
|
29
|
-
endsAt : 32
|
|
30
|
-
}, {
|
|
31
|
-
phone : '2133734253',
|
|
32
|
-
country : 'US',
|
|
33
|
-
startsAt : 41,
|
|
34
|
-
endsAt : 55
|
|
35
|
-
}])
|
|
36
|
-
|
|
37
|
-
// Opening parenthesis issue.
|
|
38
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/252
|
|
39
|
-
expect(
|
|
40
|
-
findNumbers('The number is +7 (800) 555-35-35 and not (213) 373-4253 (that\'s not even in the same country!) as written in the document.', 'US', metadata)
|
|
41
|
-
).to.deep.equal([{
|
|
42
|
-
phone : '8005553535',
|
|
43
|
-
country : 'RU',
|
|
44
|
-
startsAt : 14,
|
|
45
|
-
endsAt : 32
|
|
46
|
-
}, {
|
|
47
|
-
phone : '2133734253',
|
|
48
|
-
country : 'US',
|
|
49
|
-
startsAt : 41,
|
|
50
|
-
endsAt : 55
|
|
51
|
-
}])
|
|
52
|
-
|
|
53
|
-
// No default country.
|
|
54
|
-
expect(
|
|
55
|
-
findNumbers('The number is +7 (800) 555-35-35 as written in the document.', metadata)
|
|
56
|
-
).to.deep.equal([{
|
|
57
|
-
phone : '8005553535',
|
|
58
|
-
country : 'RU',
|
|
59
|
-
startsAt : 14,
|
|
60
|
-
endsAt : 32
|
|
61
|
-
}])
|
|
62
|
-
|
|
63
|
-
// Passing `options` and default country.
|
|
64
|
-
expect(
|
|
65
|
-
findNumbers('The number is +7 (800) 555-35-35 as written in the document.', 'US', { leniency: 'VALID' }, metadata)
|
|
66
|
-
).to.deep.equal([{
|
|
67
|
-
phone : '8005553535',
|
|
68
|
-
country : 'RU',
|
|
69
|
-
startsAt : 14,
|
|
70
|
-
endsAt : 32
|
|
71
|
-
}])
|
|
72
|
-
|
|
73
|
-
// Passing `options`.
|
|
74
|
-
expect(
|
|
75
|
-
findNumbers('The number is +7 (800) 555-35-35 as written in the document.', { leniency: 'VALID' }, metadata)
|
|
76
|
-
).to.deep.equal([{
|
|
77
|
-
phone : '8005553535',
|
|
78
|
-
country : 'RU',
|
|
79
|
-
startsAt : 14,
|
|
80
|
-
endsAt : 32
|
|
81
|
-
}])
|
|
82
|
-
|
|
83
|
-
// Not a phone number and a phone number.
|
|
84
|
-
expect(
|
|
85
|
-
findNumbers('Digits 12 are not a number, but +7 (800) 555-35-35 is.', { leniency: 'VALID' }, metadata)
|
|
86
|
-
).to.deep.equal([{
|
|
87
|
-
phone : '8005553535',
|
|
88
|
-
country : 'RU',
|
|
89
|
-
startsAt : 32,
|
|
90
|
-
endsAt : 50
|
|
91
|
-
}])
|
|
92
|
-
|
|
93
|
-
// Phone number extension.
|
|
94
|
-
expect(
|
|
95
|
-
findNumbers('Date 02/17/2018 is not a number, but +7 (800) 555-35-35 ext. 123 is.', { leniency: 'VALID' }, metadata)
|
|
96
|
-
).to.deep.equal([{
|
|
97
|
-
phone : '8005553535',
|
|
98
|
-
country : 'RU',
|
|
99
|
-
ext : '123',
|
|
100
|
-
startsAt : 37,
|
|
101
|
-
endsAt : 64
|
|
102
|
-
}])
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('should find numbers (v2)', () => {
|
|
106
|
-
const phoneNumbers = findNumbers('The number is +7 (800) 555-35-35 ext. 1234 and not (213) 373-4253 as written in the document.', 'US', { v2: true }, metadata)
|
|
107
|
-
|
|
108
|
-
expect(phoneNumbers.length).to.equal(2)
|
|
109
|
-
|
|
110
|
-
expect(phoneNumbers[0].startsAt).to.equal(14)
|
|
111
|
-
expect(phoneNumbers[0].endsAt).to.equal(42)
|
|
112
|
-
|
|
113
|
-
expect(phoneNumbers[0].number.number).to.equal('+78005553535')
|
|
114
|
-
expect(phoneNumbers[0].number.nationalNumber).to.equal('8005553535')
|
|
115
|
-
expect(phoneNumbers[0].number.country).to.equal('RU')
|
|
116
|
-
expect(phoneNumbers[0].number.countryCallingCode).to.equal('7')
|
|
117
|
-
expect(phoneNumbers[0].number.ext).to.equal('1234')
|
|
118
|
-
|
|
119
|
-
expect(phoneNumbers[1].startsAt).to.equal(51)
|
|
120
|
-
expect(phoneNumbers[1].endsAt).to.equal(65)
|
|
121
|
-
|
|
122
|
-
expect(phoneNumbers[1].number.number).to.equal('+12133734253')
|
|
123
|
-
expect(phoneNumbers[1].number.nationalNumber).to.equal('2133734253')
|
|
124
|
-
expect(phoneNumbers[1].number.country).to.equal('US')
|
|
125
|
-
expect(phoneNumbers[1].number.countryCallingCode).to.equal('1')
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
it('shouldn\'t find non-valid numbers', () => {
|
|
129
|
-
// Not a valid phone number for US.
|
|
130
|
-
expect(findNumbers('1111111111', 'US', metadata)).to.deep.equal([])
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
it('should find non-European digits', () => {
|
|
134
|
-
// E.g. in Iraq they don't write `+442323234` but rather `+٤٤٢٣٢٣٢٣٤`.
|
|
135
|
-
expect(findNumbers('العَرَبِيَّة +٤٤٣٣٣٣٣٣٣٣٣٣عَرَبِيّ', metadata)).to.deep.equal([{
|
|
136
|
-
country : 'GB',
|
|
137
|
-
phone : '3333333333',
|
|
138
|
-
startsAt : 14,
|
|
139
|
-
endsAt : 27
|
|
140
|
-
}])
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
it('should work in edge cases', () => {
|
|
144
|
-
let thrower
|
|
145
|
-
|
|
146
|
-
// No input
|
|
147
|
-
expect(findNumbers('', metadata)).to.deep.equal([])
|
|
148
|
-
|
|
149
|
-
// // No country metadata for this `require` country code
|
|
150
|
-
// thrower = () => findNumbers('123', 'ZZ', metadata)
|
|
151
|
-
// thrower.should.throw('Unknown country')
|
|
152
|
-
|
|
153
|
-
// Numerical `value`
|
|
154
|
-
thrower = () => findNumbers(2141111111, 'US')
|
|
155
|
-
expect(thrower).to.throw('A text for parsing must be a string.')
|
|
156
|
-
|
|
157
|
-
// // No metadata
|
|
158
|
-
// thrower = () => findNumbers('')
|
|
159
|
-
// thrower.should.throw('`metadata` argument not passed')
|
|
160
|
-
|
|
161
|
-
// No metadata, no default country, no phone numbers.
|
|
162
|
-
expect(findNumbers('')).to.deep.equal([])
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
it('should find international numbers when passed a non-existent default country', () => {
|
|
166
|
-
const numbers = findNumbers('Phone: +7 (800) 555 35 35. National: 8 (800) 555-55-55', { defaultCountry: 'XX', v2: true }, metadata)
|
|
167
|
-
expect(numbers.length).to.equal(1)
|
|
168
|
-
expect(numbers[0].number.nationalNumber).to.equal('8005553535')
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
it('shouldn\'t find phone numbers which are not phone numbers', () => {
|
|
172
|
-
// A timestamp.
|
|
173
|
-
expect(findNumbers('2012-01-02 08:00', 'US', metadata)).to.deep.equal([])
|
|
174
|
-
|
|
175
|
-
// A valid number (not a complete timestamp).
|
|
176
|
-
expect(findNumbers('2012-01-02 08', 'US', metadata)).to.deep.equal([{
|
|
177
|
-
country : 'US',
|
|
178
|
-
phone : '2012010208',
|
|
179
|
-
startsAt : 0,
|
|
180
|
-
endsAt : 13
|
|
181
|
-
}])
|
|
182
|
-
|
|
183
|
-
// Invalid parens.
|
|
184
|
-
expect(findNumbers('213(3734253', 'US', metadata)).to.deep.equal([])
|
|
185
|
-
|
|
186
|
-
// Letters after phone number.
|
|
187
|
-
expect(findNumbers('2133734253a', 'US', metadata)).to.deep.equal([])
|
|
188
|
-
|
|
189
|
-
// Valid phone (same as the one found in the UUID below).
|
|
190
|
-
expect(findNumbers('The phone number is 231354125.', 'FR', metadata)).to.deep.equal([{
|
|
191
|
-
country : 'FR',
|
|
192
|
-
phone : '231354125',
|
|
193
|
-
startsAt : 20,
|
|
194
|
-
endsAt : 29
|
|
195
|
-
}])
|
|
196
|
-
|
|
197
|
-
// Not a phone number (part of a UUID).
|
|
198
|
-
// Should parse in `{ extended: true }` mode.
|
|
199
|
-
const possibleNumbers = findNumbers('The UUID is CA801c26f98cd16e231354125ad046e40b.', 'FR', { extended: true }, metadata)
|
|
200
|
-
expect(possibleNumbers.length).to.equal(1)
|
|
201
|
-
expect(possibleNumbers[0].country).to.equal('FR')
|
|
202
|
-
expect(possibleNumbers[0].phone).to.equal('231354125')
|
|
203
|
-
|
|
204
|
-
// Not a phone number (part of a UUID).
|
|
205
|
-
// Shouldn't parse by default.
|
|
206
|
-
expect(
|
|
207
|
-
findNumbers('The UUID is CA801c26f98cd16e231354125ad046e40b.', 'FR', metadata)
|
|
208
|
-
).to.deep.equal([])
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
// https://gitlab.com/catamphetamine/libphonenumber-js/-/merge_requests/4
|
|
212
|
-
it('should return correct `startsAt` and `endsAt` when matching "inner" candidates in a could-be-a-candidate substring', () => {
|
|
213
|
-
expect(findNumbers('39945926 77200596 16533084', 'ID', metadata)).to.deep.equal([{
|
|
214
|
-
country: 'ID',
|
|
215
|
-
phone: '77200596',
|
|
216
|
-
startsAt: 9,
|
|
217
|
-
endsAt: 17
|
|
218
|
-
}])
|
|
219
|
-
})
|
|
220
|
-
})
|