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,105 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import parseIncompletePhoneNumber, { parsePhoneNumberCharacter } from './parseIncompletePhoneNumber.js';
|
|
4
|
-
describe('parseIncompletePhoneNumber', function () {
|
|
5
|
-
it('should fix `for ... of` loop coverage', function () {
|
|
6
|
-
// For some weird reason, "istanbul" doesn't know how to properly cover
|
|
7
|
-
// a `for ... of` loop that has been transpiled with Babel.
|
|
8
|
-
// For some reason, it attempts to cover the `for ... of` polyfill coode too,
|
|
9
|
-
// meaning that it complains if that polyfill's edge case is not covered.
|
|
10
|
-
// This test case works around that weird bug by covering that edge case of the polyfill.
|
|
11
|
-
//
|
|
12
|
-
// When it runs `npm test` command, it does so without `babel` transpilation,
|
|
13
|
-
// so the error is gonna be "string.split is not a function or its return value is not iterable".
|
|
14
|
-
//
|
|
15
|
-
// When it runs `npm run test-coverage` command, it does so with `babel` transpilation,
|
|
16
|
-
// so the error is gonna be "Invalid attempt to iterate non-iterable instance.".
|
|
17
|
-
//
|
|
18
|
-
expect(function () {
|
|
19
|
-
parseIncompletePhoneNumber({
|
|
20
|
-
split: function split() {
|
|
21
|
-
return 123;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}).to["throw"](/(not iterable|non-iterable)/);
|
|
25
|
-
});
|
|
26
|
-
it('should parse phone number character', function () {
|
|
27
|
-
// Accepts leading `+`.
|
|
28
|
-
expect(parsePhoneNumberCharacter('+')).to.equal('+');
|
|
29
|
-
|
|
30
|
-
// Doesn't accept non-leading `+`.
|
|
31
|
-
expect(parsePhoneNumberCharacter('+', '+')).to.be.undefined;
|
|
32
|
-
|
|
33
|
-
// Parses digits.
|
|
34
|
-
expect(parsePhoneNumberCharacter('1')).to.equal('1');
|
|
35
|
-
|
|
36
|
-
// Parses non-European digits.
|
|
37
|
-
expect(parsePhoneNumberCharacter('٤')).to.equal('4');
|
|
38
|
-
|
|
39
|
-
// Dismisses other characters.
|
|
40
|
-
expect(parsePhoneNumberCharacter('-')).to.be.undefined;
|
|
41
|
-
});
|
|
42
|
-
it('should parse incomplete phone number', function () {
|
|
43
|
-
expect(parseIncompletePhoneNumber('')).to.equal('');
|
|
44
|
-
|
|
45
|
-
// Doesn't accept non-leading `+`.
|
|
46
|
-
expect(parseIncompletePhoneNumber('++')).to.equal('+');
|
|
47
|
-
|
|
48
|
-
// Accepts leading `+`.
|
|
49
|
-
expect(parseIncompletePhoneNumber('+7 800 555')).to.equal('+7800555');
|
|
50
|
-
|
|
51
|
-
// Parses digits.
|
|
52
|
-
expect(parseIncompletePhoneNumber('8 (800) 555')).to.equal('8800555');
|
|
53
|
-
|
|
54
|
-
// Parses non-European digits.
|
|
55
|
-
expect(parseIncompletePhoneNumber('+٤٤٢٣٢٣٢٣٤')).to.equal('+442323234');
|
|
56
|
-
});
|
|
57
|
-
it('should work with a new `context` argument in `parsePhoneNumberCharacter()` function (international number)', function () {
|
|
58
|
-
var stopped = false;
|
|
59
|
-
var emit = function emit(event) {
|
|
60
|
-
switch (event) {
|
|
61
|
-
case 'end':
|
|
62
|
-
stopped = true;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
expect(parsePhoneNumberCharacter('+', undefined, emit)).to.equal('+');
|
|
67
|
-
expect(stopped).to.equal(false);
|
|
68
|
-
expect(parsePhoneNumberCharacter('1', '+', emit)).to.equal('1');
|
|
69
|
-
expect(stopped).to.equal(false);
|
|
70
|
-
expect(parsePhoneNumberCharacter('+', '+1', emit)).to.be.undefined;
|
|
71
|
-
expect(stopped).to.equal(true);
|
|
72
|
-
expect(parsePhoneNumberCharacter('2', '+1', emit)).to.equal('2');
|
|
73
|
-
expect(stopped).to.equal(true);
|
|
74
|
-
});
|
|
75
|
-
it('should work with a new `context` argument in `parsePhoneNumberCharacter()` function (national number)', function () {
|
|
76
|
-
var stopped = false;
|
|
77
|
-
var emit = function emit(event) {
|
|
78
|
-
switch (event) {
|
|
79
|
-
case 'end':
|
|
80
|
-
stopped = true;
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
expect(parsePhoneNumberCharacter('2', undefined, emit)).to.equal('2');
|
|
85
|
-
expect(stopped).to.equal(false);
|
|
86
|
-
expect(parsePhoneNumberCharacter('+', '2', emit)).to.be.undefined;
|
|
87
|
-
expect(stopped).to.equal(true);
|
|
88
|
-
expect(parsePhoneNumberCharacter('1', '2', emit)).to.equal('1');
|
|
89
|
-
expect(stopped).to.equal(true);
|
|
90
|
-
});
|
|
91
|
-
it('should call `eventListener` when the input ends abruptly', function () {
|
|
92
|
-
var parsingEnded = false;
|
|
93
|
-
var eventListener = function eventListener(event) {
|
|
94
|
-
parsingEnded = true;
|
|
95
|
-
if (event !== 'end') {
|
|
96
|
-
throw new Error("Unexpected event: ".concat(event));
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
// Doesn't accept non-leading `+`.
|
|
101
|
-
expect(parsePhoneNumberCharacter('+', '+123', eventListener)).to.be.undefined;
|
|
102
|
-
expect(parsingEnded).to.equal(true);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
//# sourceMappingURL=parseIncompletePhoneNumber.test.js.map
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import _parsePhoneNumber from './parsePhoneNumber.js';
|
|
4
|
-
import metadata from '../metadata.min.json' with { type: 'json' };
|
|
5
|
-
function parsePhoneNumber() {
|
|
6
|
-
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
7
|
-
parameters[_key] = arguments[_key];
|
|
8
|
-
}
|
|
9
|
-
parameters.push(metadata);
|
|
10
|
-
return _parsePhoneNumber.apply(this, parameters);
|
|
11
|
-
}
|
|
12
|
-
var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
|
|
13
|
-
describe('parsePhoneNumber', function () {
|
|
14
|
-
it('should parse phone numbers from string', function () {
|
|
15
|
-
expect(parsePhoneNumber('Phone: 8 (800) 555 35 35.', 'RU').nationalNumber).to.equal('8005553535');
|
|
16
|
-
expect(parsePhoneNumber('3', 'RU')).to.be.undefined;
|
|
17
|
-
});
|
|
18
|
-
it('should work in edge cases', function () {
|
|
19
|
-
expect(parsePhoneNumber('')).to.be.undefined;
|
|
20
|
-
});
|
|
21
|
-
it('should parse phone numbers when invalid country code is passed', function () {
|
|
22
|
-
expect(parsePhoneNumber('Phone: +7 (800) 555 35 35.', 'XX').nationalNumber).to.equal('8005553535');
|
|
23
|
-
expect(parsePhoneNumber('Phone: 8 (800) 555-35-35.', 'XX')).to.be.undefined;
|
|
24
|
-
});
|
|
25
|
-
it('should parse non-geographic numbering plan phone numbers (extended)', function () {
|
|
26
|
-
var phoneNumber = parsePhoneNumber('+870773111632');
|
|
27
|
-
expect(phoneNumber.number).to.equal('+870773111632');
|
|
28
|
-
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
29
|
-
expect(phoneNumber.country).to.equal('001');
|
|
30
|
-
} else {
|
|
31
|
-
expect(phoneNumber.country).to.be.undefined;
|
|
32
|
-
}
|
|
33
|
-
expect(phoneNumber.countryCallingCode).to.equal('870');
|
|
34
|
-
});
|
|
35
|
-
it('should parse non-geographic numbering plan phone numbers (default country code) (extended)', function () {
|
|
36
|
-
var phoneNumber = parsePhoneNumber('773111632', {
|
|
37
|
-
defaultCallingCode: '870'
|
|
38
|
-
});
|
|
39
|
-
expect(phoneNumber.number).to.equal('+870773111632');
|
|
40
|
-
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
41
|
-
expect(phoneNumber.country).to.equal('001');
|
|
42
|
-
} else {
|
|
43
|
-
expect(phoneNumber.country).to.be.undefined;
|
|
44
|
-
}
|
|
45
|
-
expect(phoneNumber.countryCallingCode).to.equal('870');
|
|
46
|
-
});
|
|
47
|
-
it('should determine the possibility of non-geographic phone numbers', function () {
|
|
48
|
-
var phoneNumber = parsePhoneNumber('+870773111632');
|
|
49
|
-
expect(phoneNumber.isPossible()).to.equal(true);
|
|
50
|
-
var phoneNumber2 = parsePhoneNumber('+8707731116321');
|
|
51
|
-
expect(phoneNumber2.isPossible()).to.equal(false);
|
|
52
|
-
});
|
|
53
|
-
it('should support `extract: false` flag', function () {
|
|
54
|
-
var testCorrectness = function testCorrectness(number, expectedResult) {
|
|
55
|
-
var result = expect(parsePhoneNumber(number, {
|
|
56
|
-
extract: false,
|
|
57
|
-
defaultCountry: 'US'
|
|
58
|
-
}));
|
|
59
|
-
if (expectedResult) {
|
|
60
|
-
result.to.not.be.undefined;
|
|
61
|
-
} else {
|
|
62
|
-
result.to.be.undefined;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
testCorrectness('Call: (213) 373-4253', false);
|
|
66
|
-
testCorrectness('(213) 373-4253x', false);
|
|
67
|
-
testCorrectness('(213) 373-4253', true);
|
|
68
|
-
testCorrectness('- (213) 373-4253 -', true);
|
|
69
|
-
testCorrectness('+1 (213) 373-4253', true);
|
|
70
|
-
testCorrectness(' +1 (213) 373-4253', false);
|
|
71
|
-
});
|
|
72
|
-
it('should not prematurely strip a possible national prefix from Chinese numbers', function () {
|
|
73
|
-
// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/57
|
|
74
|
-
var phoneNumber = parsePhoneNumber('+86123456789');
|
|
75
|
-
expect(phoneNumber.isPossible()).to.equal(true);
|
|
76
|
-
expect(phoneNumber.isValid()).to.equal(false);
|
|
77
|
-
expect(phoneNumber.nationalNumber).to.equal('123456789');
|
|
78
|
-
});
|
|
79
|
-
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', function () {
|
|
80
|
-
// Tests that Californian numbers `+1310xxxx` are considered possible.
|
|
81
|
-
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
|
|
82
|
-
|
|
83
|
-
var phoneNumber = parsePhoneNumber('+13100000');
|
|
84
|
-
expect(phoneNumber.country).to.equal('CA');
|
|
85
|
-
expect(phoneNumber.isPossible()).to.equal(true);
|
|
86
|
-
expect(phoneNumber.isValid()).to.equal(true);
|
|
87
|
-
expect(phoneNumber.nationalNumber).to.equal('3100000');
|
|
88
|
-
var phoneNumberLocal = parsePhoneNumber('3100000', 'CA');
|
|
89
|
-
expect(phoneNumberLocal.country).to.equal('CA');
|
|
90
|
-
expect(phoneNumberLocal.isPossible()).to.equal(true);
|
|
91
|
-
expect(phoneNumberLocal.isValid()).to.equal(true);
|
|
92
|
-
expect(phoneNumberLocal.nationalNumber).to.equal('3100000');
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
//# sourceMappingURL=parsePhoneNumber.test.js.map
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import _parsePhoneNumber from './parsePhoneNumberWithError.js';
|
|
4
|
-
import metadata from '../metadata.min.json' with { type: 'json' };
|
|
5
|
-
import metadataFull from '../metadata.max.json' with { type: 'json' };
|
|
6
|
-
function parsePhoneNumber() {
|
|
7
|
-
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
8
|
-
parameters[_key] = arguments[_key];
|
|
9
|
-
}
|
|
10
|
-
parameters.push(metadata);
|
|
11
|
-
return _parsePhoneNumber.apply(this, parameters);
|
|
12
|
-
}
|
|
13
|
-
function parsePhoneNumberFull() {
|
|
14
|
-
for (var _len2 = arguments.length, parameters = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
15
|
-
parameters[_key2] = arguments[_key2];
|
|
16
|
-
}
|
|
17
|
-
parameters.push(metadataFull);
|
|
18
|
-
return _parsePhoneNumber.apply(this, parameters);
|
|
19
|
-
}
|
|
20
|
-
describe('parsePhoneNumberWithError', function () {
|
|
21
|
-
it('should parse phone numbers', function () {
|
|
22
|
-
var phoneNumber = parsePhoneNumber('The phone number is: 8 (800) 555 35 35. Some other text.', 'RU');
|
|
23
|
-
expect(phoneNumber.country).to.equal('RU');
|
|
24
|
-
expect(phoneNumber.countryCallingCode).to.equal('7');
|
|
25
|
-
expect(phoneNumber.nationalNumber).to.equal('8005553535');
|
|
26
|
-
expect(phoneNumber.number).to.equal('+78005553535');
|
|
27
|
-
expect(phoneNumber.isPossible()).to.equal(true);
|
|
28
|
-
expect(phoneNumber.isValid()).to.equal(true);
|
|
29
|
-
// phoneNumber.isValidForRegion('RU').should.equal(true)
|
|
30
|
-
// Russian phone type regexps aren't included in default metadata.
|
|
31
|
-
expect(parsePhoneNumberFull('Phone: 8 (800) 555 35 35.', 'RU').getType()).to.equal('TOLL_FREE');
|
|
32
|
-
});
|
|
33
|
-
it('shouldn\'t set country when it\'s non-derivable', function () {
|
|
34
|
-
var phoneNumber = parsePhoneNumber('+7 111 555 35 35');
|
|
35
|
-
expect(phoneNumber.country).to.be.undefined;
|
|
36
|
-
expect(phoneNumber.countryCallingCode).to.equal('7');
|
|
37
|
-
expect(phoneNumber.nationalNumber).to.equal('1115553535');
|
|
38
|
-
});
|
|
39
|
-
it('should parse carrier code', function () {
|
|
40
|
-
var phoneNumber = parsePhoneNumber('0 15 21 5555-5555', 'BR');
|
|
41
|
-
expect(phoneNumber.carrierCode).to.equal('15');
|
|
42
|
-
});
|
|
43
|
-
it('should parse phone extension', function () {
|
|
44
|
-
var phoneNumber = parsePhoneNumber('Phone: 8 (800) 555 35 35 ext. 1234.', 'RU');
|
|
45
|
-
expect(phoneNumber.ext).to.equal('1234');
|
|
46
|
-
});
|
|
47
|
-
it('should validate numbers for countries with no type regular expressions', function () {
|
|
48
|
-
expect(parsePhoneNumber('+380391234567').isValid()).to.equal(true);
|
|
49
|
-
expect(parsePhoneNumber('+380191234567').isValid()).to.equal(false);
|
|
50
|
-
});
|
|
51
|
-
it('should format numbers', function () {
|
|
52
|
-
var phoneNumber = parsePhoneNumber('Phone: 8 (800) 555 35 35.', 'RU');
|
|
53
|
-
expect(phoneNumber.format('NATIONAL')).to.equal('8 (800) 555-35-35');
|
|
54
|
-
expect(phoneNumber.formatNational()).to.equal('8 (800) 555-35-35');
|
|
55
|
-
expect(phoneNumber.format('INTERNATIONAL')).to.equal('+7 800 555 35 35');
|
|
56
|
-
expect(phoneNumber.formatInternational()).to.equal('+7 800 555 35 35');
|
|
57
|
-
});
|
|
58
|
-
it('should get tel: URI', function () {
|
|
59
|
-
var phoneNumber = parsePhoneNumber('Phone: 8 (800) 555 35 35 ext. 1234.', 'RU');
|
|
60
|
-
expect(phoneNumber.getURI()).to.equal('tel:+78005553535;ext=1234');
|
|
61
|
-
});
|
|
62
|
-
it('should work in edge cases', function () {
|
|
63
|
-
expect(function () {
|
|
64
|
-
return parsePhoneNumber('+78005553535', -1, {});
|
|
65
|
-
}).to["throw"]('Invalid second argument');
|
|
66
|
-
});
|
|
67
|
-
it('should throw parse errors', function () {
|
|
68
|
-
expect(function () {
|
|
69
|
-
return parsePhoneNumber('8005553535', 'XX');
|
|
70
|
-
}).to["throw"]('INVALID_COUNTRY');
|
|
71
|
-
expect(function () {
|
|
72
|
-
return parsePhoneNumber('+', 'RU');
|
|
73
|
-
}).to["throw"]('NOT_A_NUMBER');
|
|
74
|
-
expect(function () {
|
|
75
|
-
return parsePhoneNumber('a', 'RU');
|
|
76
|
-
}).to["throw"]('NOT_A_NUMBER');
|
|
77
|
-
expect(function () {
|
|
78
|
-
return parsePhoneNumber('1', 'RU');
|
|
79
|
-
}).to["throw"]('TOO_SHORT');
|
|
80
|
-
expect(function () {
|
|
81
|
-
return parsePhoneNumber('+4');
|
|
82
|
-
}).to["throw"]('TOO_SHORT');
|
|
83
|
-
expect(function () {
|
|
84
|
-
return parsePhoneNumber('+44');
|
|
85
|
-
}).to["throw"]('TOO_SHORT');
|
|
86
|
-
expect(function () {
|
|
87
|
-
return parsePhoneNumber('+443');
|
|
88
|
-
}).to["throw"]('TOO_SHORT');
|
|
89
|
-
expect(function () {
|
|
90
|
-
return parsePhoneNumber('+370');
|
|
91
|
-
}).to["throw"]('TOO_SHORT');
|
|
92
|
-
expect(function () {
|
|
93
|
-
return parsePhoneNumber('88888888888888888888', 'RU');
|
|
94
|
-
}).to["throw"]('TOO_LONG');
|
|
95
|
-
expect(function () {
|
|
96
|
-
return parsePhoneNumber('8 (800) 555 35 35');
|
|
97
|
-
}).to["throw"]('INVALID_COUNTRY');
|
|
98
|
-
expect(function () {
|
|
99
|
-
return parsePhoneNumber('+9991112233');
|
|
100
|
-
}).to["throw"]('INVALID_COUNTRY');
|
|
101
|
-
expect(function () {
|
|
102
|
-
return parsePhoneNumber('+9991112233', 'US');
|
|
103
|
-
}).to["throw"]('INVALID_COUNTRY');
|
|
104
|
-
expect(function () {
|
|
105
|
-
return parsePhoneNumber('8005553535 ', 'RU');
|
|
106
|
-
}).to["throw"]('TOO_LONG');
|
|
107
|
-
});
|
|
108
|
-
it('should parse incorrect international phone numbers', function () {
|
|
109
|
-
// Parsing national prefixes and carrier codes
|
|
110
|
-
// is only required for local phone numbers
|
|
111
|
-
// but some people don't understand that
|
|
112
|
-
// and sometimes write international phone numbers
|
|
113
|
-
// with national prefixes (or maybe even carrier codes).
|
|
114
|
-
// http://ucken.blogspot.ru/2016/03/trunk-prefixes-in-skype4b.html
|
|
115
|
-
// Google's original library forgives such mistakes
|
|
116
|
-
// and so does this library, because it has been requested:
|
|
117
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/127
|
|
118
|
-
|
|
119
|
-
var phoneNumber;
|
|
120
|
-
|
|
121
|
-
// For complete numbers it should strip national prefix.
|
|
122
|
-
phoneNumber = parsePhoneNumber('+1 1877 215 5230');
|
|
123
|
-
expect(phoneNumber.nationalNumber).to.equal('8772155230');
|
|
124
|
-
expect(phoneNumber.country).to.equal('US');
|
|
125
|
-
|
|
126
|
-
// For complete numbers it should strip national prefix.
|
|
127
|
-
phoneNumber = parsePhoneNumber('+7 8800 555 3535');
|
|
128
|
-
expect(phoneNumber.nationalNumber).to.equal('8005553535');
|
|
129
|
-
expect(phoneNumber.country).to.equal('RU');
|
|
130
|
-
|
|
131
|
-
// For incomplete numbers it shouldn't strip national prefix.
|
|
132
|
-
phoneNumber = parsePhoneNumber('+7 8800 555 353');
|
|
133
|
-
expect(phoneNumber.nationalNumber).to.equal('8800555353');
|
|
134
|
-
expect(phoneNumber.country).to.equal('RU');
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
//# sourceMappingURL=parsePhoneNumberWithError.test.js.map
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
2
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
|
-
import { describe, it } from 'mocha';
|
|
5
|
-
import { expect } from 'chai';
|
|
6
|
-
import searchPhoneNumbersInText from './searchPhoneNumbersInText.js';
|
|
7
|
-
import metadata from '../metadata.min.json' with { type: 'json' };
|
|
8
|
-
describe('searchPhoneNumbersInText', function () {
|
|
9
|
-
it('should find phone numbers (with default country)', function () {
|
|
10
|
-
var NUMBERS = ['+78005553535', '+12133734253'];
|
|
11
|
-
for (var _iterator = _createForOfIteratorHelperLoose(searchPhoneNumbersInText('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', metadata)), _step; !(_step = _iterator()).done;) {
|
|
12
|
-
var number = _step.value;
|
|
13
|
-
expect(number.number.number).to.equal(NUMBERS[0]);
|
|
14
|
-
NUMBERS.shift();
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
it('should find phone numbers', function () {
|
|
18
|
-
var NUMBERS = ['+78005553535', '+12133734253'];
|
|
19
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(searchPhoneNumbersInText('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', metadata)), _step2; !(_step2 = _iterator2()).done;) {
|
|
20
|
-
var number = _step2.value;
|
|
21
|
-
expect(number.number.number).to.equal(NUMBERS[0]);
|
|
22
|
-
NUMBERS.shift();
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
it('should find phone numbers in text', function () {
|
|
26
|
-
var expectedNumbers = [{
|
|
27
|
-
country: 'RU',
|
|
28
|
-
nationalNumber: '8005553535',
|
|
29
|
-
startsAt: 14,
|
|
30
|
-
endsAt: 32
|
|
31
|
-
}, {
|
|
32
|
-
country: 'US',
|
|
33
|
-
nationalNumber: '2133734253',
|
|
34
|
-
startsAt: 41,
|
|
35
|
-
endsAt: 55
|
|
36
|
-
}];
|
|
37
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(searchPhoneNumbersInText('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', metadata)), _step3; !(_step3 = _iterator3()).done;) {
|
|
38
|
-
var number = _step3.value;
|
|
39
|
-
var expected = expectedNumbers.shift();
|
|
40
|
-
expect(number.startsAt).to.equal(expected.startsAt);
|
|
41
|
-
expect(number.endsAt).to.equal(expected.endsAt);
|
|
42
|
-
expect(number.number.nationalNumber).to.equal(expected.nationalNumber);
|
|
43
|
-
expect(number.number.country).to.equal(expected.country);
|
|
44
|
-
}
|
|
45
|
-
expect(expectedNumbers.length).to.equal(0);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
//# sourceMappingURL=searchPhoneNumbersInText.test.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import semverCompare from './semver-compare.js';
|
|
4
|
-
describe('semver-compare', function () {
|
|
5
|
-
it('should compare versions', function () {
|
|
6
|
-
var versions = ['1.2.3', '4.11.6', '4.2.0', '1.5.19', '1.5.6', '1.5.4', '1.5.5-alpha.beta', '1.5.5-alpha', '1.5.5', '1.5.5-rc.1', '1.5.5-beta.0', '4.1.3', '2.3.1', '10.5.5', '11.3.0'];
|
|
7
|
-
expect(versions.sort(semverCompare)).to.deep.equal(['1.2.3', '1.5.4', '1.5.5-alpha', '1.5.5-alpha.beta', '1.5.5-beta.0', '1.5.5-rc.1', '1.5.5', '1.5.6', '1.5.19', '2.3.1', '4.1.3', '4.2.0', '4.11.6', '10.5.5', '11.3.0']);
|
|
8
|
-
});
|
|
9
|
-
});
|
|
10
|
-
//# sourceMappingURL=semver-compare.test.js.map
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import _validatePhoneNumberLength from './validatePhoneNumberLength.js';
|
|
4
|
-
import metadata from '../metadata.min.json' with { type: 'json' };
|
|
5
|
-
function validatePhoneNumberLength() {
|
|
6
|
-
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
7
|
-
parameters[_key] = arguments[_key];
|
|
8
|
-
}
|
|
9
|
-
parameters.push(metadata);
|
|
10
|
-
return _validatePhoneNumberLength.apply(this, parameters);
|
|
11
|
-
}
|
|
12
|
-
describe('validatePhoneNumberLength', function () {
|
|
13
|
-
it('should detect whether a phone number length is valid', function () {
|
|
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
|
-
});
|
|
34
|
-
//# sourceMappingURL=validatePhoneNumberLength.test.js.map
|
package/jest.config.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"coveragePathIgnorePatterns": [
|
|
3
|
-
"/node_modules/",
|
|
4
|
-
"<rootDir>/test/",
|
|
5
|
-
"<rootDir>/source/findNumbers/RegExpCache.js",
|
|
6
|
-
"<rootDir>/source/findNumbers/Leniency.js",
|
|
7
|
-
"<rootDir>/source/findNumbers/LRUCache.js",
|
|
8
|
-
"<rootDir>/source/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js",
|
|
9
|
-
"<rootDir>/source/formatNumberForMobileDialing.js",
|
|
10
|
-
"<rootDir>/source/getCountryCallingCode.js",
|
|
11
|
-
"<rootDir>/source/PhoneNumberMatcher.js",
|
|
12
|
-
"<rootDir>/source/tools/*.js"
|
|
13
|
-
],
|
|
14
|
-
"testPathIgnorePatterns": [
|
|
15
|
-
"/node_modules/",
|
|
16
|
-
"<rootDir>/test/"
|
|
17
|
-
],
|
|
18
|
-
"coverageThreshold": {
|
|
19
|
-
"global": {
|
|
20
|
-
"branches": 100,
|
|
21
|
-
"functions": 100,
|
|
22
|
-
"lines": 100,
|
|
23
|
-
"statements": 100
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
package/rollup.config.mjs
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import json from '@rollup/plugin-json'
|
|
2
|
-
import terser from '@rollup/plugin-terser'
|
|
3
|
-
|
|
4
|
-
export default [
|
|
5
|
-
{
|
|
6
|
-
input: 'min/index.js',
|
|
7
|
-
plugins: [
|
|
8
|
-
json(),
|
|
9
|
-
terser()
|
|
10
|
-
],
|
|
11
|
-
output: {
|
|
12
|
-
format: 'umd',
|
|
13
|
-
name: 'libphonenumber',
|
|
14
|
-
file: 'bundle/libphonenumber-min.js',
|
|
15
|
-
sourcemap: true
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
input: 'mobile/index.js',
|
|
20
|
-
plugins: [
|
|
21
|
-
json(),
|
|
22
|
-
terser()
|
|
23
|
-
],
|
|
24
|
-
output: {
|
|
25
|
-
format: 'umd',
|
|
26
|
-
name: 'libphonenumber',
|
|
27
|
-
file: 'bundle/libphonenumber-mobile.js',
|
|
28
|
-
sourcemap: true
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
input: 'max/index.js',
|
|
33
|
-
plugins: [
|
|
34
|
-
json(),
|
|
35
|
-
terser()
|
|
36
|
-
],
|
|
37
|
-
output: {
|
|
38
|
-
format: 'umd',
|
|
39
|
-
name: 'libphonenumber',
|
|
40
|
-
file: 'bundle/libphonenumber-max.js',
|
|
41
|
-
sourcemap: true
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
input: 'index.es6',
|
|
46
|
-
plugins: [
|
|
47
|
-
json(),
|
|
48
|
-
terser()
|
|
49
|
-
],
|
|
50
|
-
output: {
|
|
51
|
-
format: 'umd',
|
|
52
|
-
name: 'libphonenumber',
|
|
53
|
-
file: 'bundle/libphonenumber-js.min.js',
|
|
54
|
-
sourcemap: true
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
]
|