libphonenumber-js 1.12.40 → 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 +12 -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
package/es6/PhoneNumber.test.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import metadata from '../metadata.min.json' with { type: 'json' };
|
|
4
|
-
import PhoneNumber from './PhoneNumber.js';
|
|
5
|
-
describe('PhoneNumber', function () {
|
|
6
|
-
it('should create a phone number via a public constructor', function () {
|
|
7
|
-
var phoneNumber = new PhoneNumber('+78005553535', metadata);
|
|
8
|
-
phoneNumber.setExt('1234');
|
|
9
|
-
expect(phoneNumber.country).to.be.undefined;
|
|
10
|
-
expect(phoneNumber.countryCallingCode).to.equal('7');
|
|
11
|
-
expect(phoneNumber.nationalNumber).to.equal('8005553535');
|
|
12
|
-
expect(phoneNumber.formatNational()).to.equal('8 (800) 555-35-35 ext. 1234');
|
|
13
|
-
});
|
|
14
|
-
it('should validate constructor arguments (public constructor)', function () {
|
|
15
|
-
expect(function () {
|
|
16
|
-
return new PhoneNumber();
|
|
17
|
-
}).to["throw"]('argument is required');
|
|
18
|
-
expect(function () {
|
|
19
|
-
return new PhoneNumber(undefined, metadata);
|
|
20
|
-
}).to["throw"]('argument is required');
|
|
21
|
-
expect(function () {
|
|
22
|
-
return new PhoneNumber('7', metadata);
|
|
23
|
-
}).to["throw"]('must consist of a "+"');
|
|
24
|
-
expect(function () {
|
|
25
|
-
return new PhoneNumber('+7', metadata);
|
|
26
|
-
}).to["throw"]('too short');
|
|
27
|
-
expect(function () {
|
|
28
|
-
return new PhoneNumber('+7800');
|
|
29
|
-
}).to["throw"]('`metadata` argument not passed');
|
|
30
|
-
expect(function () {
|
|
31
|
-
return new PhoneNumber(1234567890);
|
|
32
|
-
}).to["throw"]('must be a string');
|
|
33
|
-
expect(function () {
|
|
34
|
-
return new PhoneNumber('+1', 1234567890);
|
|
35
|
-
}).to["throw"]('must be a string');
|
|
36
|
-
});
|
|
37
|
-
it('should validate constructor arguments (private constructor)', function () {
|
|
38
|
-
expect(function () {
|
|
39
|
-
return new PhoneNumber(undefined, '800', metadata);
|
|
40
|
-
}).to["throw"]('First argument is required');
|
|
41
|
-
expect(function () {
|
|
42
|
-
return new PhoneNumber('7', undefined, metadata);
|
|
43
|
-
}).to["throw"]('`nationalNumber` argument is required');
|
|
44
|
-
expect(function () {
|
|
45
|
-
return new PhoneNumber('7', '8005553535');
|
|
46
|
-
}).to["throw"]('`metadata` argument not passed');
|
|
47
|
-
});
|
|
48
|
-
it('should accept country code argument', function () {
|
|
49
|
-
var phoneNumber = new PhoneNumber('RU', '8005553535', metadata);
|
|
50
|
-
expect(phoneNumber.countryCallingCode).to.equal('7');
|
|
51
|
-
expect(phoneNumber.country).to.equal('RU');
|
|
52
|
-
expect(phoneNumber.number).to.equal('+78005553535');
|
|
53
|
-
});
|
|
54
|
-
it('should format number with options', function () {
|
|
55
|
-
var phoneNumber = new PhoneNumber('7', '8005553535', metadata);
|
|
56
|
-
phoneNumber.ext = '123';
|
|
57
|
-
expect(phoneNumber.format('NATIONAL', {
|
|
58
|
-
formatExtension: function formatExtension(number, extension) {
|
|
59
|
-
return "".concat(number, " \u0434\u043E\u0431. ").concat(extension);
|
|
60
|
-
}
|
|
61
|
-
})).to.equal('8 (800) 555-35-35 доб. 123');
|
|
62
|
-
});
|
|
63
|
-
it('should compare phone numbers', function () {
|
|
64
|
-
expect(new PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('RU', '8005553535', metadata))).to.equal(true);
|
|
65
|
-
expect(new PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('7', '8005553535', metadata))).to.equal(true);
|
|
66
|
-
expect(new PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('RU', '8005553536', metadata))).to.equal(false);
|
|
67
|
-
});
|
|
68
|
-
it('should tell if a number is non-geographic', function () {
|
|
69
|
-
expect(new PhoneNumber('7', '8005553535', metadata).isNonGeographic()).to.equal(false);
|
|
70
|
-
expect(new PhoneNumber('870', '773111632', metadata).isNonGeographic()).to.equal(true);
|
|
71
|
-
});
|
|
72
|
-
it('should allow setting extension', function () {
|
|
73
|
-
var phoneNumber = new PhoneNumber('1', '2133734253', metadata);
|
|
74
|
-
phoneNumber.setExt('1234');
|
|
75
|
-
expect(phoneNumber.ext).to.equal('1234');
|
|
76
|
-
expect(phoneNumber.formatNational()).to.equal('(213) 373-4253 ext. 1234');
|
|
77
|
-
});
|
|
78
|
-
it('should return possible countries', function () {
|
|
79
|
-
// "599": [
|
|
80
|
-
// "CW", // "possible_lengths": [7, 8]
|
|
81
|
-
// "BQ" // "possible_lengths": [7]
|
|
82
|
-
// ]
|
|
83
|
-
|
|
84
|
-
var phoneNumber = new PhoneNumber('599', '123456', metadata);
|
|
85
|
-
expect(phoneNumber.country).to.be.undefined;
|
|
86
|
-
expect(phoneNumber.getPossibleCountries()).to.deep.equal([]);
|
|
87
|
-
phoneNumber = new PhoneNumber('599', '1234567', metadata);
|
|
88
|
-
expect(phoneNumber.country).to.be.undefined;
|
|
89
|
-
expect(phoneNumber.getPossibleCountries()).to.deep.equal(['CW', 'BQ']);
|
|
90
|
-
phoneNumber = new PhoneNumber('599', '12345678', metadata);
|
|
91
|
-
expect(phoneNumber.country).to.be.undefined;
|
|
92
|
-
expect(phoneNumber.getPossibleCountries()).to.deep.equal(['CW']);
|
|
93
|
-
phoneNumber = new PhoneNumber('599', '123456789', metadata);
|
|
94
|
-
expect(phoneNumber.country).to.be.undefined;
|
|
95
|
-
expect(phoneNumber.getPossibleCountries()).to.deep.equal([]);
|
|
96
|
-
});
|
|
97
|
-
it('should return possible countries in case of ambiguity', function () {
|
|
98
|
-
var phoneNumber = new PhoneNumber('1', '2223334444', metadata);
|
|
99
|
-
expect(phoneNumber.country).to.be.undefined;
|
|
100
|
-
expect(phoneNumber.getPossibleCountries().indexOf('US')).to.equal(0);
|
|
101
|
-
expect(phoneNumber.getPossibleCountries().length).to.equal(25);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
// it('should return empty possible countries when no national number has been input', () => {
|
|
105
|
-
// const phoneNumber = new PhoneNumber('1', '', metadata)
|
|
106
|
-
// expect(phoneNumber.country).toBe.undefined
|
|
107
|
-
// phoneNumber.getPossibleCountries().should.deep.equal([])
|
|
108
|
-
// })
|
|
109
|
-
|
|
110
|
-
it('should return empty possible countries when not enough national number digits have been input', function () {
|
|
111
|
-
var phoneNumber = new PhoneNumber('1', '222', metadata);
|
|
112
|
-
expect(phoneNumber.country).to.be.undefined;
|
|
113
|
-
expect(phoneNumber.getPossibleCountries()).to.deep.equal([]);
|
|
114
|
-
});
|
|
115
|
-
it('should return possible countries in case of no ambiguity', function () {
|
|
116
|
-
var phoneNumber = new PhoneNumber('US', '2133734253', metadata);
|
|
117
|
-
expect(phoneNumber.country).to.equal('US');
|
|
118
|
-
expect(phoneNumber.getPossibleCountries()).to.deep.equal(['US']);
|
|
119
|
-
});
|
|
120
|
-
it('should return empty possible countries in case of an unknown calling code', function () {
|
|
121
|
-
var phoneNumber = new PhoneNumber('777', '123', metadata);
|
|
122
|
-
expect(phoneNumber.country).to.be.undefined;
|
|
123
|
-
expect(phoneNumber.getPossibleCountries()).to.deep.equal([]);
|
|
124
|
-
});
|
|
125
|
-
it('should determine phone number type', function () {
|
|
126
|
-
var phoneNumber = new PhoneNumber('US', '2015550000', metadata);
|
|
127
|
-
expect(phoneNumber.getType()).to.equal('FIXED_LINE_OR_MOBILE');
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
// it('should validate phone number length', () => {
|
|
131
|
-
// const phoneNumber = new PhoneNumber('RU', '800', metadata)
|
|
132
|
-
// expect(phoneNumber.validateLength()).to.equal('TOO_SHORT')
|
|
133
|
-
//
|
|
134
|
-
// const phoneNumberValid = new PhoneNumber('RU', '8005553535', metadata)
|
|
135
|
-
// expect(phoneNumberValid.validateLength()).toBe.undefined
|
|
136
|
-
// })
|
|
137
|
-
});
|
|
138
|
-
//# sourceMappingURL=PhoneNumber.test.js.map
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import PhoneNumberMatcher from './PhoneNumberMatcher.js';
|
|
4
|
-
import metadata from '../metadata.min.json' with { type: 'json' };
|
|
5
|
-
function test(text, defaultCountry, expectedNumbers) {
|
|
6
|
-
if (typeof expectedNumbers === 'string') {
|
|
7
|
-
expectedNumbers = [{
|
|
8
|
-
nationalNumber: expectedNumbers
|
|
9
|
-
}];
|
|
10
|
-
}
|
|
11
|
-
var matcher = new PhoneNumberMatcher(text, {
|
|
12
|
-
defaultCountry: defaultCountry,
|
|
13
|
-
v2: true
|
|
14
|
-
}, metadata);
|
|
15
|
-
while (matcher.hasNext()) {
|
|
16
|
-
var number = matcher.next();
|
|
17
|
-
var phoneNumber = expectedNumbers.shift();
|
|
18
|
-
if (phoneNumber.startsAt !== undefined) {
|
|
19
|
-
expect(number.startsAt).to.equal(phoneNumber.startsAt);
|
|
20
|
-
}
|
|
21
|
-
if (phoneNumber.endsAt !== undefined) {
|
|
22
|
-
expect(number.endsAt).to.equal(phoneNumber.endsAt);
|
|
23
|
-
}
|
|
24
|
-
expect(number.number.country).to.equal(phoneNumber.country || defaultCountry);
|
|
25
|
-
expect(number.number.nationalNumber).to.equal(phoneNumber.nationalNumber);
|
|
26
|
-
}
|
|
27
|
-
expect(expectedNumbers.length).to.equal(0);
|
|
28
|
-
}
|
|
29
|
-
describe('PhoneNumberMatcher', function () {
|
|
30
|
-
it('should find phone numbers', function () {
|
|
31
|
-
test('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', [{
|
|
32
|
-
country: 'RU',
|
|
33
|
-
nationalNumber: '8005553535',
|
|
34
|
-
startsAt: 14,
|
|
35
|
-
endsAt: 32
|
|
36
|
-
}, {
|
|
37
|
-
country: 'US',
|
|
38
|
-
nationalNumber: '2133734253',
|
|
39
|
-
startsAt: 41,
|
|
40
|
-
endsAt: 55
|
|
41
|
-
}]);
|
|
42
|
-
});
|
|
43
|
-
it('should find phone numbers from Mexico', function () {
|
|
44
|
-
// Test parsing fixed-line numbers of Mexico.
|
|
45
|
-
test('+52 (449)978-0001', 'MX', '4499780001');
|
|
46
|
-
test('01 (449)978-0001', 'MX', '4499780001');
|
|
47
|
-
test('(449)978-0001', 'MX', '4499780001');
|
|
48
|
-
|
|
49
|
-
// "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
|
|
50
|
-
// no longer valid since August 2019."
|
|
51
|
-
// // Test parsing mobile numbers of Mexico.
|
|
52
|
-
// test('+52 1 33 1234-5678', 'MX', '3312345678')
|
|
53
|
-
// test('044 (33) 1234-5678', 'MX', '3312345678')
|
|
54
|
-
// test('045 33 1234-5678', 'MX', '3312345678')
|
|
55
|
-
});
|
|
56
|
-
it('should find phone numbers from Argentina', function () {
|
|
57
|
-
// Test parsing mobile numbers of Argentina.
|
|
58
|
-
test('+54 9 343 555 1212', 'AR', '93435551212');
|
|
59
|
-
test('0343 15-555-1212', 'AR', '93435551212');
|
|
60
|
-
test('+54 9 3715 65 4320', 'AR', '93715654320');
|
|
61
|
-
test('03715 15 65 4320', 'AR', '93715654320');
|
|
62
|
-
|
|
63
|
-
// Test parsing fixed-line numbers of Argentina.
|
|
64
|
-
test('+54 11 3797 0000', 'AR', '1137970000');
|
|
65
|
-
test('011 3797 0000', 'AR', '1137970000');
|
|
66
|
-
test('+54 3715 65 4321', 'AR', '3715654321');
|
|
67
|
-
test('03715 65 4321', 'AR', '3715654321');
|
|
68
|
-
test('+54 23 1234 0000', 'AR', '2312340000');
|
|
69
|
-
test('023 1234 0000', 'AR', '2312340000');
|
|
70
|
-
});
|
|
71
|
-
it('should only support the supported leniency values', function () {
|
|
72
|
-
expect(function () {
|
|
73
|
-
return new PhoneNumberMatcher('+54 23 1234 0000', {
|
|
74
|
-
leniency: 'STRICT_GROUPING',
|
|
75
|
-
v2: true
|
|
76
|
-
}, metadata);
|
|
77
|
-
}).to["throw"]('Supported values: "POSSIBLE", "VALID".');
|
|
78
|
-
});
|
|
79
|
-
it('should validate input parameters', function () {
|
|
80
|
-
// expect(() => new PhoneNumberMatcher('+54 23 1234 0000', { v2: true }, metadata)).to.throw('`leniency` is required')
|
|
81
|
-
expect(function () {
|
|
82
|
-
return new PhoneNumberMatcher('+54 23 1234 0000', {
|
|
83
|
-
leniency: '???',
|
|
84
|
-
v2: true
|
|
85
|
-
}, metadata);
|
|
86
|
-
}).to["throw"]('Unknown leniency: "???"');
|
|
87
|
-
expect(function () {
|
|
88
|
-
return new PhoneNumberMatcher('+54 23 1234 0000', {
|
|
89
|
-
maxTries: -1,
|
|
90
|
-
v2: true
|
|
91
|
-
}, metadata);
|
|
92
|
-
}).to["throw"]('`maxTries` must be `>= 0`');
|
|
93
|
-
});
|
|
94
|
-
it('should throw when calling `.next()` and there\'s no next match', function () {
|
|
95
|
-
var matcher = new PhoneNumberMatcher('+54 23 1234 0000', {
|
|
96
|
-
v2: true
|
|
97
|
-
}, metadata);
|
|
98
|
-
matcher.next();
|
|
99
|
-
expect(function () {
|
|
100
|
-
return matcher.next();
|
|
101
|
-
}).to["throw"]('No next element');
|
|
102
|
-
});
|
|
103
|
-
it('should find phone numbers that are separated by a slash', function () {
|
|
104
|
-
var matcher = new PhoneNumberMatcher('651-234-2345/332-445-1234', {
|
|
105
|
-
defaultCountry: 'US',
|
|
106
|
-
v2: true
|
|
107
|
-
}, metadata);
|
|
108
|
-
expect(matcher.hasNext()).to.equal(true);
|
|
109
|
-
var number1 = matcher.next();
|
|
110
|
-
expect(number1.startsAt).to.equal(0);
|
|
111
|
-
expect(number1.number.number).to.equal('+16512342345');
|
|
112
|
-
expect(matcher.hasNext()).to.equal(true);
|
|
113
|
-
var number2 = matcher.next();
|
|
114
|
-
expect(number2.startsAt).to.equal(13);
|
|
115
|
-
expect(number2.number.number).to.equal('+13324451234');
|
|
116
|
-
expect(matcher.hasNext()).to.equal(false);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
//# sourceMappingURL=PhoneNumberMatcher.test.js.map
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import { limit, trimAfterFirstMatch, startsWith, endsWith } from './util.js';
|
|
4
|
-
describe('findNumbers/util', function () {
|
|
5
|
-
it('should generate regexp limit', function () {
|
|
6
|
-
var thrower = function thrower() {
|
|
7
|
-
return limit(1, 0);
|
|
8
|
-
};
|
|
9
|
-
expect(thrower).to["throw"]();
|
|
10
|
-
thrower = function thrower() {
|
|
11
|
-
return limit(-1, 1);
|
|
12
|
-
};
|
|
13
|
-
expect(thrower).to["throw"]();
|
|
14
|
-
thrower = function thrower() {
|
|
15
|
-
return limit(0, 0);
|
|
16
|
-
};
|
|
17
|
-
expect(thrower).to["throw"]();
|
|
18
|
-
});
|
|
19
|
-
it('should trimAfterFirstMatch', function () {
|
|
20
|
-
expect(trimAfterFirstMatch(/\d/, 'abc123')).to.equal('abc');
|
|
21
|
-
expect(trimAfterFirstMatch(/\d/, 'abc')).to.equal('abc');
|
|
22
|
-
});
|
|
23
|
-
it('should determine if a string starts with a substring', function () {
|
|
24
|
-
expect(startsWith('𐍈123', '𐍈')).to.equal(true);
|
|
25
|
-
expect(startsWith('1𐍈', '𐍈')).to.equal(false);
|
|
26
|
-
});
|
|
27
|
-
it('should determine if a string ends with a substring', function () {
|
|
28
|
-
expect(endsWith('123𐍈', '𐍈')).to.equal(true);
|
|
29
|
-
expect(endsWith('𐍈1', '𐍈')).to.equal(false);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
//# sourceMappingURL=util.test.js.map
|
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import findPhoneNumbersInText from './findPhoneNumbersInText.js';
|
|
4
|
-
import metadata from '../metadata.min.json' with { type: 'json' };
|
|
5
|
-
import metadataMax from '../metadata.max.json' with { type: 'json' };
|
|
6
|
-
function findPhoneNumbersInTextWithResults(input, options, metadata) {
|
|
7
|
-
var results = findPhoneNumbersInText(input, options, metadata);
|
|
8
|
-
return results.map(function (result) {
|
|
9
|
-
var startsAt = result.startsAt,
|
|
10
|
-
endsAt = result.endsAt,
|
|
11
|
-
number = result.number;
|
|
12
|
-
var data = {
|
|
13
|
-
phone: number.nationalNumber,
|
|
14
|
-
startsAt: startsAt,
|
|
15
|
-
endsAt: endsAt
|
|
16
|
-
};
|
|
17
|
-
if (number.country) {
|
|
18
|
-
data.country = number.country;
|
|
19
|
-
}
|
|
20
|
-
if (number.ext) {
|
|
21
|
-
data.ext = number.ext;
|
|
22
|
-
}
|
|
23
|
-
return data;
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
describe('findPhoneNumbersInText', function () {
|
|
27
|
-
it('should find phone numbers in text (with default country)', function () {
|
|
28
|
-
expect(findPhoneNumbersInText('+7 (800) 555-35-35', 'US', metadata)[0].number.number).to.equal('+78005553535');
|
|
29
|
-
});
|
|
30
|
-
it('should find phone numbers in text (with default country in options)', function () {
|
|
31
|
-
expect(findPhoneNumbersInText('+7 (800) 555-35-35', {
|
|
32
|
-
defaultCountry: 'US'
|
|
33
|
-
}, metadata)[0].number.number).to.equal('+78005553535');
|
|
34
|
-
});
|
|
35
|
-
it('should find phone numbers in text (with default country and options)', function () {
|
|
36
|
-
expect(findPhoneNumbersInText('+7 (800) 555-35-35', 'US', {}, metadata)[0].number.number).to.equal('+78005553535');
|
|
37
|
-
});
|
|
38
|
-
it('should find phone numbers in text (without default country, with options)', function () {
|
|
39
|
-
expect(findPhoneNumbersInText('+7 (800) 555-35-35', undefined, {}, metadata)[0].number.number).to.equal('+78005553535');
|
|
40
|
-
});
|
|
41
|
-
it('should find phone numbers in text (with default country, without options)', function () {
|
|
42
|
-
expect(findPhoneNumbersInText('+7 (800) 555-35-35', 'US', undefined, metadata)[0].number.number).to.equal('+78005553535');
|
|
43
|
-
});
|
|
44
|
-
it('should find phone numbers in text (with empty default country)', function () {
|
|
45
|
-
expect(findPhoneNumbersInText('+7 (800) 555-35-35', undefined, metadata)[0].number.number).to.equal('+78005553535');
|
|
46
|
-
});
|
|
47
|
-
it('should find phone numbers in text', function () {
|
|
48
|
-
var NUMBERS = ['+78005553535', '+12133734253'];
|
|
49
|
-
var results = findPhoneNumbersInText('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', metadata);
|
|
50
|
-
var i = 0;
|
|
51
|
-
while (i < results.length) {
|
|
52
|
-
expect(results[i].number.number).to.equal(NUMBERS[i]);
|
|
53
|
-
i++;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
it('should find phone numbers in text (default country calling code)', function () {
|
|
57
|
-
var NUMBERS = ['+870773111632'];
|
|
58
|
-
var results = findPhoneNumbersInText('The number is 773 111 632', {
|
|
59
|
-
defaultCallingCode: '870'
|
|
60
|
-
}, metadata);
|
|
61
|
-
var i = 0;
|
|
62
|
-
while (i < results.length) {
|
|
63
|
-
expect(results[i].number.number).to.equal(NUMBERS[i]);
|
|
64
|
-
i++;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
it('should find numbers', function () {
|
|
68
|
-
expect(findPhoneNumbersInTextWithResults('2133734253', {
|
|
69
|
-
defaultCountry: 'US'
|
|
70
|
-
}, metadata)).to.deep.equal([{
|
|
71
|
-
phone: '2133734253',
|
|
72
|
-
country: 'US',
|
|
73
|
-
startsAt: 0,
|
|
74
|
-
endsAt: 10
|
|
75
|
-
}]);
|
|
76
|
-
expect(findPhoneNumbersInTextWithResults('(213) 373-4253', {
|
|
77
|
-
defaultCountry: 'US'
|
|
78
|
-
}, metadata)).to.deep.equal([{
|
|
79
|
-
phone: '2133734253',
|
|
80
|
-
country: 'US',
|
|
81
|
-
startsAt: 0,
|
|
82
|
-
endsAt: 14
|
|
83
|
-
}]);
|
|
84
|
-
expect(findPhoneNumbersInTextWithResults('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', {
|
|
85
|
-
defaultCountry: 'US'
|
|
86
|
-
}, metadata)).to.deep.equal([{
|
|
87
|
-
phone: '8005553535',
|
|
88
|
-
country: 'RU',
|
|
89
|
-
startsAt: 14,
|
|
90
|
-
endsAt: 32
|
|
91
|
-
}, {
|
|
92
|
-
phone: '2133734253',
|
|
93
|
-
country: 'US',
|
|
94
|
-
startsAt: 41,
|
|
95
|
-
endsAt: 55
|
|
96
|
-
}]);
|
|
97
|
-
|
|
98
|
-
// Opening parenthesis issue.
|
|
99
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/252
|
|
100
|
-
expect(findPhoneNumbersInTextWithResults('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.', {
|
|
101
|
-
defaultCountry: 'US'
|
|
102
|
-
}, metadata)).to.deep.equal([{
|
|
103
|
-
phone: '8005553535',
|
|
104
|
-
country: 'RU',
|
|
105
|
-
startsAt: 14,
|
|
106
|
-
endsAt: 32
|
|
107
|
-
}, {
|
|
108
|
-
phone: '2133734253',
|
|
109
|
-
country: 'US',
|
|
110
|
-
startsAt: 41,
|
|
111
|
-
endsAt: 55
|
|
112
|
-
}]);
|
|
113
|
-
|
|
114
|
-
// No default country.
|
|
115
|
-
expect(findPhoneNumbersInTextWithResults('The number is +7 (800) 555-35-35 as written in the document.', undefined, metadata)).to.deep.equal([{
|
|
116
|
-
phone: '8005553535',
|
|
117
|
-
country: 'RU',
|
|
118
|
-
startsAt: 14,
|
|
119
|
-
endsAt: 32
|
|
120
|
-
}]);
|
|
121
|
-
|
|
122
|
-
// Passing `options` and default country.
|
|
123
|
-
expect(findPhoneNumbersInTextWithResults('The number is +7 (800) 555-35-35 as written in the document.', {
|
|
124
|
-
defaultCountry: 'US',
|
|
125
|
-
leniency: 'VALID'
|
|
126
|
-
}, metadata)).to.deep.equal([{
|
|
127
|
-
phone: '8005553535',
|
|
128
|
-
country: 'RU',
|
|
129
|
-
startsAt: 14,
|
|
130
|
-
endsAt: 32
|
|
131
|
-
}]);
|
|
132
|
-
|
|
133
|
-
// Passing `options`.
|
|
134
|
-
expect(findPhoneNumbersInTextWithResults('The number is +7 (800) 555-35-35 as written in the document.', {
|
|
135
|
-
leniency: 'VALID'
|
|
136
|
-
}, metadata)).to.deep.equal([{
|
|
137
|
-
phone: '8005553535',
|
|
138
|
-
country: 'RU',
|
|
139
|
-
startsAt: 14,
|
|
140
|
-
endsAt: 32
|
|
141
|
-
}]);
|
|
142
|
-
|
|
143
|
-
// Not a phone number and a phone number.
|
|
144
|
-
expect(findPhoneNumbersInTextWithResults('Digits 12 are not a number, but +7 (800) 555-35-35 is.', {
|
|
145
|
-
leniency: 'VALID'
|
|
146
|
-
}, metadata)).to.deep.equal([{
|
|
147
|
-
phone: '8005553535',
|
|
148
|
-
country: 'RU',
|
|
149
|
-
startsAt: 32,
|
|
150
|
-
endsAt: 50
|
|
151
|
-
}]);
|
|
152
|
-
|
|
153
|
-
// Phone number extension.
|
|
154
|
-
expect(findPhoneNumbersInTextWithResults('Date 02/17/2018 is not a number, but +7 (800) 555-35-35 ext. 123 is.', {
|
|
155
|
-
leniency: 'VALID'
|
|
156
|
-
}, metadata)).to.deep.equal([{
|
|
157
|
-
phone: '8005553535',
|
|
158
|
-
country: 'RU',
|
|
159
|
-
ext: '123',
|
|
160
|
-
startsAt: 37,
|
|
161
|
-
endsAt: 64
|
|
162
|
-
}]);
|
|
163
|
-
});
|
|
164
|
-
it('should find numbers (v2)', function () {
|
|
165
|
-
var phoneNumbers = findPhoneNumbersInText('The number is +7 (800) 555-35-35 ext. 1234 and not (213) 373-4253 as written in the document.', {
|
|
166
|
-
defaultCountry: 'US',
|
|
167
|
-
v2: true
|
|
168
|
-
}, metadata);
|
|
169
|
-
expect(phoneNumbers.length).to.equal(2);
|
|
170
|
-
expect(phoneNumbers[0].startsAt).to.equal(14);
|
|
171
|
-
expect(phoneNumbers[0].endsAt).to.equal(42);
|
|
172
|
-
expect(phoneNumbers[0].number.number).to.equal('+78005553535');
|
|
173
|
-
expect(phoneNumbers[0].number.nationalNumber).to.equal('8005553535');
|
|
174
|
-
expect(phoneNumbers[0].number.country).to.equal('RU');
|
|
175
|
-
expect(phoneNumbers[0].number.countryCallingCode).to.equal('7');
|
|
176
|
-
expect(phoneNumbers[0].number.ext).to.equal('1234');
|
|
177
|
-
expect(phoneNumbers[1].startsAt).to.equal(51);
|
|
178
|
-
expect(phoneNumbers[1].endsAt).to.equal(65);
|
|
179
|
-
expect(phoneNumbers[1].number.number).to.equal('+12133734253');
|
|
180
|
-
expect(phoneNumbers[1].number.nationalNumber).to.equal('2133734253');
|
|
181
|
-
expect(phoneNumbers[1].number.country).to.equal('US');
|
|
182
|
-
expect(phoneNumbers[1].number.countryCallingCode).to.equal('1');
|
|
183
|
-
});
|
|
184
|
-
it('shouldn\'t find non-valid numbers', function () {
|
|
185
|
-
// Not a valid phone number for US.
|
|
186
|
-
expect(findPhoneNumbersInTextWithResults('1111111111', {
|
|
187
|
-
defaultCountry: 'US'
|
|
188
|
-
}, metadata)).to.deep.equal([]);
|
|
189
|
-
});
|
|
190
|
-
it('should find non-European digits', function () {
|
|
191
|
-
// E.g. in Iraq they don't write `+442323234` but rather `+٤٤٢٣٢٣٢٣٤`.
|
|
192
|
-
expect(findPhoneNumbersInTextWithResults('العَرَبِيَّة +٤٤٣٣٣٣٣٣٣٣٣٣عَرَبِيّ', undefined, metadata)).to.deep.equal([{
|
|
193
|
-
country: 'GB',
|
|
194
|
-
phone: '3333333333',
|
|
195
|
-
startsAt: 14,
|
|
196
|
-
endsAt: 27
|
|
197
|
-
}]);
|
|
198
|
-
});
|
|
199
|
-
it('should work in edge cases', function () {
|
|
200
|
-
var thrower;
|
|
201
|
-
|
|
202
|
-
// No input
|
|
203
|
-
expect(findPhoneNumbersInTextWithResults('', undefined, metadata)).to.deep.equal([]);
|
|
204
|
-
|
|
205
|
-
// // No country metadata for this `require` country code
|
|
206
|
-
// thrower = () => findPhoneNumbersInTextWithResults('123', { defaultCountry: 'ZZ' }, metadata)
|
|
207
|
-
// thrower.should.throw('Unknown country')
|
|
208
|
-
|
|
209
|
-
// Numerical `value`
|
|
210
|
-
thrower = function thrower() {
|
|
211
|
-
return findPhoneNumbersInTextWithResults(2141111111, {
|
|
212
|
-
defaultCountry: 'US'
|
|
213
|
-
});
|
|
214
|
-
};
|
|
215
|
-
expect(thrower).to["throw"]('A text for parsing must be a string.');
|
|
216
|
-
|
|
217
|
-
// // No metadata
|
|
218
|
-
// thrower = () => findPhoneNumbersInTextWithResults('')
|
|
219
|
-
// thrower.should.throw('`metadata` argument not passed')
|
|
220
|
-
|
|
221
|
-
// No metadata, no default country, no phone numbers.
|
|
222
|
-
expect(findPhoneNumbersInTextWithResults('')).to.deep.equal([]);
|
|
223
|
-
});
|
|
224
|
-
it('should find international numbers when passed a non-existent default country', function () {
|
|
225
|
-
var numbers = findPhoneNumbersInText('Phone: +7 (800) 555 35 35. National: 8 (800) 555-55-55', {
|
|
226
|
-
defaultCountry: 'XX',
|
|
227
|
-
v2: true
|
|
228
|
-
}, metadata);
|
|
229
|
-
expect(numbers.length).to.equal(1);
|
|
230
|
-
expect(numbers[0].number.nationalNumber).to.equal('8005553535');
|
|
231
|
-
});
|
|
232
|
-
it('shouldn\'t find phone numbers which are not phone numbers', function () {
|
|
233
|
-
// A timestamp.
|
|
234
|
-
expect(findPhoneNumbersInTextWithResults('2012-01-02 08:00', {
|
|
235
|
-
defaultCountry: 'US'
|
|
236
|
-
}, metadata)).to.deep.equal([]);
|
|
237
|
-
|
|
238
|
-
// A valid number (not a complete timestamp).
|
|
239
|
-
expect(findPhoneNumbersInTextWithResults('2012-01-02 08', {
|
|
240
|
-
defaultCountry: 'US'
|
|
241
|
-
}, metadata)).to.deep.equal([{
|
|
242
|
-
country: 'US',
|
|
243
|
-
phone: '2012010208',
|
|
244
|
-
startsAt: 0,
|
|
245
|
-
endsAt: 13
|
|
246
|
-
}]);
|
|
247
|
-
|
|
248
|
-
// Invalid parens.
|
|
249
|
-
expect(findPhoneNumbersInTextWithResults('213(3734253', {
|
|
250
|
-
defaultCountry: 'US'
|
|
251
|
-
}, metadata)).to.deep.equal([]);
|
|
252
|
-
|
|
253
|
-
// Letters after phone number.
|
|
254
|
-
expect(findPhoneNumbersInTextWithResults('2133734253a', {
|
|
255
|
-
defaultCountry: 'US'
|
|
256
|
-
}, metadata)).to.deep.equal([]);
|
|
257
|
-
|
|
258
|
-
// Valid phone (same as the one found in the UUID below).
|
|
259
|
-
expect(findPhoneNumbersInTextWithResults('The phone number is 231354125.', {
|
|
260
|
-
defaultCountry: 'FR'
|
|
261
|
-
}, metadata)).to.deep.equal([{
|
|
262
|
-
country: 'FR',
|
|
263
|
-
phone: '231354125',
|
|
264
|
-
startsAt: 20,
|
|
265
|
-
endsAt: 29
|
|
266
|
-
}]);
|
|
267
|
-
|
|
268
|
-
// Not a phone number (part of a UUID).
|
|
269
|
-
// Should parse in `{ extended: true }` mode.
|
|
270
|
-
var possibleNumbers = findPhoneNumbersInTextWithResults('The UUID is CA801c26f98cd16e231354125ad046e40b.', {
|
|
271
|
-
defaultCountry: 'FR',
|
|
272
|
-
extended: true
|
|
273
|
-
}, metadata);
|
|
274
|
-
expect(possibleNumbers.length).to.equal(1);
|
|
275
|
-
expect(possibleNumbers[0].country).to.equal('FR');
|
|
276
|
-
expect(possibleNumbers[0].phone).to.equal('231354125');
|
|
277
|
-
|
|
278
|
-
// Not a phone number (part of a UUID).
|
|
279
|
-
// Shouldn't parse by default.
|
|
280
|
-
expect(findPhoneNumbersInTextWithResults('The UUID is CA801c26f98cd16e231354125ad046e40b.', {
|
|
281
|
-
defaultCountry: 'FR'
|
|
282
|
-
}, metadata)).to.deep.equal([]);
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
// https://gitlab.com/catamphetamine/libphonenumber-js/-/merge_requests/4
|
|
286
|
-
it('should return correct `startsAt` and `endsAt` when matching "inner" candidates in a could-be-a-candidate substring', function () {
|
|
287
|
-
expect(findPhoneNumbersInTextWithResults('39945926 77200596 16533084', {
|
|
288
|
-
defaultCountry: 'ID'
|
|
289
|
-
}, metadataMax)).to.deep.equal([{
|
|
290
|
-
country: 'ID',
|
|
291
|
-
phone: '77200596',
|
|
292
|
-
startsAt: 9,
|
|
293
|
-
endsAt: 17
|
|
294
|
-
}]);
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
//# sourceMappingURL=findPhoneNumbersInText.test.js.map
|