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.
- package/CHANGELOG.md +32 -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,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
|
-
})
|