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