libphonenumber-js 1.12.39 → 1.12.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/bundle/libphonenumber-js.min.js +1 -1
- package/bundle/libphonenumber-js.min.js.map +1 -1
- package/bundle/libphonenumber-max.js +1 -1
- package/bundle/libphonenumber-max.js.map +1 -1
- package/bundle/libphonenumber-min.js +1 -1
- package/bundle/libphonenumber-min.js.map +1 -1
- package/bundle/libphonenumber-mobile.js +1 -1
- package/bundle/libphonenumber-mobile.js.map +1 -1
- package/max/metadata/metadata.max.json +1 -1
- package/max/metadata/metadata.max.json.js +1 -1
- package/metadata.full.json +1 -1
- package/metadata.full.json.js +1 -1
- package/metadata.max.json +1 -1
- package/metadata.max.json.js +1 -1
- package/metadata.min.json +1 -1
- package/metadata.min.json.js +1 -1
- package/metadata.mobile.json +1 -1
- package/metadata.mobile.json.js +1 -1
- package/min/metadata/metadata.min.json +1 -1
- package/min/metadata/metadata.min.json.js +1 -1
- package/mobile/metadata/metadata.mobile.json +1 -1
- package/mobile/metadata/metadata.mobile.json.js +1 -1
- package/package.json +1 -1
- package/.babelrc +0 -21
- package/.nycrc +0 -27
- package/METADATA.md +0 -155
- package/autoupdate.cmd +0 -6
- package/autoupdate.sh +0 -16
- package/build/AsYouType.test.js +0 -1339
- package/build/AsYouTypeFormatter.PatternMatcher.test.js +0 -502
- package/build/AsYouTypeFormatter.PatternParser.test.js +0 -49
- package/build/AsYouTypeFormatter.util.test.js +0 -24
- package/build/PhoneNumber.test.js +0 -141
- package/build/PhoneNumberMatcher.test.js +0 -122
- package/build/findNumbers/util.test.js +0 -34
- package/build/findPhoneNumbersInText.test.js +0 -300
- package/build/format.test.js +0 -339
- package/build/formatIncompletePhoneNumber.test.js +0 -33
- package/build/getCountries.test.js +0 -13
- package/build/getCountryCallingCode.test.js +0 -18
- package/build/getExampleNumber.test.js +0 -21
- package/build/helpers/RFC3966.test.js +0 -47
- package/build/helpers/applyInternationalSeparatorStyle.test.js +0 -13
- package/build/helpers/checkNumberLength.test.js +0 -81
- package/build/helpers/extractCountryCallingCode.test.js +0 -23
- package/build/helpers/extractNationalNumber.test.js +0 -27
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -20
- package/build/helpers/extractPhoneContext.test.js +0 -71
- package/build/helpers/getNumberType.test.js +0 -23
- package/build/helpers/matchesEntirely.test.js +0 -16
- package/build/helpers/mergeArrays.test.js +0 -12
- package/build/helpers/parseDigits.test.js +0 -12
- package/build/helpers/stripIddPrefix.test.js +0 -22
- package/build/isPossible.test.js +0 -121
- package/build/isPossiblePhoneNumber.test.js +0 -42
- package/build/isValid.test.js +0 -144
- package/build/isValidPhoneNumber.test.js +0 -29
- package/build/legacy/findNumbers.test.js +0 -210
- package/build/legacy/findPhoneNumbers.test.js +0 -245
- package/build/legacy/format.test.js +0 -299
- package/build/legacy/getNumberType.test.js +0 -80
- package/build/legacy/isPossibleNumber.test.js +0 -82
- package/build/legacy/isValidNumber.test.js +0 -102
- package/build/legacy/isValidNumberForRegion.test.js +0 -40
- package/build/legacy/parse.test.js +0 -617
- package/build/legacy/searchNumbers.test.js +0 -33
- package/build/metadata.test.js +0 -170
- package/build/parse.test.js +0 -653
- package/build/parseIncompletePhoneNumber.test.js +0 -109
- package/build/parsePhoneNumber.test.js +0 -98
- package/build/parsePhoneNumberWithError.test.js +0 -140
- package/build/searchPhoneNumbersInText.test.js +0 -51
- package/build/tools/semver-compare.test.js +0 -13
- package/build/validatePhoneNumberLength.test.js +0 -37
- package/build-scripts/check-for-metadata-changes-and-create-pull-request.js +0 -88
- package/build-scripts/check-for-metadata-changes-and-release.js +0 -67
- package/build-scripts/check-for-uncommitted-files.js +0 -13
- package/build-scripts/create-commonjs-package-json-file.js +0 -11
- package/build-scripts/create-js-file-for-json-file.js +0 -14
- package/build-scripts/create-metadata-update-branch.js +0 -31
- package/build-scripts/generate-country-codes-list-in-typescript.js +0 -14
- package/build-scripts/generate-metadata-from-google-metadata.js +0 -75
- package/build-scripts/helpers/commit.js +0 -14
- package/build-scripts/helpers/exec.js +0 -6
- package/build-scripts/helpers/getUncommittedChanges.js +0 -33
- package/build-scripts/helpers/sendEmail.js +0 -62
- package/build-scripts/helpers/updateMetadataFromGoogleMetadata.js +0 -130
- package/build-scripts/pull-google-metadata.js +0 -29
- package/es6/AsYouType.test.js +0 -1336
- package/es6/AsYouTypeFormatter.PatternMatcher.test.js +0 -499
- package/es6/AsYouTypeFormatter.PatternParser.test.js +0 -46
- package/es6/AsYouTypeFormatter.util.test.js +0 -22
- package/es6/PhoneNumber.test.js +0 -138
- package/es6/PhoneNumberMatcher.test.js +0 -119
- package/es6/findNumbers/util.test.js +0 -32
- package/es6/findPhoneNumbersInText.test.js +0 -297
- package/es6/format.test.js +0 -336
- package/es6/formatIncompletePhoneNumber.test.js +0 -30
- package/es6/getCountries.test.js +0 -10
- package/es6/getCountryCallingCode.test.js +0 -15
- package/es6/getExampleNumber.test.js +0 -18
- package/es6/helpers/RFC3966.test.js +0 -45
- package/es6/helpers/applyInternationalSeparatorStyle.test.js +0 -10
- package/es6/helpers/checkNumberLength.test.js +0 -76
- package/es6/helpers/extractCountryCallingCode.test.js +0 -20
- package/es6/helpers/extractNationalNumber.test.js +0 -24
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -17
- package/es6/helpers/extractPhoneContext.test.js +0 -68
- package/es6/helpers/getNumberType.test.js +0 -20
- package/es6/helpers/matchesEntirely.test.js +0 -13
- package/es6/helpers/mergeArrays.test.js +0 -9
- package/es6/helpers/parseDigits.test.js +0 -9
- package/es6/helpers/stripIddPrefix.test.js +0 -19
- package/es6/isPossible.test.js +0 -118
- package/es6/isPossiblePhoneNumber.test.js +0 -39
- package/es6/isValid.test.js +0 -141
- package/es6/isValidPhoneNumber.test.js +0 -26
- package/es6/legacy/findNumbers.test.js +0 -207
- package/es6/legacy/findPhoneNumbers.test.js +0 -243
- package/es6/legacy/format.test.js +0 -296
- package/es6/legacy/getNumberType.test.js +0 -77
- package/es6/legacy/isPossibleNumber.test.js +0 -79
- package/es6/legacy/isValidNumber.test.js +0 -99
- package/es6/legacy/isValidNumberForRegion.test.js +0 -37
- package/es6/legacy/parse.test.js +0 -614
- package/es6/legacy/searchNumbers.test.js +0 -30
- package/es6/metadata.test.js +0 -166
- package/es6/parse.test.js +0 -650
- package/es6/parseIncompletePhoneNumber.test.js +0 -105
- package/es6/parsePhoneNumber.test.js +0 -95
- package/es6/parsePhoneNumberWithError.test.js +0 -137
- package/es6/searchPhoneNumbersInText.test.js +0 -48
- package/es6/tools/semver-compare.test.js +0 -10
- package/es6/validatePhoneNumberLength.test.js +0 -34
- package/jest.config.json +0 -26
- package/rollup.config.mjs +0 -57
- package/source/AsYouType.test.js +0 -1409
- package/source/AsYouTypeFormatter.PatternMatcher.test.js +0 -644
- package/source/AsYouTypeFormatter.PatternParser.test.js +0 -70
- package/source/AsYouTypeFormatter.util.test.js +0 -25
- package/source/PhoneNumber.test.js +0 -138
- package/source/PhoneNumberMatcher.test.js +0 -112
- package/source/findNumbers/util.test.js +0 -37
- package/source/findPhoneNumbersInText.test.js +0 -316
- package/source/format.test.js +0 -273
- package/source/formatIncompletePhoneNumber.test.js +0 -33
- package/source/getCountries.test.js +0 -12
- package/source/getCountryCallingCode.test.js +0 -16
- package/source/getExampleNumber.test.js +0 -20
- package/source/helpers/RFC3966.test.js +0 -39
- package/source/helpers/applyInternationalSeparatorStyle.test.js +0 -11
- package/source/helpers/checkNumberLength.test.js +0 -85
- package/source/helpers/extractCountryCallingCode.test.js +0 -23
- package/source/helpers/extractNationalNumber.test.js +0 -27
- package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -18
- package/source/helpers/extractPhoneContext.test.js +0 -107
- package/source/helpers/getNumberType.test.js +0 -27
- package/source/helpers/matchesEntirely.test.js +0 -14
- package/source/helpers/mergeArrays.test.js +0 -10
- package/source/helpers/parseDigits.test.js +0 -10
- package/source/helpers/stripIddPrefix.test.js +0 -24
- package/source/isPossible.test.js +0 -86
- package/source/isPossiblePhoneNumber.test.js +0 -36
- package/source/isValid.test.js +0 -123
- package/source/isValidPhoneNumber.test.js +0 -23
- package/source/legacy/findNumbers.test.js +0 -220
- package/source/legacy/findPhoneNumbers.test.js +0 -252
- package/source/legacy/format.test.js +0 -246
- package/source/legacy/getNumberType.test.js +0 -70
- package/source/legacy/isPossibleNumber.test.js +0 -49
- package/source/legacy/isValidNumber.test.js +0 -95
- package/source/legacy/isValidNumberForRegion.test.js +0 -31
- package/source/legacy/parse.test.js +0 -533
- package/source/legacy/searchNumbers.test.js +0 -29
- package/source/metadata.test.js +0 -178
- package/source/parse.test.js +0 -561
- package/source/parseIncompletePhoneNumber.test.js +0 -118
- package/source/parsePhoneNumber.test.js +0 -99
- package/source/parsePhoneNumberWithError.test.js +0 -115
- package/source/searchPhoneNumbersInText.test.js +0 -47
- package/source/tools/semver-compare.test.js +0 -43
- package/source/validatePhoneNumberLength.test.js +0 -33
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
-
var _mocha = require("mocha");
|
|
5
|
-
var _chai = require("chai");
|
|
6
|
-
var _parseIncompletePhoneNumber = _interopRequireWildcard(require("./parseIncompletePhoneNumber.js"));
|
|
7
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
8
|
-
(0, _mocha.describe)('parseIncompletePhoneNumber', function () {
|
|
9
|
-
(0, _mocha.it)('should fix `for ... of` loop coverage', function () {
|
|
10
|
-
// For some weird reason, "istanbul" doesn't know how to properly cover
|
|
11
|
-
// a `for ... of` loop that has been transpiled with Babel.
|
|
12
|
-
// For some reason, it attempts to cover the `for ... of` polyfill coode too,
|
|
13
|
-
// meaning that it complains if that polyfill's edge case is not covered.
|
|
14
|
-
// This test case works around that weird bug by covering that edge case of the polyfill.
|
|
15
|
-
//
|
|
16
|
-
// When it runs `npm test` command, it does so without `babel` transpilation,
|
|
17
|
-
// so the error is gonna be "string.split is not a function or its return value is not iterable".
|
|
18
|
-
//
|
|
19
|
-
// When it runs `npm run test-coverage` command, it does so with `babel` transpilation,
|
|
20
|
-
// so the error is gonna be "Invalid attempt to iterate non-iterable instance.".
|
|
21
|
-
//
|
|
22
|
-
(0, _chai.expect)(function () {
|
|
23
|
-
(0, _parseIncompletePhoneNumber["default"])({
|
|
24
|
-
split: function split() {
|
|
25
|
-
return 123;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}).to["throw"](/(not iterable|non-iterable)/);
|
|
29
|
-
});
|
|
30
|
-
(0, _mocha.it)('should parse phone number character', function () {
|
|
31
|
-
// Accepts leading `+`.
|
|
32
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber.parsePhoneNumberCharacter)('+')).to.equal('+');
|
|
33
|
-
|
|
34
|
-
// Doesn't accept non-leading `+`.
|
|
35
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber.parsePhoneNumberCharacter)('+', '+')).to.be.undefined;
|
|
36
|
-
|
|
37
|
-
// Parses digits.
|
|
38
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber.parsePhoneNumberCharacter)('1')).to.equal('1');
|
|
39
|
-
|
|
40
|
-
// Parses non-European digits.
|
|
41
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber.parsePhoneNumberCharacter)('٤')).to.equal('4');
|
|
42
|
-
|
|
43
|
-
// Dismisses other characters.
|
|
44
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber.parsePhoneNumberCharacter)('-')).to.be.undefined;
|
|
45
|
-
});
|
|
46
|
-
(0, _mocha.it)('should parse incomplete phone number', function () {
|
|
47
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber["default"])('')).to.equal('');
|
|
48
|
-
|
|
49
|
-
// Doesn't accept non-leading `+`.
|
|
50
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber["default"])('++')).to.equal('+');
|
|
51
|
-
|
|
52
|
-
// Accepts leading `+`.
|
|
53
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber["default"])('+7 800 555')).to.equal('+7800555');
|
|
54
|
-
|
|
55
|
-
// Parses digits.
|
|
56
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber["default"])('8 (800) 555')).to.equal('8800555');
|
|
57
|
-
|
|
58
|
-
// Parses non-European digits.
|
|
59
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber["default"])('+٤٤٢٣٢٣٢٣٤')).to.equal('+442323234');
|
|
60
|
-
});
|
|
61
|
-
(0, _mocha.it)('should work with a new `context` argument in `parsePhoneNumberCharacter()` function (international number)', function () {
|
|
62
|
-
var stopped = false;
|
|
63
|
-
var emit = function emit(event) {
|
|
64
|
-
switch (event) {
|
|
65
|
-
case 'end':
|
|
66
|
-
stopped = true;
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber.parsePhoneNumberCharacter)('+', undefined, emit)).to.equal('+');
|
|
71
|
-
(0, _chai.expect)(stopped).to.equal(false);
|
|
72
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber.parsePhoneNumberCharacter)('1', '+', emit)).to.equal('1');
|
|
73
|
-
(0, _chai.expect)(stopped).to.equal(false);
|
|
74
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber.parsePhoneNumberCharacter)('+', '+1', emit)).to.be.undefined;
|
|
75
|
-
(0, _chai.expect)(stopped).to.equal(true);
|
|
76
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber.parsePhoneNumberCharacter)('2', '+1', emit)).to.equal('2');
|
|
77
|
-
(0, _chai.expect)(stopped).to.equal(true);
|
|
78
|
-
});
|
|
79
|
-
(0, _mocha.it)('should work with a new `context` argument in `parsePhoneNumberCharacter()` function (national number)', function () {
|
|
80
|
-
var stopped = false;
|
|
81
|
-
var emit = function emit(event) {
|
|
82
|
-
switch (event) {
|
|
83
|
-
case 'end':
|
|
84
|
-
stopped = true;
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber.parsePhoneNumberCharacter)('2', undefined, emit)).to.equal('2');
|
|
89
|
-
(0, _chai.expect)(stopped).to.equal(false);
|
|
90
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber.parsePhoneNumberCharacter)('+', '2', emit)).to.be.undefined;
|
|
91
|
-
(0, _chai.expect)(stopped).to.equal(true);
|
|
92
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber.parsePhoneNumberCharacter)('1', '2', emit)).to.equal('1');
|
|
93
|
-
(0, _chai.expect)(stopped).to.equal(true);
|
|
94
|
-
});
|
|
95
|
-
(0, _mocha.it)('should call `eventListener` when the input ends abruptly', function () {
|
|
96
|
-
var parsingEnded = false;
|
|
97
|
-
var eventListener = function eventListener(event) {
|
|
98
|
-
parsingEnded = true;
|
|
99
|
-
if (event !== 'end') {
|
|
100
|
-
throw new Error("Unexpected event: ".concat(event));
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// Doesn't accept non-leading `+`.
|
|
105
|
-
(0, _chai.expect)((0, _parseIncompletePhoneNumber.parsePhoneNumberCharacter)('+', '+123', eventListener)).to.be.undefined;
|
|
106
|
-
(0, _chai.expect)(parsingEnded).to.equal(true);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
//# sourceMappingURL=parseIncompletePhoneNumber.test.js.map
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _mocha = require("mocha");
|
|
4
|
-
var _chai = require("chai");
|
|
5
|
-
var _parsePhoneNumber2 = _interopRequireDefault(require("./parsePhoneNumber.js"));
|
|
6
|
-
var _metadataMin = _interopRequireDefault(require("../metadata.min.json"));
|
|
7
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
8
|
-
function parsePhoneNumber() {
|
|
9
|
-
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
10
|
-
parameters[_key] = arguments[_key];
|
|
11
|
-
}
|
|
12
|
-
parameters.push(_metadataMin["default"]);
|
|
13
|
-
return _parsePhoneNumber2["default"].apply(this, parameters);
|
|
14
|
-
}
|
|
15
|
-
var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
|
|
16
|
-
(0, _mocha.describe)('parsePhoneNumber', function () {
|
|
17
|
-
(0, _mocha.it)('should parse phone numbers from string', function () {
|
|
18
|
-
(0, _chai.expect)(parsePhoneNumber('Phone: 8 (800) 555 35 35.', 'RU').nationalNumber).to.equal('8005553535');
|
|
19
|
-
(0, _chai.expect)(parsePhoneNumber('3', 'RU')).to.be.undefined;
|
|
20
|
-
});
|
|
21
|
-
(0, _mocha.it)('should work in edge cases', function () {
|
|
22
|
-
(0, _chai.expect)(parsePhoneNumber('')).to.be.undefined;
|
|
23
|
-
});
|
|
24
|
-
(0, _mocha.it)('should parse phone numbers when invalid country code is passed', function () {
|
|
25
|
-
(0, _chai.expect)(parsePhoneNumber('Phone: +7 (800) 555 35 35.', 'XX').nationalNumber).to.equal('8005553535');
|
|
26
|
-
(0, _chai.expect)(parsePhoneNumber('Phone: 8 (800) 555-35-35.', 'XX')).to.be.undefined;
|
|
27
|
-
});
|
|
28
|
-
(0, _mocha.it)('should parse non-geographic numbering plan phone numbers (extended)', function () {
|
|
29
|
-
var phoneNumber = parsePhoneNumber('+870773111632');
|
|
30
|
-
(0, _chai.expect)(phoneNumber.number).to.equal('+870773111632');
|
|
31
|
-
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
32
|
-
(0, _chai.expect)(phoneNumber.country).to.equal('001');
|
|
33
|
-
} else {
|
|
34
|
-
(0, _chai.expect)(phoneNumber.country).to.be.undefined;
|
|
35
|
-
}
|
|
36
|
-
(0, _chai.expect)(phoneNumber.countryCallingCode).to.equal('870');
|
|
37
|
-
});
|
|
38
|
-
(0, _mocha.it)('should parse non-geographic numbering plan phone numbers (default country code) (extended)', function () {
|
|
39
|
-
var phoneNumber = parsePhoneNumber('773111632', {
|
|
40
|
-
defaultCallingCode: '870'
|
|
41
|
-
});
|
|
42
|
-
(0, _chai.expect)(phoneNumber.number).to.equal('+870773111632');
|
|
43
|
-
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
44
|
-
(0, _chai.expect)(phoneNumber.country).to.equal('001');
|
|
45
|
-
} else {
|
|
46
|
-
(0, _chai.expect)(phoneNumber.country).to.be.undefined;
|
|
47
|
-
}
|
|
48
|
-
(0, _chai.expect)(phoneNumber.countryCallingCode).to.equal('870');
|
|
49
|
-
});
|
|
50
|
-
(0, _mocha.it)('should determine the possibility of non-geographic phone numbers', function () {
|
|
51
|
-
var phoneNumber = parsePhoneNumber('+870773111632');
|
|
52
|
-
(0, _chai.expect)(phoneNumber.isPossible()).to.equal(true);
|
|
53
|
-
var phoneNumber2 = parsePhoneNumber('+8707731116321');
|
|
54
|
-
(0, _chai.expect)(phoneNumber2.isPossible()).to.equal(false);
|
|
55
|
-
});
|
|
56
|
-
(0, _mocha.it)('should support `extract: false` flag', function () {
|
|
57
|
-
var testCorrectness = function testCorrectness(number, expectedResult) {
|
|
58
|
-
var result = (0, _chai.expect)(parsePhoneNumber(number, {
|
|
59
|
-
extract: false,
|
|
60
|
-
defaultCountry: 'US'
|
|
61
|
-
}));
|
|
62
|
-
if (expectedResult) {
|
|
63
|
-
result.to.not.be.undefined;
|
|
64
|
-
} else {
|
|
65
|
-
result.to.be.undefined;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
testCorrectness('Call: (213) 373-4253', false);
|
|
69
|
-
testCorrectness('(213) 373-4253x', false);
|
|
70
|
-
testCorrectness('(213) 373-4253', true);
|
|
71
|
-
testCorrectness('- (213) 373-4253 -', true);
|
|
72
|
-
testCorrectness('+1 (213) 373-4253', true);
|
|
73
|
-
testCorrectness(' +1 (213) 373-4253', false);
|
|
74
|
-
});
|
|
75
|
-
(0, _mocha.it)('should not prematurely strip a possible national prefix from Chinese numbers', function () {
|
|
76
|
-
// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/57
|
|
77
|
-
var phoneNumber = parsePhoneNumber('+86123456789');
|
|
78
|
-
(0, _chai.expect)(phoneNumber.isPossible()).to.equal(true);
|
|
79
|
-
(0, _chai.expect)(phoneNumber.isValid()).to.equal(false);
|
|
80
|
-
(0, _chai.expect)(phoneNumber.nationalNumber).to.equal('123456789');
|
|
81
|
-
});
|
|
82
|
-
(0, _mocha.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 () {
|
|
83
|
-
// Tests that Californian numbers `+1310xxxx` are considered possible.
|
|
84
|
-
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
|
|
85
|
-
|
|
86
|
-
var phoneNumber = parsePhoneNumber('+13100000');
|
|
87
|
-
(0, _chai.expect)(phoneNumber.country).to.equal('CA');
|
|
88
|
-
(0, _chai.expect)(phoneNumber.isPossible()).to.equal(true);
|
|
89
|
-
(0, _chai.expect)(phoneNumber.isValid()).to.equal(true);
|
|
90
|
-
(0, _chai.expect)(phoneNumber.nationalNumber).to.equal('3100000');
|
|
91
|
-
var phoneNumberLocal = parsePhoneNumber('3100000', 'CA');
|
|
92
|
-
(0, _chai.expect)(phoneNumberLocal.country).to.equal('CA');
|
|
93
|
-
(0, _chai.expect)(phoneNumberLocal.isPossible()).to.equal(true);
|
|
94
|
-
(0, _chai.expect)(phoneNumberLocal.isValid()).to.equal(true);
|
|
95
|
-
(0, _chai.expect)(phoneNumberLocal.nationalNumber).to.equal('3100000');
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
//# sourceMappingURL=parsePhoneNumber.test.js.map
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _mocha = require("mocha");
|
|
4
|
-
var _chai = require("chai");
|
|
5
|
-
var _parsePhoneNumberWithError = _interopRequireDefault(require("./parsePhoneNumberWithError.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 parsePhoneNumber() {
|
|
10
|
-
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
11
|
-
parameters[_key] = arguments[_key];
|
|
12
|
-
}
|
|
13
|
-
parameters.push(_metadataMin["default"]);
|
|
14
|
-
return _parsePhoneNumberWithError["default"].apply(this, parameters);
|
|
15
|
-
}
|
|
16
|
-
function parsePhoneNumberFull() {
|
|
17
|
-
for (var _len2 = arguments.length, parameters = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
18
|
-
parameters[_key2] = arguments[_key2];
|
|
19
|
-
}
|
|
20
|
-
parameters.push(_metadataMax["default"]);
|
|
21
|
-
return _parsePhoneNumberWithError["default"].apply(this, parameters);
|
|
22
|
-
}
|
|
23
|
-
(0, _mocha.describe)('parsePhoneNumberWithError', function () {
|
|
24
|
-
(0, _mocha.it)('should parse phone numbers', function () {
|
|
25
|
-
var phoneNumber = parsePhoneNumber('The phone number is: 8 (800) 555 35 35. Some other text.', 'RU');
|
|
26
|
-
(0, _chai.expect)(phoneNumber.country).to.equal('RU');
|
|
27
|
-
(0, _chai.expect)(phoneNumber.countryCallingCode).to.equal('7');
|
|
28
|
-
(0, _chai.expect)(phoneNumber.nationalNumber).to.equal('8005553535');
|
|
29
|
-
(0, _chai.expect)(phoneNumber.number).to.equal('+78005553535');
|
|
30
|
-
(0, _chai.expect)(phoneNumber.isPossible()).to.equal(true);
|
|
31
|
-
(0, _chai.expect)(phoneNumber.isValid()).to.equal(true);
|
|
32
|
-
// phoneNumber.isValidForRegion('RU').should.equal(true)
|
|
33
|
-
// Russian phone type regexps aren't included in default metadata.
|
|
34
|
-
(0, _chai.expect)(parsePhoneNumberFull('Phone: 8 (800) 555 35 35.', 'RU').getType()).to.equal('TOLL_FREE');
|
|
35
|
-
});
|
|
36
|
-
(0, _mocha.it)('shouldn\'t set country when it\'s non-derivable', function () {
|
|
37
|
-
var phoneNumber = parsePhoneNumber('+7 111 555 35 35');
|
|
38
|
-
(0, _chai.expect)(phoneNumber.country).to.be.undefined;
|
|
39
|
-
(0, _chai.expect)(phoneNumber.countryCallingCode).to.equal('7');
|
|
40
|
-
(0, _chai.expect)(phoneNumber.nationalNumber).to.equal('1115553535');
|
|
41
|
-
});
|
|
42
|
-
(0, _mocha.it)('should parse carrier code', function () {
|
|
43
|
-
var phoneNumber = parsePhoneNumber('0 15 21 5555-5555', 'BR');
|
|
44
|
-
(0, _chai.expect)(phoneNumber.carrierCode).to.equal('15');
|
|
45
|
-
});
|
|
46
|
-
(0, _mocha.it)('should parse phone extension', function () {
|
|
47
|
-
var phoneNumber = parsePhoneNumber('Phone: 8 (800) 555 35 35 ext. 1234.', 'RU');
|
|
48
|
-
(0, _chai.expect)(phoneNumber.ext).to.equal('1234');
|
|
49
|
-
});
|
|
50
|
-
(0, _mocha.it)('should validate numbers for countries with no type regular expressions', function () {
|
|
51
|
-
(0, _chai.expect)(parsePhoneNumber('+380391234567').isValid()).to.equal(true);
|
|
52
|
-
(0, _chai.expect)(parsePhoneNumber('+380191234567').isValid()).to.equal(false);
|
|
53
|
-
});
|
|
54
|
-
(0, _mocha.it)('should format numbers', function () {
|
|
55
|
-
var phoneNumber = parsePhoneNumber('Phone: 8 (800) 555 35 35.', 'RU');
|
|
56
|
-
(0, _chai.expect)(phoneNumber.format('NATIONAL')).to.equal('8 (800) 555-35-35');
|
|
57
|
-
(0, _chai.expect)(phoneNumber.formatNational()).to.equal('8 (800) 555-35-35');
|
|
58
|
-
(0, _chai.expect)(phoneNumber.format('INTERNATIONAL')).to.equal('+7 800 555 35 35');
|
|
59
|
-
(0, _chai.expect)(phoneNumber.formatInternational()).to.equal('+7 800 555 35 35');
|
|
60
|
-
});
|
|
61
|
-
(0, _mocha.it)('should get tel: URI', function () {
|
|
62
|
-
var phoneNumber = parsePhoneNumber('Phone: 8 (800) 555 35 35 ext. 1234.', 'RU');
|
|
63
|
-
(0, _chai.expect)(phoneNumber.getURI()).to.equal('tel:+78005553535;ext=1234');
|
|
64
|
-
});
|
|
65
|
-
(0, _mocha.it)('should work in edge cases', function () {
|
|
66
|
-
(0, _chai.expect)(function () {
|
|
67
|
-
return parsePhoneNumber('+78005553535', -1, {});
|
|
68
|
-
}).to["throw"]('Invalid second argument');
|
|
69
|
-
});
|
|
70
|
-
(0, _mocha.it)('should throw parse errors', function () {
|
|
71
|
-
(0, _chai.expect)(function () {
|
|
72
|
-
return parsePhoneNumber('8005553535', 'XX');
|
|
73
|
-
}).to["throw"]('INVALID_COUNTRY');
|
|
74
|
-
(0, _chai.expect)(function () {
|
|
75
|
-
return parsePhoneNumber('+', 'RU');
|
|
76
|
-
}).to["throw"]('NOT_A_NUMBER');
|
|
77
|
-
(0, _chai.expect)(function () {
|
|
78
|
-
return parsePhoneNumber('a', 'RU');
|
|
79
|
-
}).to["throw"]('NOT_A_NUMBER');
|
|
80
|
-
(0, _chai.expect)(function () {
|
|
81
|
-
return parsePhoneNumber('1', 'RU');
|
|
82
|
-
}).to["throw"]('TOO_SHORT');
|
|
83
|
-
(0, _chai.expect)(function () {
|
|
84
|
-
return parsePhoneNumber('+4');
|
|
85
|
-
}).to["throw"]('TOO_SHORT');
|
|
86
|
-
(0, _chai.expect)(function () {
|
|
87
|
-
return parsePhoneNumber('+44');
|
|
88
|
-
}).to["throw"]('TOO_SHORT');
|
|
89
|
-
(0, _chai.expect)(function () {
|
|
90
|
-
return parsePhoneNumber('+443');
|
|
91
|
-
}).to["throw"]('TOO_SHORT');
|
|
92
|
-
(0, _chai.expect)(function () {
|
|
93
|
-
return parsePhoneNumber('+370');
|
|
94
|
-
}).to["throw"]('TOO_SHORT');
|
|
95
|
-
(0, _chai.expect)(function () {
|
|
96
|
-
return parsePhoneNumber('88888888888888888888', 'RU');
|
|
97
|
-
}).to["throw"]('TOO_LONG');
|
|
98
|
-
(0, _chai.expect)(function () {
|
|
99
|
-
return parsePhoneNumber('8 (800) 555 35 35');
|
|
100
|
-
}).to["throw"]('INVALID_COUNTRY');
|
|
101
|
-
(0, _chai.expect)(function () {
|
|
102
|
-
return parsePhoneNumber('+9991112233');
|
|
103
|
-
}).to["throw"]('INVALID_COUNTRY');
|
|
104
|
-
(0, _chai.expect)(function () {
|
|
105
|
-
return parsePhoneNumber('+9991112233', 'US');
|
|
106
|
-
}).to["throw"]('INVALID_COUNTRY');
|
|
107
|
-
(0, _chai.expect)(function () {
|
|
108
|
-
return parsePhoneNumber('8005553535 ', 'RU');
|
|
109
|
-
}).to["throw"]('TOO_LONG');
|
|
110
|
-
});
|
|
111
|
-
(0, _mocha.it)('should parse incorrect international phone numbers', function () {
|
|
112
|
-
// Parsing national prefixes and carrier codes
|
|
113
|
-
// is only required for local phone numbers
|
|
114
|
-
// but some people don't understand that
|
|
115
|
-
// and sometimes write international phone numbers
|
|
116
|
-
// with national prefixes (or maybe even carrier codes).
|
|
117
|
-
// http://ucken.blogspot.ru/2016/03/trunk-prefixes-in-skype4b.html
|
|
118
|
-
// Google's original library forgives such mistakes
|
|
119
|
-
// and so does this library, because it has been requested:
|
|
120
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/127
|
|
121
|
-
|
|
122
|
-
var phoneNumber;
|
|
123
|
-
|
|
124
|
-
// For complete numbers it should strip national prefix.
|
|
125
|
-
phoneNumber = parsePhoneNumber('+1 1877 215 5230');
|
|
126
|
-
(0, _chai.expect)(phoneNumber.nationalNumber).to.equal('8772155230');
|
|
127
|
-
(0, _chai.expect)(phoneNumber.country).to.equal('US');
|
|
128
|
-
|
|
129
|
-
// For complete numbers it should strip national prefix.
|
|
130
|
-
phoneNumber = parsePhoneNumber('+7 8800 555 3535');
|
|
131
|
-
(0, _chai.expect)(phoneNumber.nationalNumber).to.equal('8005553535');
|
|
132
|
-
(0, _chai.expect)(phoneNumber.country).to.equal('RU');
|
|
133
|
-
|
|
134
|
-
// For incomplete numbers it shouldn't strip national prefix.
|
|
135
|
-
phoneNumber = parsePhoneNumber('+7 8800 555 353');
|
|
136
|
-
(0, _chai.expect)(phoneNumber.nationalNumber).to.equal('8800555353');
|
|
137
|
-
(0, _chai.expect)(phoneNumber.country).to.equal('RU');
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
//# sourceMappingURL=parsePhoneNumberWithError.test.js.map
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _mocha = require("mocha");
|
|
4
|
-
var _chai = require("chai");
|
|
5
|
-
var _searchPhoneNumbersInText = _interopRequireDefault(require("./searchPhoneNumbersInText.js"));
|
|
6
|
-
var _metadataMin = _interopRequireDefault(require("../metadata.min.json"));
|
|
7
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
8
|
-
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."); }
|
|
9
|
-
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; } }
|
|
10
|
-
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; }
|
|
11
|
-
(0, _mocha.describe)('searchPhoneNumbersInText', function () {
|
|
12
|
-
(0, _mocha.it)('should find phone numbers (with default country)', function () {
|
|
13
|
-
var NUMBERS = ['+78005553535', '+12133734253'];
|
|
14
|
-
for (var _iterator = _createForOfIteratorHelperLoose((0, _searchPhoneNumbersInText["default"])('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', _metadataMin["default"])), _step; !(_step = _iterator()).done;) {
|
|
15
|
-
var number = _step.value;
|
|
16
|
-
(0, _chai.expect)(number.number.number).to.equal(NUMBERS[0]);
|
|
17
|
-
NUMBERS.shift();
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
(0, _mocha.it)('should find phone numbers', function () {
|
|
21
|
-
var NUMBERS = ['+78005553535', '+12133734253'];
|
|
22
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose((0, _searchPhoneNumbersInText["default"])('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', _metadataMin["default"])), _step2; !(_step2 = _iterator2()).done;) {
|
|
23
|
-
var number = _step2.value;
|
|
24
|
-
(0, _chai.expect)(number.number.number).to.equal(NUMBERS[0]);
|
|
25
|
-
NUMBERS.shift();
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
(0, _mocha.it)('should find phone numbers in text', function () {
|
|
29
|
-
var expectedNumbers = [{
|
|
30
|
-
country: 'RU',
|
|
31
|
-
nationalNumber: '8005553535',
|
|
32
|
-
startsAt: 14,
|
|
33
|
-
endsAt: 32
|
|
34
|
-
}, {
|
|
35
|
-
country: 'US',
|
|
36
|
-
nationalNumber: '2133734253',
|
|
37
|
-
startsAt: 41,
|
|
38
|
-
endsAt: 55
|
|
39
|
-
}];
|
|
40
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose((0, _searchPhoneNumbersInText["default"])('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', _metadataMin["default"])), _step3; !(_step3 = _iterator3()).done;) {
|
|
41
|
-
var number = _step3.value;
|
|
42
|
-
var expected = expectedNumbers.shift();
|
|
43
|
-
(0, _chai.expect)(number.startsAt).to.equal(expected.startsAt);
|
|
44
|
-
(0, _chai.expect)(number.endsAt).to.equal(expected.endsAt);
|
|
45
|
-
(0, _chai.expect)(number.number.nationalNumber).to.equal(expected.nationalNumber);
|
|
46
|
-
(0, _chai.expect)(number.number.country).to.equal(expected.country);
|
|
47
|
-
}
|
|
48
|
-
(0, _chai.expect)(expectedNumbers.length).to.equal(0);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
//# sourceMappingURL=searchPhoneNumbersInText.test.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _mocha = require("mocha");
|
|
4
|
-
var _chai = require("chai");
|
|
5
|
-
var _semverCompare = _interopRequireDefault(require("./semver-compare.js"));
|
|
6
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
7
|
-
(0, _mocha.describe)('semver-compare', function () {
|
|
8
|
-
(0, _mocha.it)('should compare versions', function () {
|
|
9
|
-
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'];
|
|
10
|
-
(0, _chai.expect)(versions.sort(_semverCompare["default"])).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']);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
//# sourceMappingURL=semver-compare.test.js.map
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _mocha = require("mocha");
|
|
4
|
-
var _chai = require("chai");
|
|
5
|
-
var _validatePhoneNumberLength2 = _interopRequireDefault(require("./validatePhoneNumberLength.js"));
|
|
6
|
-
var _metadataMin = _interopRequireDefault(require("../metadata.min.json"));
|
|
7
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
8
|
-
function validatePhoneNumberLength() {
|
|
9
|
-
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
10
|
-
parameters[_key] = arguments[_key];
|
|
11
|
-
}
|
|
12
|
-
parameters.push(_metadataMin["default"]);
|
|
13
|
-
return _validatePhoneNumberLength2["default"].apply(this, parameters);
|
|
14
|
-
}
|
|
15
|
-
(0, _mocha.describe)('validatePhoneNumberLength', function () {
|
|
16
|
-
(0, _mocha.it)('should detect whether a phone number length is valid', function () {
|
|
17
|
-
// Not a phone number.
|
|
18
|
-
(0, _chai.expect)(validatePhoneNumberLength('+')).to.equal('NOT_A_NUMBER');
|
|
19
|
-
(0, _chai.expect)(validatePhoneNumberLength('abcde')).to.equal('NOT_A_NUMBER');
|
|
20
|
-
|
|
21
|
-
// No country supplied for a national number.
|
|
22
|
-
(0, _chai.expect)(validatePhoneNumberLength('123')).to.equal('INVALID_COUNTRY');
|
|
23
|
-
|
|
24
|
-
// Too short while the number is not considered "viable"
|
|
25
|
-
// by Google's `libphonenumber`.
|
|
26
|
-
(0, _chai.expect)(validatePhoneNumberLength('2', 'US')).to.equal('TOO_SHORT');
|
|
27
|
-
(0, _chai.expect)(validatePhoneNumberLength('+1', 'US')).to.equal('TOO_SHORT');
|
|
28
|
-
(0, _chai.expect)(validatePhoneNumberLength('+12', 'US')).to.equal('TOO_SHORT');
|
|
29
|
-
|
|
30
|
-
// Test national (significant) number length.
|
|
31
|
-
(0, _chai.expect)(validatePhoneNumberLength('444 1 44', 'TR')).to.equal('TOO_SHORT');
|
|
32
|
-
(0, _chai.expect)(validatePhoneNumberLength('444 1 444', 'TR')).to.be.undefined;
|
|
33
|
-
(0, _chai.expect)(validatePhoneNumberLength('444 1 4444', 'TR')).to.equal('INVALID_LENGTH');
|
|
34
|
-
(0, _chai.expect)(validatePhoneNumberLength('444 1 4444444444', 'TR')).to.equal('TOO_LONG');
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
//# sourceMappingURL=validatePhoneNumberLength.test.js.map
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// (deprecated because unused)
|
|
2
|
-
|
|
3
|
-
// * Creates a pull request in the github repository from a local "metadata-update" branch.
|
|
4
|
-
// * Deletes the "metadata-update" branch.
|
|
5
|
-
|
|
6
|
-
// In order for this script to work:
|
|
7
|
-
//
|
|
8
|
-
// * Install `hub` command line tool: https://hub.github.com/
|
|
9
|
-
// * Create a "Personal Access Token" in GitHub account settings (just "repo_public" would be enough)
|
|
10
|
-
// * Tell `hub` to use the token for creating GitHub pull requests: `echo "---\ngithub.com:\n- protocol: https\n user: GITHUB_USERNAME\n oauth_token: TOKEN" >> ~/.config/hub`
|
|
11
|
-
|
|
12
|
-
import updateMetadataFromGoogleMetadata from './helpers/updateMetadataFromGoogleMetadata.js'
|
|
13
|
-
import commit from './helpers/commit.js'
|
|
14
|
-
import exec from './helpers/exec.js'
|
|
15
|
-
|
|
16
|
-
const googleMetadataFilePath = process.argv[2]
|
|
17
|
-
const metadataInfoFilePath = process.argv[3]
|
|
18
|
-
|
|
19
|
-
// This script is meant to be run from a local "update-metadata" branch.
|
|
20
|
-
// See `createMetadataUpdateBranch()` function for how it could be set up.
|
|
21
|
-
throw new Error('Run `createMetadataUpdateBranch()` function first')
|
|
22
|
-
|
|
23
|
-
const metadataChanged = updateMetadataFromGoogleMetadata(googleMetadataFilePath, metadataInfoFilePath)
|
|
24
|
-
|
|
25
|
-
if (metadataChanged) {
|
|
26
|
-
commit()
|
|
27
|
-
|
|
28
|
-
console.log()
|
|
29
|
-
console.log('========================================')
|
|
30
|
-
console.log('= Pushing changes =')
|
|
31
|
-
console.log('========================================')
|
|
32
|
-
console.log()
|
|
33
|
-
|
|
34
|
-
// Delete pre-existing remote `update-metadata` remote branch
|
|
35
|
-
// (if it already exists)
|
|
36
|
-
if (exec('git ls-remote --heads origin update-metadata'))
|
|
37
|
-
{
|
|
38
|
-
console.log(exec('git push origin update-metadata --delete'))
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Push the local `update-metadata` branch to GitHub
|
|
42
|
-
console.log(exec('git push origin update-metadata'))
|
|
43
|
-
|
|
44
|
-
console.log()
|
|
45
|
-
console.log('========================================')
|
|
46
|
-
console.log('= Pushed. Creating Pull Request. =')
|
|
47
|
-
console.log('========================================')
|
|
48
|
-
console.log()
|
|
49
|
-
|
|
50
|
-
console.log(exec('hub pull-request -m "Updated metadata" -b catamphetamine/libphonenumber-js:master -h update-metadata'))
|
|
51
|
-
|
|
52
|
-
console.log()
|
|
53
|
-
console.log('========================================')
|
|
54
|
-
console.log('= Pull Request created =')
|
|
55
|
-
console.log('========================================')
|
|
56
|
-
console.log()
|
|
57
|
-
|
|
58
|
-
console.log(exec('git checkout master'))
|
|
59
|
-
console.log(exec('git branch -D update-metadata'))
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// This function creates "update-metadata" branch and switches into it.
|
|
63
|
-
function createMetadataUpdateBranch() {
|
|
64
|
-
let metadata_branch_exists = false
|
|
65
|
-
|
|
66
|
-
try
|
|
67
|
-
{
|
|
68
|
-
exec('git rev-parse --verify update-metadata')
|
|
69
|
-
metadata_branch_exists = true
|
|
70
|
-
}
|
|
71
|
-
catch (error)
|
|
72
|
-
{
|
|
73
|
-
if (error.message.indexOf('fatal: Needed a single revision') === -1)
|
|
74
|
-
{
|
|
75
|
-
throw error
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (metadata_branch_exists)
|
|
80
|
-
{
|
|
81
|
-
console.log(exec('git checkout master'))
|
|
82
|
-
console.log(exec('git branch -D update-metadata'))
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
console.log(exec('git pull'))
|
|
86
|
-
console.log(exec('git branch update-metadata origin/master'))
|
|
87
|
-
console.log(exec('git checkout update-metadata'))
|
|
88
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// Pulls the latest metadata from Google's repo, and, if it has changed,
|
|
2
|
-
// pushes the changes in the main branch and releases a new version on `npm`.
|
|
3
|
-
|
|
4
|
-
import updateMetadataFromGoogleMetadata from './helpers/updateMetadataFromGoogleMetadata.js'
|
|
5
|
-
import commit from './helpers/commit.js'
|
|
6
|
-
import exec from './helpers/exec.js'
|
|
7
|
-
import sendEmail from './helpers/sendEmail.js'
|
|
8
|
-
|
|
9
|
-
const googleMetadataFilePath = process.argv[2]
|
|
10
|
-
const metadataInfoFilePath = process.argv[3]
|
|
11
|
-
|
|
12
|
-
const metadataChanged = updateMetadataFromGoogleMetadata(googleMetadataFilePath, metadataInfoFilePath)
|
|
13
|
-
|
|
14
|
-
if (metadataChanged) {
|
|
15
|
-
commit()
|
|
16
|
-
|
|
17
|
-
console.log()
|
|
18
|
-
console.log('========================================')
|
|
19
|
-
console.log('= Push the changes to the repository =')
|
|
20
|
-
console.log('========================================')
|
|
21
|
-
console.log()
|
|
22
|
-
|
|
23
|
-
console.log(exec('git push'))
|
|
24
|
-
|
|
25
|
-
console.log()
|
|
26
|
-
console.log('========================================')
|
|
27
|
-
console.log('= Increment the version =')
|
|
28
|
-
console.log('========================================')
|
|
29
|
-
console.log()
|
|
30
|
-
|
|
31
|
-
console.log(exec('npm version patch'))
|
|
32
|
-
console.log(exec('git push'))
|
|
33
|
-
|
|
34
|
-
console.log()
|
|
35
|
-
console.log('========================================')
|
|
36
|
-
console.log('= Publish the new version =')
|
|
37
|
-
console.log('========================================')
|
|
38
|
-
console.log()
|
|
39
|
-
|
|
40
|
-
// `npm` requires "two-factor authentication", so running an `npm publish`
|
|
41
|
-
// command programmatically won't work without human intervention.
|
|
42
|
-
//
|
|
43
|
-
// To work around that, one could optionally specify GMail credentials.
|
|
44
|
-
// In that case, instead of attempting to run `npm publish` command,
|
|
45
|
-
// it will send an email notification to do that manually.
|
|
46
|
-
//
|
|
47
|
-
if (await sendEmail({
|
|
48
|
-
// Send an email notification about manually publishing the new version of the package to `npm`.
|
|
49
|
-
subject: '[libphonenumber-js] Publish a new version',
|
|
50
|
-
text: 'A new version of `libphonenumber-js` has been pushed to the repository:\nhttps://gitlab.com/catamphetamine/libphonenumber-js/-/commits/master\n\nRun `npm publish` in `libphonenumber-js` directory to publish the new version.'
|
|
51
|
-
})) {
|
|
52
|
-
console.log()
|
|
53
|
-
console.log('==========================================================')
|
|
54
|
-
console.log('= Email notification sent. Publish the package manually. =')
|
|
55
|
-
console.log('==========================================================')
|
|
56
|
-
console.log()
|
|
57
|
-
} else {
|
|
58
|
-
// Attempt to publish the `npm` package.
|
|
59
|
-
console.log(exec('npm publish'))
|
|
60
|
-
|
|
61
|
-
console.log()
|
|
62
|
-
console.log('========================================')
|
|
63
|
-
console.log('= Published =')
|
|
64
|
-
console.log('========================================')
|
|
65
|
-
console.log()
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import getUncommittedChanges from './helpers/getUncommittedChanges.js';
|
|
2
|
-
import sendEmail from './helpers/sendEmail.js'
|
|
3
|
-
|
|
4
|
-
const uncommittedChanges = await getUncommittedChanges()
|
|
5
|
-
if (uncommittedChanges.length > 0) {
|
|
6
|
-
const errorText = `You have uncommitted files in your repository:\n\n${uncommittedChanges.map(({ filename }) => filename).join('\n')}`
|
|
7
|
-
console.error(new Error(errorText))
|
|
8
|
-
await sendEmail({
|
|
9
|
-
subject: '[libphonenumber-js] Uncommitted changes found',
|
|
10
|
-
text: errorText
|
|
11
|
-
})
|
|
12
|
-
process.exit(1)
|
|
13
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Creates a `package.json` file in the CommonJS `build` folder.
|
|
2
|
-
// That marks that whole folder as CommonJS so that Node.js doesn't complain
|
|
3
|
-
// about `require()`-ing those files.
|
|
4
|
-
|
|
5
|
-
import fs from 'fs'
|
|
6
|
-
|
|
7
|
-
fs.writeFileSync('./build/package.json', JSON.stringify({
|
|
8
|
-
name: 'libphonenumber-js/build',
|
|
9
|
-
type: 'commonjs',
|
|
10
|
-
private: true
|
|
11
|
-
}, null, 2), 'utf8')
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
|
|
3
|
-
const COMMENT = '// This file is a workaround for a bug in web browsers\' "native"' + '\n' +
|
|
4
|
-
'// ES6 importing system which is uncapable of importing "*.json" files.' + '\n' +
|
|
5
|
-
'// https://github.com/catamphetamine/libphonenumber-js/issues/239'
|
|
6
|
-
|
|
7
|
-
const path = process.argv[2]
|
|
8
|
-
createJsFileForJsonFile(path)
|
|
9
|
-
|
|
10
|
-
function createJsFileForJsonFile(path) {
|
|
11
|
-
let contents = fs.readFileSync(path, 'utf-8')
|
|
12
|
-
contents = COMMENT + '\n' + 'export default ' + contents
|
|
13
|
-
fs.writeFileSync(path + '.js', contents)
|
|
14
|
-
}
|