🎯 MapView v2.0 - Global Deployment Ready

 MAJOR FEATURES:
• Auto-zoom intelligence với smart bounds fitting
• Enhanced 3D GPS markers với pulsing effects
• Professional route display với 6-layer rendering
• Status-based parking icons với availability indicators
• Production-ready build optimizations

🗺️ AUTO-ZOOM FEATURES:
• Smart bounds fitting cho GPS + selected parking
• Adaptive padding (50px) cho visual balance
• Max zoom control (level 16) để tránh quá gần
• Dynamic centering khi không có selection

🎨 ENHANCED VISUALS:
• 3D GPS marker với multi-layer pulse effects
• Advanced parking icons với status colors
• Selection highlighting với animation
• Dimming system cho non-selected items

🛣️ ROUTE SYSTEM:
• OpenRouteService API integration
• Multi-layer route rendering (glow, shadow, main, animated)
• Real-time distance & duration calculation
• Visual route info trong popup

📱 PRODUCTION READY:
• SSR safe với dynamic imports
• Build errors resolved
• Global deployment via Vercel
• Optimized performance

🌍 DEPLOYMENT:
• Vercel: https://whatever-ctk2auuxr-phong12hexdockworks-projects.vercel.app
• Bundle size: 22.8 kB optimized
• Global CDN distribution
• HTTPS enabled

💾 VERSION CONTROL:
• MapView-v2.0.tsx backup created
• MAPVIEW_VERSIONS.md documentation
• Full version history tracking
This commit is contained in:
2025-07-20 19:52:16 +07:00
parent 3203463a6a
commit c65cc97a33
64624 changed files with 7199453 additions and 6462 deletions

View File

@@ -0,0 +1,102 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.formatRFC3966 = formatRFC3966;
exports.parseRFC3966 = parseRFC3966;
var _isViablePhoneNumber = _interopRequireDefault(require("./isViablePhoneNumber.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
// https://www.ietf.org/rfc/rfc3966.txt
/**
* @param {string} text - Phone URI (RFC 3966).
* @return {object} `{ ?number, ?ext }`.
*/
function parseRFC3966(text) {
var number;
var ext; // Replace "tel:" with "tel=" for parsing convenience.
text = text.replace(/^tel:/, 'tel=');
for (var _iterator = _createForOfIteratorHelperLoose(text.split(';')), _step; !(_step = _iterator()).done;) {
var part = _step.value;
var _part$split = part.split('='),
_part$split2 = _slicedToArray(_part$split, 2),
name = _part$split2[0],
value = _part$split2[1];
switch (name) {
case 'tel':
number = value;
break;
case 'ext':
ext = value;
break;
case 'phone-context':
// Only "country contexts" are supported.
// "Domain contexts" are ignored.
if (value[0] === '+') {
number = value + number;
}
break;
}
} // If the phone number is not viable, then abort.
if (!(0, _isViablePhoneNumber["default"])(number)) {
return {};
}
var result = {
number: number
};
if (ext) {
result.ext = ext;
}
return result;
}
/**
* @param {object} - `{ ?number, ?extension }`.
* @return {string} Phone URI (RFC 3966).
*/
function formatRFC3966(_ref) {
var number = _ref.number,
ext = _ref.ext;
if (!number) {
return '';
}
if (number[0] !== '+') {
throw new Error("\"formatRFC3966()\" expects \"number\" to be in E.164 format.");
}
return "tel:".concat(number).concat(ext ? ';ext=' + ext : '');
}
//# sourceMappingURL=RFC3966.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"RFC3966.js","names":["parseRFC3966","text","number","ext","replace","split","part","name","value","isViablePhoneNumber","result","formatRFC3966","Error"],"sources":["../../source/helpers/RFC3966.js"],"sourcesContent":["import isViablePhoneNumber from './isViablePhoneNumber.js'\r\n\r\n// https://www.ietf.org/rfc/rfc3966.txt\r\n\r\n/**\r\n * @param {string} text - Phone URI (RFC 3966).\r\n * @return {object} `{ ?number, ?ext }`.\r\n */\r\nexport function parseRFC3966(text) {\r\n\tlet number\r\n\tlet ext\r\n\r\n\t// Replace \"tel:\" with \"tel=\" for parsing convenience.\r\n\ttext = text.replace(/^tel:/, 'tel=')\r\n\r\n\tfor (const part of text.split(';')) {\r\n\t\tconst [name, value] = part.split('=')\r\n\t\tswitch (name) {\r\n\t\t\tcase 'tel':\r\n\t\t\t\tnumber = value\r\n\t\t\t\tbreak\r\n\t\t\tcase 'ext':\r\n\t\t\t\text = value\r\n\t\t\t\tbreak\r\n\t\t\tcase 'phone-context':\r\n\t\t\t\t// Only \"country contexts\" are supported.\r\n\t\t\t\t// \"Domain contexts\" are ignored.\r\n\t\t\t\tif (value[0] === '+') {\r\n\t\t\t\t\tnumber = value + number\r\n\t\t\t\t}\r\n\t\t\t\tbreak\r\n\t\t}\r\n\t}\r\n\r\n\t// If the phone number is not viable, then abort.\r\n\tif (!isViablePhoneNumber(number)) {\r\n\t\treturn {}\r\n\t}\r\n\r\n\tconst result = { number }\r\n\tif (ext) {\r\n\t\tresult.ext = ext\r\n\t}\r\n\treturn result\r\n}\r\n\r\n/**\r\n * @param {object} - `{ ?number, ?extension }`.\r\n * @return {string} Phone URI (RFC 3966).\r\n */\r\nexport function formatRFC3966({ number, ext }) {\r\n\tif (!number) {\r\n\t\treturn ''\r\n\t}\r\n\tif (number[0] !== '+') {\r\n\t\tthrow new Error(`\"formatRFC3966()\" expects \"number\" to be in E.164 format.`)\r\n\t}\r\n\treturn `tel:${number}${ext ? ';ext=' + ext : ''}`\r\n}"],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;;;;;;;AAEA;;AAEA;AACA;AACA;AACA;AACO,SAASA,YAAT,CAAsBC,IAAtB,EAA4B;EAClC,IAAIC,MAAJ;EACA,IAAIC,GAAJ,CAFkC,CAIlC;;EACAF,IAAI,GAAGA,IAAI,CAACG,OAAL,CAAa,OAAb,EAAsB,MAAtB,CAAP;;EAEA,qDAAmBH,IAAI,CAACI,KAAL,CAAW,GAAX,CAAnB,wCAAoC;IAAA,IAAzBC,IAAyB;;IACnC,kBAAsBA,IAAI,CAACD,KAAL,CAAW,GAAX,CAAtB;IAAA;IAAA,IAAOE,IAAP;IAAA,IAAaC,KAAb;;IACA,QAAQD,IAAR;MACC,KAAK,KAAL;QACCL,MAAM,GAAGM,KAAT;QACA;;MACD,KAAK,KAAL;QACCL,GAAG,GAAGK,KAAN;QACA;;MACD,KAAK,eAAL;QACC;QACA;QACA,IAAIA,KAAK,CAAC,CAAD,CAAL,KAAa,GAAjB,EAAsB;UACrBN,MAAM,GAAGM,KAAK,GAAGN,MAAjB;QACA;;QACD;IAbF;EAeA,CAxBiC,CA0BlC;;;EACA,IAAI,CAAC,IAAAO,+BAAA,EAAoBP,MAApB,CAAL,EAAkC;IACjC,OAAO,EAAP;EACA;;EAED,IAAMQ,MAAM,GAAG;IAAER,MAAM,EAANA;EAAF,CAAf;;EACA,IAAIC,GAAJ,EAAS;IACRO,MAAM,CAACP,GAAP,GAAaA,GAAb;EACA;;EACD,OAAOO,MAAP;AACA;AAED;AACA;AACA;AACA;;;AACO,SAASC,aAAT,OAAwC;EAAA,IAAfT,MAAe,QAAfA,MAAe;EAAA,IAAPC,GAAO,QAAPA,GAAO;;EAC9C,IAAI,CAACD,MAAL,EAAa;IACZ,OAAO,EAAP;EACA;;EACD,IAAIA,MAAM,CAAC,CAAD,CAAN,KAAc,GAAlB,EAAuB;IACtB,MAAM,IAAIU,KAAJ,iEAAN;EACA;;EACD,qBAAcV,MAAd,SAAuBC,GAAG,GAAG,UAAUA,GAAb,GAAmB,EAA7C;AACA"}

View File

@@ -0,0 +1,43 @@
"use strict";
var _RFC = require("./RFC3966.js");
describe('RFC3966', function () {
it('should format', function () {
expect(function () {
return (0, _RFC.formatRFC3966)({
number: '123'
});
}).to["throw"]('expects "number" to be in E.164 format');
(0, _RFC.formatRFC3966)({}).should.equal('');
(0, _RFC.formatRFC3966)({
number: '+78005553535'
}).should.equal('tel:+78005553535');
(0, _RFC.formatRFC3966)({
number: '+78005553535',
ext: '123'
}).should.equal('tel:+78005553535;ext=123');
});
it('should parse', function () {
(0, _RFC.parseRFC3966)('tel:+78005553535').should.deep.equal({
number: '+78005553535'
});
(0, _RFC.parseRFC3966)('tel:+78005553535;ext=123').should.deep.equal({
number: '+78005553535',
ext: '123'
}); // With `phone-context`
(0, _RFC.parseRFC3966)('tel:8005553535;ext=123;phone-context=+7').should.deep.equal({
number: '+78005553535',
ext: '123'
}); // "Domain contexts" are ignored
(0, _RFC.parseRFC3966)('tel:8005553535;ext=123;phone-context=www.leningrad.spb.ru').should.deep.equal({
number: '8005553535',
ext: '123'
}); // Not a viable phone number.
(0, _RFC.parseRFC3966)('tel:3').should.deep.equal({});
});
});
//# sourceMappingURL=RFC3966.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"RFC3966.test.js","names":["describe","it","expect","formatRFC3966","number","to","should","equal","ext","parseRFC3966","deep"],"sources":["../../source/helpers/RFC3966.test.js"],"sourcesContent":["import { parseRFC3966, formatRFC3966 } from './RFC3966.js'\r\n\r\ndescribe('RFC3966', () => {\r\n\tit('should format', () => {\r\n\t\texpect(() => formatRFC3966({ number: '123' })).to.throw('expects \"number\" to be in E.164 format')\r\n\t\tformatRFC3966({}).should.equal('')\r\n\t\tformatRFC3966({ number: '+78005553535' }).should.equal('tel:+78005553535')\r\n\t\tformatRFC3966({ number: '+78005553535', ext: '123' }).should.equal('tel:+78005553535;ext=123')\r\n\t})\r\n\r\n\tit('should parse', () => {\r\n\t\tparseRFC3966('tel:+78005553535').should.deep.equal({\r\n\t\t\tnumber : '+78005553535'\r\n\t\t})\r\n\r\n\t\tparseRFC3966('tel:+78005553535;ext=123').should.deep.equal({\r\n\t\t\tnumber : '+78005553535',\r\n\t\t\text : '123'\r\n\t\t})\r\n\r\n\t\t// With `phone-context`\r\n\t\tparseRFC3966('tel:8005553535;ext=123;phone-context=+7').should.deep.equal({\r\n\t\t\tnumber : '+78005553535',\r\n\t\t\text : '123'\r\n\t\t})\r\n\r\n\t\t// \"Domain contexts\" are ignored\r\n\t\tparseRFC3966('tel:8005553535;ext=123;phone-context=www.leningrad.spb.ru').should.deep.equal({\r\n\t\t\tnumber : '8005553535',\r\n\t\t\text : '123'\r\n\t\t})\r\n\r\n\t\t// Not a viable phone number.\r\n\t\tparseRFC3966('tel:3').should.deep.equal({})\r\n\t})\r\n})\r\n"],"mappings":";;AAAA;;AAEAA,QAAQ,CAAC,SAAD,EAAY,YAAM;EACzBC,EAAE,CAAC,eAAD,EAAkB,YAAM;IACzBC,MAAM,CAAC;MAAA,OAAM,IAAAC,kBAAA,EAAc;QAAEC,MAAM,EAAE;MAAV,CAAd,CAAN;IAAA,CAAD,CAAN,CAA+CC,EAA/C,UAAwD,wCAAxD;IACA,IAAAF,kBAAA,EAAc,EAAd,EAAkBG,MAAlB,CAAyBC,KAAzB,CAA+B,EAA/B;IACA,IAAAJ,kBAAA,EAAc;MAAEC,MAAM,EAAE;IAAV,CAAd,EAA0CE,MAA1C,CAAiDC,KAAjD,CAAuD,kBAAvD;IACA,IAAAJ,kBAAA,EAAc;MAAEC,MAAM,EAAE,cAAV;MAA0BI,GAAG,EAAE;IAA/B,CAAd,EAAsDF,MAAtD,CAA6DC,KAA7D,CAAmE,0BAAnE;EACA,CALC,CAAF;EAOAN,EAAE,CAAC,cAAD,EAAiB,YAAM;IACxB,IAAAQ,iBAAA,EAAa,kBAAb,EAAiCH,MAAjC,CAAwCI,IAAxC,CAA6CH,KAA7C,CAAmD;MAClDH,MAAM,EAAG;IADyC,CAAnD;IAIA,IAAAK,iBAAA,EAAa,0BAAb,EAAyCH,MAAzC,CAAgDI,IAAhD,CAAqDH,KAArD,CAA2D;MAC1DH,MAAM,EAAG,cADiD;MAE1DI,GAAG,EAAM;IAFiD,CAA3D,EALwB,CAUxB;;IACA,IAAAC,iBAAA,EAAa,yCAAb,EAAwDH,MAAxD,CAA+DI,IAA/D,CAAoEH,KAApE,CAA0E;MACzEH,MAAM,EAAG,cADgE;MAEzEI,GAAG,EAAM;IAFgE,CAA1E,EAXwB,CAgBxB;;IACA,IAAAC,iBAAA,EAAa,2DAAb,EAA0EH,MAA1E,CAAiFI,IAAjF,CAAsFH,KAAtF,CAA4F;MAC3FH,MAAM,EAAG,YADkF;MAE3FI,GAAG,EAAM;IAFkF,CAA5F,EAjBwB,CAsBxB;;IACA,IAAAC,iBAAA,EAAa,OAAb,EAAsBH,MAAtB,CAA6BI,IAA7B,CAAkCH,KAAlC,CAAwC,EAAxC;EACA,CAxBC,CAAF;AAyBA,CAjCO,CAAR"}

View File

@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = applyInternationalSeparatorStyle;
var _constants = require("../constants.js");
// Removes brackets and replaces dashes with spaces.
//
// E.g. "(999) 111-22-33" -> "999 111 22 33"
//
// For some reason Google's metadata contains `<intlFormat/>`s with brackets and dashes.
// Meanwhile, there's no single opinion about using punctuation in international phone numbers.
//
// For example, Google's `<intlFormat/>` for USA is `+1 213-373-4253`.
// And here's a quote from WikiPedia's "North American Numbering Plan" page:
// https://en.wikipedia.org/wiki/North_American_Numbering_Plan
//
// "The country calling code for all countries participating in the NANP is 1.
// In international format, an NANP number should be listed as +1 301 555 01 00,
// where 301 is an area code (Maryland)."
//
// I personally prefer the international format without any punctuation.
// For example, brackets are remnants of the old age, meaning that the
// phone number part in brackets (so called "area code") can be omitted
// if dialing within the same "area".
// And hyphens were clearly introduced for splitting local numbers into memorizable groups.
// For example, remembering "5553535" is difficult but "555-35-35" is much simpler.
// Imagine a man taking a bus from home to work and seeing an ad with a phone number.
// He has a couple of seconds to memorize that number until it passes by.
// If it were spaces instead of hyphens the man wouldn't necessarily get it,
// but with hyphens instead of spaces the grouping is more explicit.
// I personally think that hyphens introduce visual clutter,
// so I prefer replacing them with spaces in international numbers.
// In the modern age all output is done on displays where spaces are clearly distinguishable
// so hyphens can be safely replaced with spaces without losing any legibility.
//
function applyInternationalSeparatorStyle(formattedNumber) {
return formattedNumber.replace(new RegExp("[".concat(_constants.VALID_PUNCTUATION, "]+"), 'g'), ' ').trim();
}
//# sourceMappingURL=applyInternationalSeparatorStyle.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"applyInternationalSeparatorStyle.js","names":["applyInternationalSeparatorStyle","formattedNumber","replace","RegExp","VALID_PUNCTUATION","trim"],"sources":["../../source/helpers/applyInternationalSeparatorStyle.js"],"sourcesContent":["import { VALID_PUNCTUATION } from '../constants.js'\r\n\r\n// Removes brackets and replaces dashes with spaces.\r\n//\r\n// E.g. \"(999) 111-22-33\" -> \"999 111 22 33\"\r\n//\r\n// For some reason Google's metadata contains `<intlFormat/>`s with brackets and dashes.\r\n// Meanwhile, there's no single opinion about using punctuation in international phone numbers.\r\n//\r\n// For example, Google's `<intlFormat/>` for USA is `+1 213-373-4253`.\r\n// And here's a quote from WikiPedia's \"North American Numbering Plan\" page:\r\n// https://en.wikipedia.org/wiki/North_American_Numbering_Plan\r\n//\r\n// \"The country calling code for all countries participating in the NANP is 1.\r\n// In international format, an NANP number should be listed as +1 301 555 01 00,\r\n// where 301 is an area code (Maryland).\"\r\n//\r\n// I personally prefer the international format without any punctuation.\r\n// For example, brackets are remnants of the old age, meaning that the\r\n// phone number part in brackets (so called \"area code\") can be omitted\r\n// if dialing within the same \"area\".\r\n// And hyphens were clearly introduced for splitting local numbers into memorizable groups.\r\n// For example, remembering \"5553535\" is difficult but \"555-35-35\" is much simpler.\r\n// Imagine a man taking a bus from home to work and seeing an ad with a phone number.\r\n// He has a couple of seconds to memorize that number until it passes by.\r\n// If it were spaces instead of hyphens the man wouldn't necessarily get it,\r\n// but with hyphens instead of spaces the grouping is more explicit.\r\n// I personally think that hyphens introduce visual clutter,\r\n// so I prefer replacing them with spaces in international numbers.\r\n// In the modern age all output is done on displays where spaces are clearly distinguishable\r\n// so hyphens can be safely replaced with spaces without losing any legibility.\r\n//\r\nexport default function applyInternationalSeparatorStyle(formattedNumber) {\r\n\treturn formattedNumber.replace(new RegExp(`[${VALID_PUNCTUATION}]+`, 'g'), ' ').trim()\r\n}"],"mappings":";;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,gCAAT,CAA0CC,eAA1C,EAA2D;EACzE,OAAOA,eAAe,CAACC,OAAhB,CAAwB,IAAIC,MAAJ,YAAeC,4BAAf,SAAsC,GAAtC,CAAxB,EAAoE,GAApE,EAAyEC,IAAzE,EAAP;AACA"}

View File

@@ -0,0 +1,13 @@
"use strict";
var _applyInternationalSeparatorStyle = _interopRequireDefault(require("./applyInternationalSeparatorStyle.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
describe('applyInternationalSeparatorStyle', function () {
it('should change Google\'s international format style', function () {
(0, _applyInternationalSeparatorStyle["default"])('(xxx) xxx-xx-xx').should.equal('xxx xxx xx xx');
(0, _applyInternationalSeparatorStyle["default"])('(xxx)xxx').should.equal('xxx xxx');
});
});
//# sourceMappingURL=applyInternationalSeparatorStyle.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"applyInternationalSeparatorStyle.test.js","names":["describe","it","applyInternationalSeparatorStyle","should","equal"],"sources":["../../source/helpers/applyInternationalSeparatorStyle.test.js"],"sourcesContent":["import applyInternationalSeparatorStyle from './applyInternationalSeparatorStyle.js'\r\n\r\ndescribe('applyInternationalSeparatorStyle', () => {\r\n\tit('should change Google\\'s international format style', () => {\r\n\t\tapplyInternationalSeparatorStyle('(xxx) xxx-xx-xx').should.equal('xxx xxx xx xx')\r\n\t\tapplyInternationalSeparatorStyle('(xxx)xxx').should.equal('xxx xxx')\r\n\t})\r\n})"],"mappings":";;AAAA;;;;AAEAA,QAAQ,CAAC,kCAAD,EAAqC,YAAM;EAClDC,EAAE,CAAC,oDAAD,EAAuD,YAAM;IAC9D,IAAAC,4CAAA,EAAiC,iBAAjC,EAAoDC,MAApD,CAA2DC,KAA3D,CAAiE,eAAjE;IACA,IAAAF,4CAAA,EAAiC,UAAjC,EAA6CC,MAA7C,CAAoDC,KAApD,CAA0D,SAA1D;EACA,CAHC,CAAF;AAIA,CALO,CAAR"}

View File

@@ -0,0 +1,92 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.checkNumberLengthForType = checkNumberLengthForType;
exports["default"] = checkNumberLength;
var _mergeArrays = _interopRequireDefault(require("./mergeArrays.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function checkNumberLength(nationalNumber, metadata) {
return checkNumberLengthForType(nationalNumber, undefined, metadata);
} // Checks whether a number is possible for the country based on its length.
// Should only be called for the "new" metadata which has "possible lengths".
function checkNumberLengthForType(nationalNumber, type, metadata) {
var type_info = metadata.type(type); // There should always be "<possiblePengths/>" set for every type element.
// This is declared in the XML schema.
// For size efficiency, where a sub-description (e.g. fixed-line)
// has the same "<possiblePengths/>" as the "general description", this is missing,
// so we fall back to the "general description". Where no numbers of the type
// exist at all, there is one possible length (-1) which is guaranteed
// not to match the length of any real phone number.
var possible_lengths = type_info && type_info.possibleLengths() || metadata.possibleLengths(); // let local_lengths = type_info && type.possibleLengthsLocal() || metadata.possibleLengthsLocal()
// Metadata before version `1.0.18` didn't contain `possible_lengths`.
if (!possible_lengths) {
return 'IS_POSSIBLE';
}
if (type === 'FIXED_LINE_OR_MOBILE') {
// No such country in metadata.
/* istanbul ignore next */
if (!metadata.type('FIXED_LINE')) {
// The rare case has been encountered where no fixedLine data is available
// (true for some non-geographic entities), so we just check mobile.
return checkNumberLengthForType(nationalNumber, 'MOBILE', metadata);
}
var mobile_type = metadata.type('MOBILE');
if (mobile_type) {
// Merge the mobile data in if there was any. "Concat" creates a new
// array, it doesn't edit possible_lengths in place, so we don't need a copy.
// Note that when adding the possible lengths from mobile, we have
// to again check they aren't empty since if they are this indicates
// they are the same as the general desc and should be obtained from there.
possible_lengths = (0, _mergeArrays["default"])(possible_lengths, mobile_type.possibleLengths()); // The current list is sorted; we need to merge in the new list and
// re-sort (duplicates are okay). Sorting isn't so expensive because
// the lists are very small.
// if (local_lengths) {
// local_lengths = mergeArrays(local_lengths, mobile_type.possibleLengthsLocal())
// } else {
// local_lengths = mobile_type.possibleLengthsLocal()
// }
}
} // If the type doesn't exist then return 'INVALID_LENGTH'.
else if (type && !type_info) {
return 'INVALID_LENGTH';
}
var actual_length = nationalNumber.length; // In `libphonenumber-js` all "local-only" formats are dropped for simplicity.
// // This is safe because there is never an overlap beween the possible lengths
// // and the local-only lengths; this is checked at build time.
// if (local_lengths && local_lengths.indexOf(nationalNumber.length) >= 0)
// {
// return 'IS_POSSIBLE_LOCAL_ONLY'
// }
var minimum_length = possible_lengths[0];
if (minimum_length === actual_length) {
return 'IS_POSSIBLE';
}
if (minimum_length > actual_length) {
return 'TOO_SHORT';
}
if (possible_lengths[possible_lengths.length - 1] < actual_length) {
return 'TOO_LONG';
} // We skip the first element since we've already checked it.
return possible_lengths.indexOf(actual_length, 1) >= 0 ? 'IS_POSSIBLE' : 'INVALID_LENGTH';
}
//# sourceMappingURL=checkNumberLength.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,48 @@
"use strict";
var _metadata2 = _interopRequireDefault(require("../metadata.js"));
var _metadataMax = _interopRequireDefault(require("../../metadata.max.json"));
var _metadataMin = _interopRequireDefault(require("../../test/metadata/1.0.0/metadata.min.json"));
var _checkNumberLength = require("./checkNumberLength.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
describe('checkNumberLength', function () {
it('should check phone number length', function () {
// Too short.
checkNumberLength('800555353', 'FIXED_LINE', 'RU').should.equal('TOO_SHORT'); // Normal.
checkNumberLength('8005553535', 'FIXED_LINE', 'RU').should.equal('IS_POSSIBLE'); // Too long.
checkNumberLength('80055535355', 'FIXED_LINE', 'RU').should.equal('TOO_LONG'); // No such type.
checkNumberLength('169454850', 'VOIP', 'AC').should.equal('INVALID_LENGTH'); // No such possible length.
checkNumberLength('1694548', undefined, 'AD').should.equal('INVALID_LENGTH'); // FIXED_LINE_OR_MOBILE
checkNumberLength('1694548', 'FIXED_LINE_OR_MOBILE', 'AD').should.equal('INVALID_LENGTH'); // No mobile phones.
checkNumberLength('8123', 'FIXED_LINE_OR_MOBILE', 'TA').should.equal('IS_POSSIBLE'); // No "possible lengths" for "mobile".
checkNumberLength('81234567', 'FIXED_LINE_OR_MOBILE', 'SZ').should.equal('IS_POSSIBLE');
});
it('should work for old metadata', function () {
var _oldMetadata = new _metadata2["default"](_metadataMin["default"]);
_oldMetadata.country('RU');
(0, _checkNumberLength.checkNumberLengthForType)('8005553535', 'FIXED_LINE', _oldMetadata).should.equal('IS_POSSIBLE');
});
});
function checkNumberLength(number, type, country) {
var _metadata = new _metadata2["default"](_metadataMax["default"]);
_metadata.country(country);
return (0, _checkNumberLength.checkNumberLengthForType)(number, type, _metadata);
}
//# sourceMappingURL=checkNumberLength.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"checkNumberLength.test.js","names":["describe","it","checkNumberLength","should","equal","undefined","_oldMetadata","Metadata","oldMetadata","country","checkNumberLengthForType","number","type","_metadata","metadata"],"sources":["../../source/helpers/checkNumberLength.test.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport metadata from '../../metadata.max.json' assert { type: 'json' }\r\nimport oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' assert { type: 'json' }\r\n\r\nimport { checkNumberLengthForType } from './checkNumberLength.js'\r\n\r\ndescribe('checkNumberLength', () => {\r\n\tit('should check phone number length', () => {\r\n\t\t// Too short.\r\n\t\tcheckNumberLength('800555353', 'FIXED_LINE', 'RU').should.equal('TOO_SHORT')\r\n\t\t// Normal.\r\n\t\tcheckNumberLength('8005553535', 'FIXED_LINE', 'RU').should.equal('IS_POSSIBLE')\r\n\t\t// Too long.\r\n\t\tcheckNumberLength('80055535355', 'FIXED_LINE', 'RU').should.equal('TOO_LONG')\r\n\r\n\t\t// No such type.\r\n\t\tcheckNumberLength('169454850', 'VOIP', 'AC').should.equal('INVALID_LENGTH')\r\n\t\t// No such possible length.\r\n\t\tcheckNumberLength('1694548', undefined, 'AD').should.equal('INVALID_LENGTH')\r\n\r\n\t\t// FIXED_LINE_OR_MOBILE\r\n\t\tcheckNumberLength('1694548', 'FIXED_LINE_OR_MOBILE', 'AD').should.equal('INVALID_LENGTH')\r\n\t\t// No mobile phones.\r\n\t\tcheckNumberLength('8123', 'FIXED_LINE_OR_MOBILE', 'TA').should.equal('IS_POSSIBLE')\r\n\t\t// No \"possible lengths\" for \"mobile\".\r\n\t\tcheckNumberLength('81234567', 'FIXED_LINE_OR_MOBILE', 'SZ').should.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should work for old metadata', function() {\r\n\t\tconst _oldMetadata = new Metadata(oldMetadata)\r\n\t\t_oldMetadata.country('RU')\r\n\t\tcheckNumberLengthForType('8005553535', 'FIXED_LINE', _oldMetadata).should.equal('IS_POSSIBLE')\r\n\t})\r\n})\r\n\r\nfunction checkNumberLength(number, type, country) {\r\n\tconst _metadata = new Metadata(metadata)\r\n\t_metadata.country(country)\r\n\treturn checkNumberLengthForType(number, type, _metadata)\r\n}"],"mappings":";;AAAA;;AACA;;AACA;;AAEA;;;;AAEAA,QAAQ,CAAC,mBAAD,EAAsB,YAAM;EACnCC,EAAE,CAAC,kCAAD,EAAqC,YAAM;IAC5C;IACAC,iBAAiB,CAAC,WAAD,EAAc,YAAd,EAA4B,IAA5B,CAAjB,CAAmDC,MAAnD,CAA0DC,KAA1D,CAAgE,WAAhE,EAF4C,CAG5C;;IACAF,iBAAiB,CAAC,YAAD,EAAe,YAAf,EAA6B,IAA7B,CAAjB,CAAoDC,MAApD,CAA2DC,KAA3D,CAAiE,aAAjE,EAJ4C,CAK5C;;IACAF,iBAAiB,CAAC,aAAD,EAAgB,YAAhB,EAA8B,IAA9B,CAAjB,CAAqDC,MAArD,CAA4DC,KAA5D,CAAkE,UAAlE,EAN4C,CAQ5C;;IACAF,iBAAiB,CAAC,WAAD,EAAc,MAAd,EAAsB,IAAtB,CAAjB,CAA6CC,MAA7C,CAAoDC,KAApD,CAA0D,gBAA1D,EAT4C,CAU5C;;IACAF,iBAAiB,CAAC,SAAD,EAAYG,SAAZ,EAAuB,IAAvB,CAAjB,CAA8CF,MAA9C,CAAqDC,KAArD,CAA2D,gBAA3D,EAX4C,CAa5C;;IACAF,iBAAiB,CAAC,SAAD,EAAY,sBAAZ,EAAoC,IAApC,CAAjB,CAA2DC,MAA3D,CAAkEC,KAAlE,CAAwE,gBAAxE,EAd4C,CAe5C;;IACAF,iBAAiB,CAAC,MAAD,EAAS,sBAAT,EAAiC,IAAjC,CAAjB,CAAwDC,MAAxD,CAA+DC,KAA/D,CAAqE,aAArE,EAhB4C,CAiB5C;;IACAF,iBAAiB,CAAC,UAAD,EAAa,sBAAb,EAAqC,IAArC,CAAjB,CAA4DC,MAA5D,CAAmEC,KAAnE,CAAyE,aAAzE;EACA,CAnBC,CAAF;EAqBAH,EAAE,CAAC,8BAAD,EAAiC,YAAW;IAC7C,IAAMK,YAAY,GAAG,IAAIC,qBAAJ,CAAaC,uBAAb,CAArB;;IACAF,YAAY,CAACG,OAAb,CAAqB,IAArB;;IACA,IAAAC,2CAAA,EAAyB,YAAzB,EAAuC,YAAvC,EAAqDJ,YAArD,EAAmEH,MAAnE,CAA0EC,KAA1E,CAAgF,aAAhF;EACA,CAJC,CAAF;AAKA,CA3BO,CAAR;;AA6BA,SAASF,iBAAT,CAA2BS,MAA3B,EAAmCC,IAAnC,EAAyCH,OAAzC,EAAkD;EACjD,IAAMI,SAAS,GAAG,IAAIN,qBAAJ,CAAaO,uBAAb,CAAlB;;EACAD,SAAS,CAACJ,OAAV,CAAkBA,OAAlB;;EACA,OAAO,IAAAC,2CAAA,EAAyBC,MAAzB,EAAiCC,IAAjC,EAAuCC,SAAvC,CAAP;AACA"}

View File

@@ -0,0 +1,116 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = createExtensionPattern;
var _constants = require("../../constants.js");
// The RFC 3966 format for extensions.
var RFC3966_EXTN_PREFIX = ';ext=';
/**
* Helper method for constructing regular expressions for parsing. Creates
* an expression that captures up to max_length digits.
* @return {string} RegEx pattern to capture extension digits.
*/
var getExtensionDigitsPattern = function getExtensionDigitsPattern(maxLength) {
return "([".concat(_constants.VALID_DIGITS, "]{1,").concat(maxLength, "})");
};
/**
* Helper initialiser method to create the regular-expression pattern to match
* extensions.
* Copy-pasted from Google's `libphonenumber`:
* https://github.com/google/libphonenumber/blob/55b2646ec9393f4d3d6661b9c82ef9e258e8b829/javascript/i18n/phonenumbers/phonenumberutil.js#L759-L766
* @return {string} RegEx pattern to capture extensions.
*/
function createExtensionPattern(purpose) {
// We cap the maximum length of an extension based on the ambiguity of the way
// the extension is prefixed. As per ITU, the officially allowed length for
// extensions is actually 40, but we don't support this since we haven't seen real
// examples and this introduces many false interpretations as the extension labels
// are not standardized.
/** @type {string} */
var extLimitAfterExplicitLabel = '20';
/** @type {string} */
var extLimitAfterLikelyLabel = '15';
/** @type {string} */
var extLimitAfterAmbiguousChar = '9';
/** @type {string} */
var extLimitWhenNotSure = '6';
/** @type {string} */
var possibleSeparatorsBetweenNumberAndExtLabel = "[ \xA0\\t,]*"; // Optional full stop (.) or colon, followed by zero or more spaces/tabs/commas.
/** @type {string} */
var possibleCharsAfterExtLabel = "[:\\.\uFF0E]?[ \xA0\\t,-]*";
/** @type {string} */
var optionalExtnSuffix = "#?"; // Here the extension is called out in more explicit way, i.e mentioning it obvious
// patterns like "ext.".
/** @type {string} */
var explicitExtLabels = "(?:e?xt(?:ensi(?:o\u0301?|\xF3))?n?|\uFF45?\uFF58\uFF54\uFF4E?|\u0434\u043E\u0431|anexo)"; // One-character symbols that can be used to indicate an extension, and less
// commonly used or more ambiguous extension labels.
/** @type {string} */
var ambiguousExtLabels = "(?:[x\uFF58#\uFF03~\uFF5E]|int|\uFF49\uFF4E\uFF54)"; // When extension is not separated clearly.
/** @type {string} */
var ambiguousSeparator = "[- ]+"; // This is the same as possibleSeparatorsBetweenNumberAndExtLabel, but not matching
// comma as extension label may have it.
/** @type {string} */
var possibleSeparatorsNumberExtLabelNoComma = "[ \xA0\\t]*"; // ",," is commonly used for auto dialling the extension when connected. First
// comma is matched through possibleSeparatorsBetweenNumberAndExtLabel, so we do
// not repeat it here. Semi-colon works in Iphone and Android also to pop up a
// button with the extension number following.
/** @type {string} */
var autoDiallingAndExtLabelsFound = "(?:,{2}|;)";
/** @type {string} */
var rfcExtn = RFC3966_EXTN_PREFIX + getExtensionDigitsPattern(extLimitAfterExplicitLabel);
/** @type {string} */
var explicitExtn = possibleSeparatorsBetweenNumberAndExtLabel + explicitExtLabels + possibleCharsAfterExtLabel + getExtensionDigitsPattern(extLimitAfterExplicitLabel) + optionalExtnSuffix;
/** @type {string} */
var ambiguousExtn = possibleSeparatorsBetweenNumberAndExtLabel + ambiguousExtLabels + possibleCharsAfterExtLabel + getExtensionDigitsPattern(extLimitAfterAmbiguousChar) + optionalExtnSuffix;
/** @type {string} */
var americanStyleExtnWithSuffix = ambiguousSeparator + getExtensionDigitsPattern(extLimitWhenNotSure) + "#";
/** @type {string} */
var autoDiallingExtn = possibleSeparatorsNumberExtLabelNoComma + autoDiallingAndExtLabelsFound + possibleCharsAfterExtLabel + getExtensionDigitsPattern(extLimitAfterLikelyLabel) + optionalExtnSuffix;
/** @type {string} */
var onlyCommasExtn = possibleSeparatorsNumberExtLabelNoComma + "(?:,)+" + possibleCharsAfterExtLabel + getExtensionDigitsPattern(extLimitAfterAmbiguousChar) + optionalExtnSuffix; // The first regular expression covers RFC 3966 format, where the extension is added
// using ";ext=". The second more generic where extension is mentioned with explicit
// labels like "ext:". In both the above cases we allow more numbers in extension than
// any other extension labels. The third one captures when single character extension
// labels or less commonly used labels are used. In such cases we capture fewer
// extension digits in order to reduce the chance of falsely interpreting two
// numbers beside each other as a number + extension. The fourth one covers the
// special case of American numbers where the extension is written with a hash
// at the end, such as "- 503#". The fifth one is exclusively for extension
// autodialling formats which are used when dialling and in this case we accept longer
// extensions. The last one is more liberal on the number of commas that acts as
// extension labels, so we have a strict cap on the number of digits in such extensions.
return rfcExtn + "|" + explicitExtn + "|" + ambiguousExtn + "|" + americanStyleExtnWithSuffix + "|" + autoDiallingExtn + "|" + onlyCommasExtn;
}
//# sourceMappingURL=createExtensionPattern.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = extractExtension;
var _createExtensionPattern = _interopRequireDefault(require("./createExtensionPattern.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
// Regexp of all known extension prefixes used by different regions followed by
// 1 or more valid digits, for use when parsing.
var EXTN_PATTERN = new RegExp('(?:' + (0, _createExtensionPattern["default"])() + ')$', 'i'); // Strips any extension (as in, the part of the number dialled after the call is
// connected, usually indicated with extn, ext, x or similar) from the end of
// the number, and returns it.
function extractExtension(number) {
var start = number.search(EXTN_PATTERN);
if (start < 0) {
return {};
} // If we find a potential extension, and the number preceding this is a viable
// number, we assume it is an extension.
var numberWithoutExtension = number.slice(0, start);
var matches = number.match(EXTN_PATTERN);
var i = 1;
while (i < matches.length) {
if (matches[i]) {
return {
number: numberWithoutExtension,
ext: matches[i]
};
}
i++;
}
}
//# sourceMappingURL=extractExtension.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"extractExtension.js","names":["EXTN_PATTERN","RegExp","createExtensionPattern","extractExtension","number","start","search","numberWithoutExtension","slice","matches","match","i","length","ext"],"sources":["../../../source/helpers/extension/extractExtension.js"],"sourcesContent":["import createExtensionPattern from './createExtensionPattern.js'\r\n\r\n// Regexp of all known extension prefixes used by different regions followed by\r\n// 1 or more valid digits, for use when parsing.\r\nconst EXTN_PATTERN = new RegExp('(?:' + createExtensionPattern() + ')$', 'i')\r\n\r\n// Strips any extension (as in, the part of the number dialled after the call is\r\n// connected, usually indicated with extn, ext, x or similar) from the end of\r\n// the number, and returns it.\r\nexport default function extractExtension(number) {\r\n\tconst start = number.search(EXTN_PATTERN)\r\n\tif (start < 0) {\r\n\t\treturn {}\r\n\t}\r\n\t// If we find a potential extension, and the number preceding this is a viable\r\n\t// number, we assume it is an extension.\r\n\tconst numberWithoutExtension = number.slice(0, start)\r\n\tconst matches = number.match(EXTN_PATTERN)\r\n\tlet i = 1\r\n\twhile (i < matches.length) {\r\n\t\tif (matches[i]) {\r\n\t\t\treturn {\r\n\t\t\t\tnumber: numberWithoutExtension,\r\n\t\t\t\text: matches[i]\r\n\t\t\t}\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n}"],"mappings":";;;;;;;AAAA;;;;AAEA;AACA;AACA,IAAMA,YAAY,GAAG,IAAIC,MAAJ,CAAW,QAAQ,IAAAC,kCAAA,GAAR,GAAmC,IAA9C,EAAoD,GAApD,CAArB,C,CAEA;AACA;AACA;;AACe,SAASC,gBAAT,CAA0BC,MAA1B,EAAkC;EAChD,IAAMC,KAAK,GAAGD,MAAM,CAACE,MAAP,CAAcN,YAAd,CAAd;;EACA,IAAIK,KAAK,GAAG,CAAZ,EAAe;IACd,OAAO,EAAP;EACA,CAJ+C,CAKhD;EACA;;;EACA,IAAME,sBAAsB,GAAGH,MAAM,CAACI,KAAP,CAAa,CAAb,EAAgBH,KAAhB,CAA/B;EACA,IAAMI,OAAO,GAAGL,MAAM,CAACM,KAAP,CAAaV,YAAb,CAAhB;EACA,IAAIW,CAAC,GAAG,CAAR;;EACA,OAAOA,CAAC,GAAGF,OAAO,CAACG,MAAnB,EAA2B;IAC1B,IAAIH,OAAO,CAACE,CAAD,CAAX,EAAgB;MACf,OAAO;QACNP,MAAM,EAAEG,sBADF;QAENM,GAAG,EAAEJ,OAAO,CAACE,CAAD;MAFN,CAAP;IAIA;;IACDA,CAAC;EACD;AACD"}

View File

@@ -0,0 +1,154 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = extractCountryCallingCode;
var _stripIddPrefix = _interopRequireDefault(require("./stripIddPrefix.js"));
var _extractCountryCallingCodeFromInternationalNumberWithoutPlusSign = _interopRequireDefault(require("./extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js"));
var _metadata = _interopRequireDefault(require("../metadata.js"));
var _constants = require("../constants.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Converts a phone number digits (possibly with a `+`)
* into a calling code and the rest phone number digits.
* The "rest phone number digits" could include
* a national prefix, carrier code, and national
* (significant) number.
* @param {string} number — Phone number digits (possibly with a `+`).
* @param {string} [country] — Default country.
* @param {string} [callingCode] — Default calling code (some phone numbering plans are non-geographic).
* @param {object} metadata
* @return {object} `{ countryCallingCodeSource: string?, countryCallingCode: string?, number: string }`
* @example
* // Returns `{ countryCallingCode: "1", number: "2133734253" }`.
* extractCountryCallingCode('2133734253', 'US', null, metadata)
* extractCountryCallingCode('2133734253', null, '1', metadata)
* extractCountryCallingCode('+12133734253', null, null, metadata)
* extractCountryCallingCode('+12133734253', 'RU', null, metadata)
*/
function extractCountryCallingCode(number, country, callingCode, metadata) {
if (!number) {
return {};
}
var isNumberWithIddPrefix; // If this is not an international phone number,
// then either extract an "IDD" prefix, or extract a
// country calling code from a number by autocorrecting it
// by prepending a leading `+` in cases when it starts
// with the country calling code.
// https://wikitravel.org/en/International_dialling_prefix
// https://github.com/catamphetamine/libphonenumber-js/issues/376
if (number[0] !== '+') {
// Convert an "out-of-country" dialing phone number
// to a proper international phone number.
var numberWithoutIDD = (0, _stripIddPrefix["default"])(number, country, callingCode, metadata); // If an IDD prefix was stripped then
// convert the number to international one
// for subsequent parsing.
if (numberWithoutIDD && numberWithoutIDD !== number) {
isNumberWithIddPrefix = true;
number = '+' + numberWithoutIDD;
} else {
// Check to see if the number starts with the country calling code
// for the default country. If so, we remove the country calling code,
// and do some checks on the validity of the number before and after.
// https://github.com/catamphetamine/libphonenumber-js/issues/376
if (country || callingCode) {
var _extractCountryCallin = (0, _extractCountryCallingCodeFromInternationalNumberWithoutPlusSign["default"])(number, country, callingCode, metadata),
countryCallingCode = _extractCountryCallin.countryCallingCode,
shorterNumber = _extractCountryCallin.number;
if (countryCallingCode) {
return {
countryCallingCodeSource: 'FROM_NUMBER_WITHOUT_PLUS_SIGN',
countryCallingCode: countryCallingCode,
number: shorterNumber
};
}
}
return {
// No need to set it to `UNSPECIFIED`. It can be just `undefined`.
// countryCallingCodeSource: 'UNSPECIFIED',
number: number
};
}
} // Fast abortion: country codes do not begin with a '0'
if (number[1] === '0') {
return {};
}
metadata = new _metadata["default"](metadata); // The thing with country phone codes
// is that they are orthogonal to each other
// i.e. there's no such country phone code A
// for which country phone code B exists
// where B starts with A.
// Therefore, while scanning digits,
// if a valid country code is found,
// that means that it is the country code.
//
var i = 2;
while (i - 1 <= _constants.MAX_LENGTH_COUNTRY_CODE && i <= number.length) {
var _countryCallingCode = number.slice(1, i);
if (metadata.hasCallingCode(_countryCallingCode)) {
metadata.selectNumberingPlan(_countryCallingCode);
return {
countryCallingCodeSource: isNumberWithIddPrefix ? 'FROM_NUMBER_WITH_IDD' : 'FROM_NUMBER_WITH_PLUS_SIGN',
countryCallingCode: _countryCallingCode,
number: number.slice(i)
};
}
i++;
}
return {};
} // The possible values for the returned `countryCallingCodeSource` are:
//
// Copy-pasted from:
// https://github.com/google/libphonenumber/blob/master/resources/phonenumber.proto
//
// // The source from which the country_code is derived. This is not set in the
// // general parsing method, but in the method that parses and keeps raw_input.
// // New fields could be added upon request.
// enum CountryCodeSource {
// // Default value returned if this is not set, because the phone number was
// // created using parse, not parseAndKeepRawInput. hasCountryCodeSource will
// // return false if this is the case.
// UNSPECIFIED = 0;
//
// // The country_code is derived based on a phone number with a leading "+",
// // e.g. the French number "+33 1 42 68 53 00".
// FROM_NUMBER_WITH_PLUS_SIGN = 1;
//
// // The country_code is derived based on a phone number with a leading IDD,
// // e.g. the French number "011 33 1 42 68 53 00", as it is dialled from US.
// FROM_NUMBER_WITH_IDD = 5;
//
// // The country_code is derived based on a phone number without a leading
// // "+", e.g. the French number "33 1 42 68 53 00" when defaultCountry is
// // supplied as France.
// FROM_NUMBER_WITHOUT_PLUS_SIGN = 10;
//
// // The country_code is derived NOT based on the phone number itself, but
// // from the defaultCountry parameter provided in the parsing function by the
// // clients. This happens mostly for numbers written in the national format
// // (without country code). For example, this would be set when parsing the
// // French number "01 42 68 53 00", when defaultCountry is supplied as
// // France.
// FROM_DEFAULT_COUNTRY = 20;
// }
//# sourceMappingURL=extractCountryCallingCode.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,24 @@
"use strict";
var _extractCountryCallingCode = _interopRequireDefault(require("./extractCountryCallingCode.js"));
var _metadataMin = _interopRequireDefault(require("../../metadata.min.json"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
describe('extractCountryCallingCode', function () {
it('should extract country calling code from a number', function () {
(0, _extractCountryCallingCode["default"])('+78005553535', null, null, _metadataMin["default"]).should.deep.equal({
countryCallingCodeSource: 'FROM_NUMBER_WITH_PLUS_SIGN',
countryCallingCode: '7',
number: '8005553535'
});
(0, _extractCountryCallingCode["default"])('+7800', null, null, _metadataMin["default"]).should.deep.equal({
countryCallingCodeSource: 'FROM_NUMBER_WITH_PLUS_SIGN',
countryCallingCode: '7',
number: '800'
});
(0, _extractCountryCallingCode["default"])('', null, null, _metadataMin["default"]).should.deep.equal({});
});
});
//# sourceMappingURL=extractCountryCallingCode.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"extractCountryCallingCode.test.js","names":["describe","it","extractCountryCallingCode","metadata","should","deep","equal","countryCallingCodeSource","countryCallingCode","number"],"sources":["../../source/helpers/extractCountryCallingCode.test.js"],"sourcesContent":["import extractCountryCallingCode from './extractCountryCallingCode.js'\r\nimport metadata from '../../metadata.min.json' assert { type: 'json' }\r\n\r\ndescribe('extractCountryCallingCode', () => {\r\n\tit('should extract country calling code from a number', () => {\r\n\t\textractCountryCallingCode('+78005553535', null, null, metadata).should.deep.equal({\r\n\t\t\tcountryCallingCodeSource: 'FROM_NUMBER_WITH_PLUS_SIGN',\r\n\t\t\tcountryCallingCode: '7',\r\n\t\t\tnumber: '8005553535'\r\n\t\t})\r\n\r\n\t\textractCountryCallingCode('+7800', null, null, metadata).should.deep.equal({\r\n\t\t\tcountryCallingCodeSource: 'FROM_NUMBER_WITH_PLUS_SIGN',\r\n\t\t\tcountryCallingCode: '7',\r\n\t\t\tnumber: '800'\r\n\t\t})\r\n\r\n\t\textractCountryCallingCode('', null, null, metadata).should.deep.equal({})\r\n\t})\r\n})\r\n"],"mappings":";;AAAA;;AACA;;;;AAEAA,QAAQ,CAAC,2BAAD,EAA8B,YAAM;EAC3CC,EAAE,CAAC,mDAAD,EAAsD,YAAM;IAC7D,IAAAC,qCAAA,EAA0B,cAA1B,EAA0C,IAA1C,EAAgD,IAAhD,EAAsDC,uBAAtD,EAAgEC,MAAhE,CAAuEC,IAAvE,CAA4EC,KAA5E,CAAkF;MACjFC,wBAAwB,EAAE,4BADuD;MAEjFC,kBAAkB,EAAE,GAF6D;MAGjFC,MAAM,EAAE;IAHyE,CAAlF;IAMA,IAAAP,qCAAA,EAA0B,OAA1B,EAAmC,IAAnC,EAAyC,IAAzC,EAA+CC,uBAA/C,EAAyDC,MAAzD,CAAgEC,IAAhE,CAAqEC,KAArE,CAA2E;MAC1EC,wBAAwB,EAAE,4BADgD;MAE1EC,kBAAkB,EAAE,GAFsD;MAG1EC,MAAM,EAAE;IAHkE,CAA3E;IAMA,IAAAP,qCAAA,EAA0B,EAA1B,EAA8B,IAA9B,EAAoC,IAApC,EAA0CC,uBAA1C,EAAoDC,MAApD,CAA2DC,IAA3D,CAAgEC,KAAhE,CAAsE,EAAtE;EACA,CAdC,CAAF;AAeA,CAhBO,CAAR"}

View File

@@ -0,0 +1,63 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = extractCountryCallingCodeFromInternationalNumberWithoutPlusSign;
var _metadata = _interopRequireDefault(require("../metadata.js"));
var _matchesEntirely = _interopRequireDefault(require("./matchesEntirely.js"));
var _extractNationalNumber = _interopRequireDefault(require("./extractNationalNumber.js"));
var _checkNumberLength = _interopRequireDefault(require("./checkNumberLength.js"));
var _getCountryCallingCode = _interopRequireDefault(require("../getCountryCallingCode.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Sometimes some people incorrectly input international phone numbers
* without the leading `+`. This function corrects such input.
* @param {string} number — Phone number digits.
* @param {string?} country
* @param {string?} callingCode
* @param {object} metadata
* @return {object} `{ countryCallingCode: string?, number: string }`.
*/
function extractCountryCallingCodeFromInternationalNumberWithoutPlusSign(number, country, callingCode, metadata) {
var countryCallingCode = country ? (0, _getCountryCallingCode["default"])(country, metadata) : callingCode;
if (number.indexOf(countryCallingCode) === 0) {
metadata = new _metadata["default"](metadata);
metadata.selectNumberingPlan(country, callingCode);
var possibleShorterNumber = number.slice(countryCallingCode.length);
var _extractNationalNumbe = (0, _extractNationalNumber["default"])(possibleShorterNumber, metadata),
possibleShorterNationalNumber = _extractNationalNumbe.nationalNumber;
var _extractNationalNumbe2 = (0, _extractNationalNumber["default"])(number, metadata),
nationalNumber = _extractNationalNumbe2.nationalNumber; // If the number was not valid before but is valid now,
// or if it was too long before, we consider the number
// with the country calling code stripped to be a better result
// and keep that instead.
// For example, in Germany (+49), `49` is a valid area code,
// so if a number starts with `49`, it could be both a valid
// national German number or an international number without
// a leading `+`.
if (!(0, _matchesEntirely["default"])(nationalNumber, metadata.nationalNumberPattern()) && (0, _matchesEntirely["default"])(possibleShorterNationalNumber, metadata.nationalNumberPattern()) || (0, _checkNumberLength["default"])(nationalNumber, metadata) === 'TOO_LONG') {
return {
countryCallingCode: countryCallingCode,
number: possibleShorterNumber
};
}
}
return {
number: number
};
}
//# sourceMappingURL=extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js","names":["extractCountryCallingCodeFromInternationalNumberWithoutPlusSign","number","country","callingCode","metadata","countryCallingCode","getCountryCallingCode","indexOf","Metadata","selectNumberingPlan","possibleShorterNumber","slice","length","extractNationalNumber","possibleShorterNationalNumber","nationalNumber","matchesEntirely","nationalNumberPattern","checkNumberLength"],"sources":["../../source/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport matchesEntirely from './matchesEntirely.js'\r\nimport extractNationalNumber from './extractNationalNumber.js'\r\nimport checkNumberLength from './checkNumberLength.js'\r\nimport getCountryCallingCode from '../getCountryCallingCode.js'\r\n\r\n/**\r\n * Sometimes some people incorrectly input international phone numbers\r\n * without the leading `+`. This function corrects such input.\r\n * @param {string} number — Phone number digits.\r\n * @param {string?} country\r\n * @param {string?} callingCode\r\n * @param {object} metadata\r\n * @return {object} `{ countryCallingCode: string?, number: string }`.\r\n */\r\nexport default function extractCountryCallingCodeFromInternationalNumberWithoutPlusSign(\r\n\tnumber,\r\n\tcountry,\r\n\tcallingCode,\r\n\tmetadata\r\n) {\r\n\tconst countryCallingCode = country ? getCountryCallingCode(country, metadata) : callingCode\r\n\tif (number.indexOf(countryCallingCode) === 0) {\r\n\t\tmetadata = new Metadata(metadata)\r\n\t\tmetadata.selectNumberingPlan(country, callingCode)\r\n\t\tconst possibleShorterNumber = number.slice(countryCallingCode.length)\r\n\t\tconst {\r\n\t\t\tnationalNumber: possibleShorterNationalNumber,\r\n\t\t} = extractNationalNumber(\r\n\t\t\tpossibleShorterNumber,\r\n\t\t\tmetadata\r\n\t\t)\r\n\t\tconst {\r\n\t\t\tnationalNumber\r\n\t\t} = extractNationalNumber(\r\n\t\t\tnumber,\r\n\t\t\tmetadata\r\n\t\t)\r\n\t\t// If the number was not valid before but is valid now,\r\n\t\t// or if it was too long before, we consider the number\r\n\t\t// with the country calling code stripped to be a better result\r\n\t\t// and keep that instead.\r\n\t\t// For example, in Germany (+49), `49` is a valid area code,\r\n\t\t// so if a number starts with `49`, it could be both a valid\r\n\t\t// national German number or an international number without\r\n\t\t// a leading `+`.\r\n\t\tif (\r\n\t\t\t(\r\n\t\t\t\t!matchesEntirely(nationalNumber, metadata.nationalNumberPattern())\r\n\t\t\t\t&&\r\n\t\t\t\tmatchesEntirely(possibleShorterNationalNumber, metadata.nationalNumberPattern())\r\n\t\t\t)\r\n\t\t\t||\r\n\t\t\tcheckNumberLength(nationalNumber, metadata) === 'TOO_LONG'\r\n\t\t) {\r\n\t\t\treturn {\r\n\t\t\t\tcountryCallingCode,\r\n\t\t\t\tnumber: possibleShorterNumber\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn { number }\r\n}"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,+DAAT,CACdC,MADc,EAEdC,OAFc,EAGdC,WAHc,EAIdC,QAJc,EAKb;EACD,IAAMC,kBAAkB,GAAGH,OAAO,GAAG,IAAAI,iCAAA,EAAsBJ,OAAtB,EAA+BE,QAA/B,CAAH,GAA8CD,WAAhF;;EACA,IAAIF,MAAM,CAACM,OAAP,CAAeF,kBAAf,MAAuC,CAA3C,EAA8C;IAC7CD,QAAQ,GAAG,IAAII,oBAAJ,CAAaJ,QAAb,CAAX;IACAA,QAAQ,CAACK,mBAAT,CAA6BP,OAA7B,EAAsCC,WAAtC;IACA,IAAMO,qBAAqB,GAAGT,MAAM,CAACU,KAAP,CAAaN,kBAAkB,CAACO,MAAhC,CAA9B;;IACA,4BAEI,IAAAC,iCAAA,EACHH,qBADG,EAEHN,QAFG,CAFJ;IAAA,IACiBU,6BADjB,yBACCC,cADD;;IAMA,6BAEI,IAAAF,iCAAA,EACHZ,MADG,EAEHG,QAFG,CAFJ;IAAA,IACCW,cADD,0BACCA,cADD,CAV6C,CAgB7C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;;IACA,IAEE,CAAC,IAAAC,2BAAA,EAAgBD,cAAhB,EAAgCX,QAAQ,CAACa,qBAAT,EAAhC,CAAD,IAEA,IAAAD,2BAAA,EAAgBF,6BAAhB,EAA+CV,QAAQ,CAACa,qBAAT,EAA/C,CAHD,IAMA,IAAAC,6BAAA,EAAkBH,cAAlB,EAAkCX,QAAlC,MAAgD,UAPjD,EAQE;MACD,OAAO;QACNC,kBAAkB,EAAlBA,kBADM;QAENJ,MAAM,EAAES;MAFF,CAAP;IAIA;EACD;;EACD,OAAO;IAAET,MAAM,EAANA;EAAF,CAAP;AACA"}

View File

@@ -0,0 +1,86 @@
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = extractFormattedPhoneNumberFromPossibleRfc3966NumberUri;
var _extractPhoneContext = _interopRequireWildcard(require("./extractPhoneContext.js"));
var _ParseError = _interopRequireDefault(require("../ParseError.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**
* @param {string} numberToParse
* @param {string} nationalNumber
* @return {}
*/
function extractFormattedPhoneNumberFromPossibleRfc3966NumberUri(numberToParse, _ref) {
var extractFormattedPhoneNumber = _ref.extractFormattedPhoneNumber;
var phoneContext = (0, _extractPhoneContext["default"])(numberToParse);
if (!(0, _extractPhoneContext.isPhoneContextValid)(phoneContext)) {
throw new _ParseError["default"]('NOT_A_NUMBER');
}
var phoneNumberString;
if (phoneContext === null) {
// Extract a possible number from the string passed in.
// (this strips leading characters that could not be the start of a phone number)
phoneNumberString = extractFormattedPhoneNumber(numberToParse) || '';
} else {
phoneNumberString = ''; // If the phone context contains a phone number prefix, we need to capture
// it, whereas domains will be ignored.
if (phoneContext.charAt(0) === _extractPhoneContext.PLUS_SIGN) {
phoneNumberString += phoneContext;
} // Now append everything between the "tel:" prefix and the phone-context.
// This should include the national number, an optional extension or
// isdn-subaddress component. Note we also handle the case when "tel:" is
// missing, as we have seen in some of the phone number inputs.
// In that case, we append everything from the beginning.
var indexOfRfc3966Prefix = numberToParse.indexOf(_extractPhoneContext.RFC3966_PREFIX_);
var indexOfNationalNumber; // RFC 3966 "tel:" prefix is preset at this stage because
// `isPhoneContextValid()` requires it to be present.
/* istanbul ignore else */
if (indexOfRfc3966Prefix >= 0) {
indexOfNationalNumber = indexOfRfc3966Prefix + _extractPhoneContext.RFC3966_PREFIX_.length;
} else {
indexOfNationalNumber = 0;
}
var indexOfPhoneContext = numberToParse.indexOf(_extractPhoneContext.RFC3966_PHONE_CONTEXT_);
phoneNumberString += numberToParse.substring(indexOfNationalNumber, indexOfPhoneContext);
} // Delete the isdn-subaddress and everything after it if it is present.
// Note extension won't appear at the same time with isdn-subaddress
// according to paragraph 5.3 of the RFC3966 spec.
var indexOfIsdn = phoneNumberString.indexOf(_extractPhoneContext.RFC3966_ISDN_SUBADDRESS_);
if (indexOfIsdn > 0) {
phoneNumberString = phoneNumberString.substring(0, indexOfIsdn);
} // If both phone context and isdn-subaddress are absent but other
// parameters are present, the parameters are left in nationalNumber.
// This is because we are concerned about deleting content from a potential
// number string when there is no strong evidence that the number is
// actually written in RFC3966.
if (phoneNumberString !== '') {
return phoneNumberString;
}
}
//# sourceMappingURL=extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js","names":["extractFormattedPhoneNumberFromPossibleRfc3966NumberUri","numberToParse","extractFormattedPhoneNumber","phoneContext","extractPhoneContext","isPhoneContextValid","ParseError","phoneNumberString","charAt","PLUS_SIGN","indexOfRfc3966Prefix","indexOf","RFC3966_PREFIX_","indexOfNationalNumber","length","indexOfPhoneContext","RFC3966_PHONE_CONTEXT_","substring","indexOfIsdn","RFC3966_ISDN_SUBADDRESS_"],"sources":["../../source/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js"],"sourcesContent":["import extractPhoneContext, {\r\n\tisPhoneContextValid,\r\n\tPLUS_SIGN,\r\n\tRFC3966_PREFIX_,\r\n\tRFC3966_PHONE_CONTEXT_,\r\n\tRFC3966_ISDN_SUBADDRESS_\r\n} from './extractPhoneContext.js'\r\n\r\nimport ParseError from '../ParseError.js'\r\n\r\n/**\r\n * @param {string} numberToParse\r\n * @param {string} nationalNumber\r\n * @return {}\r\n */\r\nexport default function extractFormattedPhoneNumberFromPossibleRfc3966NumberUri(numberToParse, {\r\n\textractFormattedPhoneNumber\r\n}) {\r\n\tconst phoneContext = extractPhoneContext(numberToParse)\r\n\tif (!isPhoneContextValid(phoneContext)) {\r\n\t\tthrow new ParseError('NOT_A_NUMBER')\r\n\t}\r\n\r\n\tlet phoneNumberString\r\n\r\n\tif (phoneContext === null) {\r\n\t\t// Extract a possible number from the string passed in.\r\n\t\t// (this strips leading characters that could not be the start of a phone number)\r\n\t\tphoneNumberString = extractFormattedPhoneNumber(numberToParse) || ''\r\n\t} else {\r\n\t\tphoneNumberString = ''\r\n\r\n\t\t// If the phone context contains a phone number prefix, we need to capture\r\n\t\t// it, whereas domains will be ignored.\r\n\t\tif (phoneContext.charAt(0) === PLUS_SIGN) {\r\n\t\t\tphoneNumberString += phoneContext\r\n\t\t}\r\n\r\n\t\t// Now append everything between the \"tel:\" prefix and the phone-context.\r\n\t\t// This should include the national number, an optional extension or\r\n\t\t// isdn-subaddress component. Note we also handle the case when \"tel:\" is\r\n\t\t// missing, as we have seen in some of the phone number inputs.\r\n\t\t// In that case, we append everything from the beginning.\r\n\t\tconst indexOfRfc3966Prefix = numberToParse.indexOf(RFC3966_PREFIX_)\r\n\t\tlet indexOfNationalNumber\r\n\t\t// RFC 3966 \"tel:\" prefix is preset at this stage because\r\n\t\t// `isPhoneContextValid()` requires it to be present.\r\n\t\t/* istanbul ignore else */\r\n\t\tif (indexOfRfc3966Prefix >= 0) {\r\n\t\t\tindexOfNationalNumber = indexOfRfc3966Prefix + RFC3966_PREFIX_.length\r\n\t\t} else {\r\n\t\t\tindexOfNationalNumber = 0\r\n\t\t}\r\n\t\tconst indexOfPhoneContext = numberToParse.indexOf(RFC3966_PHONE_CONTEXT_)\r\n\t\tphoneNumberString += numberToParse.substring(indexOfNationalNumber, indexOfPhoneContext)\r\n\t}\r\n\r\n\t// Delete the isdn-subaddress and everything after it if it is present.\r\n\t// Note extension won't appear at the same time with isdn-subaddress\r\n\t// according to paragraph 5.3 of the RFC3966 spec.\r\n\tconst indexOfIsdn = phoneNumberString.indexOf(RFC3966_ISDN_SUBADDRESS_)\r\n\tif (indexOfIsdn > 0) {\r\n\t\tphoneNumberString = phoneNumberString.substring(0, indexOfIsdn)\r\n\t}\r\n\t// If both phone context and isdn-subaddress are absent but other\r\n\t// parameters are present, the parameters are left in nationalNumber.\r\n\t// This is because we are concerned about deleting content from a potential\r\n\t// number string when there is no strong evidence that the number is\r\n\t// actually written in RFC3966.\r\n\r\n\tif (phoneNumberString !== '') {\r\n\t\treturn phoneNumberString\r\n\t}\r\n}"],"mappings":";;;;;;;;;AAAA;;AAQA;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACe,SAASA,uDAAT,CAAiEC,aAAjE,QAEZ;EAAA,IADFC,2BACE,QADFA,2BACE;EACF,IAAMC,YAAY,GAAG,IAAAC,+BAAA,EAAoBH,aAApB,CAArB;;EACA,IAAI,CAAC,IAAAI,wCAAA,EAAoBF,YAApB,CAAL,EAAwC;IACvC,MAAM,IAAIG,sBAAJ,CAAe,cAAf,CAAN;EACA;;EAED,IAAIC,iBAAJ;;EAEA,IAAIJ,YAAY,KAAK,IAArB,EAA2B;IAC1B;IACA;IACAI,iBAAiB,GAAGL,2BAA2B,CAACD,aAAD,CAA3B,IAA8C,EAAlE;EACA,CAJD,MAIO;IACNM,iBAAiB,GAAG,EAApB,CADM,CAGN;IACA;;IACA,IAAIJ,YAAY,CAACK,MAAb,CAAoB,CAApB,MAA2BC,8BAA/B,EAA0C;MACzCF,iBAAiB,IAAIJ,YAArB;IACA,CAPK,CASN;IACA;IACA;IACA;IACA;;;IACA,IAAMO,oBAAoB,GAAGT,aAAa,CAACU,OAAd,CAAsBC,oCAAtB,CAA7B;IACA,IAAIC,qBAAJ,CAfM,CAgBN;IACA;;IACA;;IACA,IAAIH,oBAAoB,IAAI,CAA5B,EAA+B;MAC9BG,qBAAqB,GAAGH,oBAAoB,GAAGE,oCAAA,CAAgBE,MAA/D;IACA,CAFD,MAEO;MACND,qBAAqB,GAAG,CAAxB;IACA;;IACD,IAAME,mBAAmB,GAAGd,aAAa,CAACU,OAAd,CAAsBK,2CAAtB,CAA5B;IACAT,iBAAiB,IAAIN,aAAa,CAACgB,SAAd,CAAwBJ,qBAAxB,EAA+CE,mBAA/C,CAArB;EACA,CAtCC,CAwCF;EACA;EACA;;;EACA,IAAMG,WAAW,GAAGX,iBAAiB,CAACI,OAAlB,CAA0BQ,6CAA1B,CAApB;;EACA,IAAID,WAAW,GAAG,CAAlB,EAAqB;IACpBX,iBAAiB,GAAGA,iBAAiB,CAACU,SAAlB,CAA4B,CAA5B,EAA+BC,WAA/B,CAApB;EACA,CA9CC,CA+CF;EACA;EACA;EACA;EACA;;;EAEA,IAAIX,iBAAiB,KAAK,EAA1B,EAA8B;IAC7B,OAAOA,iBAAP;EACA;AACD"}

View File

@@ -0,0 +1,123 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = extractNationalNumber;
var _extractNationalNumberFromPossiblyIncompleteNumber = _interopRequireDefault(require("./extractNationalNumberFromPossiblyIncompleteNumber.js"));
var _matchesEntirely = _interopRequireDefault(require("./matchesEntirely.js"));
var _checkNumberLength = _interopRequireDefault(require("./checkNumberLength.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Strips national prefix and carrier code from a complete phone number.
* The difference from the non-"FromCompleteNumber" function is that
* it won't extract national prefix if the resultant number is too short
* to be a complete number for the selected phone numbering plan.
* @param {string} number — Complete phone number digits.
* @param {Metadata} metadata — Metadata with a phone numbering plan selected.
* @return {object} `{ nationalNumber: string, carrierCode: string? }`.
*/
function extractNationalNumber(number, metadata) {
// Parsing national prefixes and carrier codes
// is only required for local phone numbers
// but some people don't understand that
// and sometimes write international phone numbers
// with national prefixes (or maybe even carrier codes).
// http://ucken.blogspot.ru/2016/03/trunk-prefixes-in-skype4b.html
// Google's original library forgives such mistakes
// and so does this library, because it has been requested:
// https://github.com/catamphetamine/libphonenumber-js/issues/127
var _extractNationalNumbe = (0, _extractNationalNumberFromPossiblyIncompleteNumber["default"])(number, metadata),
carrierCode = _extractNationalNumbe.carrierCode,
nationalNumber = _extractNationalNumbe.nationalNumber;
if (nationalNumber !== number) {
if (!shouldHaveExtractedNationalPrefix(number, nationalNumber, metadata)) {
// Don't strip the national prefix.
return {
nationalNumber: number
};
} // Check the national (significant) number length after extracting national prefix and carrier code.
// Legacy generated metadata (before `1.0.18`) didn't support the "possible lengths" feature.
if (metadata.possibleLengths()) {
// The number remaining after stripping the national prefix and carrier code
// should be long enough to have a possible length for the country.
// Otherwise, don't strip the national prefix and carrier code,
// since the original number could be a valid number.
// This check has been copy-pasted "as is" from Google's original library:
// https://github.com/google/libphonenumber/blob/876268eb1ad6cdc1b7b5bef17fc5e43052702d57/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L3236-L3250
// It doesn't check for the "possibility" of the original `number`.
// I guess it's fine not checking that one. It works as is anyway.
if (!isPossibleIncompleteNationalNumber(nationalNumber, metadata)) {
// Don't strip the national prefix.
return {
nationalNumber: number
};
}
}
}
return {
nationalNumber: nationalNumber,
carrierCode: carrierCode
};
} // In some countries, the same digit could be a national prefix
// or a leading digit of a valid phone number.
// For example, in Russia, national prefix is `8`,
// and also `800 555 35 35` is a valid number
// in which `8` is not a national prefix, but the first digit
// of a national (significant) number.
// Same's with Belarus:
// `82004910060` is a valid national (significant) number,
// but `2004910060` is not.
// To support such cases (to prevent the code from always stripping
// national prefix), a condition is imposed: a national prefix
// is not extracted when the original number is "viable" and the
// resultant number is not, a "viable" national number being the one
// that matches `national_number_pattern`.
function shouldHaveExtractedNationalPrefix(nationalNumberBefore, nationalNumberAfter, metadata) {
// The equivalent in Google's code is:
// https://github.com/google/libphonenumber/blob/e326fa1fc4283bb05eb35cb3c15c18f98a31af33/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L2969-L3004
if ((0, _matchesEntirely["default"])(nationalNumberBefore, metadata.nationalNumberPattern()) && !(0, _matchesEntirely["default"])(nationalNumberAfter, metadata.nationalNumberPattern())) {
return false;
} // This "is possible" national number (length) check has been commented out
// because it's superceded by the (effectively) same check done in the
// `extractNationalNumber()` function after it calls `shouldHaveExtractedNationalPrefix()`.
// In other words, why run the same check twice if it could only be run once.
// // Check the national (significant) number length after extracting national prefix and carrier code.
// // Fixes a minor "weird behavior" bug: https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/57
// // (Legacy generated metadata (before `1.0.18`) didn't support the "possible lengths" feature).
// if (metadata.possibleLengths()) {
// if (isPossibleIncompleteNationalNumber(nationalNumberBefore, metadata) &&
// !isPossibleIncompleteNationalNumber(nationalNumberAfter, metadata)) {
// return false
// }
// }
return true;
}
function isPossibleIncompleteNationalNumber(nationalNumber, metadata) {
switch ((0, _checkNumberLength["default"])(nationalNumber, metadata)) {
case 'TOO_SHORT':
case 'INVALID_LENGTH':
// This library ignores "local-only" phone numbers (for simplicity).
// See the readme for more info on what are "local-only" phone numbers.
// case 'IS_POSSIBLE_LOCAL_ONLY':
return false;
default:
return true;
}
}
//# sourceMappingURL=extractNationalNumber.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,23 @@
"use strict";
var _extractNationalNumber = _interopRequireDefault(require("./extractNationalNumber.js"));
var _metadata = _interopRequireDefault(require("../metadata.js"));
var _metadataMin = _interopRequireDefault(require("../../test/metadata/1.0.0/metadata.min.json"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
describe('extractNationalNumber', function () {
it('should extract a national number when using old metadata', function () {
var _oldMetadata = new _metadata["default"](_metadataMin["default"]);
_oldMetadata.selectNumberingPlan('RU');
(0, _extractNationalNumber["default"])('88005553535', _oldMetadata).should.deep.equal({
nationalNumber: '8005553535',
carrierCode: undefined
});
});
});
//# sourceMappingURL=extractNationalNumber.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"extractNationalNumber.test.js","names":["describe","it","_oldMetadata","Metadata","oldMetadata","selectNumberingPlan","extractNationalNumber","should","deep","equal","nationalNumber","carrierCode","undefined"],"sources":["../../source/helpers/extractNationalNumber.test.js"],"sourcesContent":["import extractNationalNumber from './extractNationalNumber.js'\r\n\r\nimport Metadata from '../metadata.js'\r\nimport oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' assert { type: 'json' }\r\n\r\ndescribe('extractNationalNumber', function() {\r\n\tit('should extract a national number when using old metadata', function() {\r\n\t\tconst _oldMetadata = new Metadata(oldMetadata)\r\n\t\t_oldMetadata.selectNumberingPlan('RU')\r\n\t\textractNationalNumber('88005553535', _oldMetadata).should.deep.equal({\r\n\t\t\tnationalNumber: '8005553535',\r\n\t\t\tcarrierCode: undefined\r\n\t\t})\r\n\t})\r\n})"],"mappings":";;AAAA;;AAEA;;AACA;;;;AAEAA,QAAQ,CAAC,uBAAD,EAA0B,YAAW;EAC5CC,EAAE,CAAC,0DAAD,EAA6D,YAAW;IACzE,IAAMC,YAAY,GAAG,IAAIC,oBAAJ,CAAaC,uBAAb,CAArB;;IACAF,YAAY,CAACG,mBAAb,CAAiC,IAAjC;;IACA,IAAAC,iCAAA,EAAsB,aAAtB,EAAqCJ,YAArC,EAAmDK,MAAnD,CAA0DC,IAA1D,CAA+DC,KAA/D,CAAqE;MACpEC,cAAc,EAAE,YADoD;MAEpEC,WAAW,EAAEC;IAFuD,CAArE;EAIA,CAPC,CAAF;AAQA,CATO,CAAR"}

View File

@@ -0,0 +1,114 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = extractNationalNumberFromPossiblyIncompleteNumber;
/**
* Strips any national prefix (such as 0, 1) present in a
* (possibly incomplete) number provided.
* "Carrier codes" are only used in Colombia and Brazil,
* and only when dialing within those countries from a mobile phone to a fixed line number.
* Sometimes it won't actually strip national prefix
* and will instead prepend some digits to the `number`:
* for example, when number `2345678` is passed with `VI` country selected,
* it will return `{ number: "3402345678" }`, because `340` area code is prepended.
* @param {string} number — National number digits.
* @param {object} metadata — Metadata with country selected.
* @return {object} `{ nationalNumber: string, nationalPrefix: string? carrierCode: string? }`. Even if a national prefix was extracted, it's not necessarily present in the returned object, so don't rely on its presence in the returned object in order to find out whether a national prefix has been extracted or not.
*/
function extractNationalNumberFromPossiblyIncompleteNumber(number, metadata) {
if (number && metadata.numberingPlan.nationalPrefixForParsing()) {
// See METADATA.md for the description of
// `national_prefix_for_parsing` and `national_prefix_transform_rule`.
// Attempt to parse the first digits as a national prefix.
var prefixPattern = new RegExp('^(?:' + metadata.numberingPlan.nationalPrefixForParsing() + ')');
var prefixMatch = prefixPattern.exec(number);
if (prefixMatch) {
var nationalNumber;
var carrierCode; // https://gitlab.com/catamphetamine/libphonenumber-js/-/blob/master/METADATA.md#national_prefix_for_parsing--national_prefix_transform_rule
// If a `national_prefix_for_parsing` has any "capturing groups"
// then it means that the national (significant) number is equal to
// those "capturing groups" transformed via `national_prefix_transform_rule`,
// and nothing could be said about the actual national prefix:
// what is it and was it even there.
// If a `national_prefix_for_parsing` doesn't have any "capturing groups",
// then everything it matches is a national prefix.
// To determine whether `national_prefix_for_parsing` matched any
// "capturing groups", the value of the result of calling `.exec()`
// is looked at, and if it has non-undefined values where there're
// "capturing groups" in the regular expression, then it means
// that "capturing groups" have been matched.
// It's not possible to tell whether there'll be any "capturing gropus"
// before the matching process, because a `national_prefix_for_parsing`
// could exhibit both behaviors.
var capturedGroupsCount = prefixMatch.length - 1;
var hasCapturedGroups = capturedGroupsCount > 0 && prefixMatch[capturedGroupsCount];
if (metadata.nationalPrefixTransformRule() && hasCapturedGroups) {
nationalNumber = number.replace(prefixPattern, metadata.nationalPrefixTransformRule()); // If there's more than one captured group,
// then carrier code is the second one.
if (capturedGroupsCount > 1) {
carrierCode = prefixMatch[1];
}
} // If there're no "capturing groups",
// or if there're "capturing groups" but no
// `national_prefix_transform_rule`,
// then just strip the national prefix from the number,
// and possibly a carrier code.
// Seems like there could be more.
else {
// `prefixBeforeNationalNumber` is the whole substring matched by
// the `national_prefix_for_parsing` regular expression.
// There seem to be no guarantees that it's just a national prefix.
// For example, if there's a carrier code, it's gonna be a
// part of `prefixBeforeNationalNumber` too.
var prefixBeforeNationalNumber = prefixMatch[0];
nationalNumber = number.slice(prefixBeforeNationalNumber.length); // If there's at least one captured group,
// then carrier code is the first one.
if (hasCapturedGroups) {
carrierCode = prefixMatch[1];
}
} // Tries to guess whether a national prefix was present in the input.
// This is not something copy-pasted from Google's library:
// they don't seem to have an equivalent for that.
// So this isn't an "officially approved" way of doing something like that.
// But since there seems no other existing method, this library uses it.
var nationalPrefix;
if (hasCapturedGroups) {
var possiblePositionOfTheFirstCapturedGroup = number.indexOf(prefixMatch[1]);
var possibleNationalPrefix = number.slice(0, possiblePositionOfTheFirstCapturedGroup); // Example: an Argentinian (AR) phone number `0111523456789`.
// `prefixMatch[0]` is `01115`, and `$1` is `11`,
// and the rest of the phone number is `23456789`.
// The national number is transformed via `9$1` to `91123456789`.
// National prefix `0` is detected being present at the start.
// if (possibleNationalPrefix.indexOf(metadata.numberingPlan.nationalPrefix()) === 0) {
if (possibleNationalPrefix === metadata.numberingPlan.nationalPrefix()) {
nationalPrefix = metadata.numberingPlan.nationalPrefix();
}
} else {
nationalPrefix = prefixMatch[0];
}
return {
nationalNumber: nationalNumber,
nationalPrefix: nationalPrefix,
carrierCode: carrierCode
};
}
}
return {
nationalNumber: number
};
}
//# sourceMappingURL=extractNationalNumberFromPossiblyIncompleteNumber.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,22 @@
"use strict";
var _metadata = _interopRequireDefault(require("../metadata.js"));
var _metadataMin = _interopRequireDefault(require("../../metadata.min.json"));
var _extractNationalNumberFromPossiblyIncompleteNumber = _interopRequireDefault(require("./extractNationalNumberFromPossiblyIncompleteNumber.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
describe('extractNationalNumberFromPossiblyIncompleteNumber', function () {
it('should parse a carrier code when there is no national prefix transform rule', function () {
var meta = new _metadata["default"](_metadataMin["default"]);
meta.country('AU');
(0, _extractNationalNumberFromPossiblyIncompleteNumber["default"])('18311800123', meta).should.deep.equal({
nationalPrefix: undefined,
carrierCode: '1831',
nationalNumber: '1800123'
});
});
});
//# sourceMappingURL=extractNationalNumberFromPossiblyIncompleteNumber.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"extractNationalNumberFromPossiblyIncompleteNumber.test.js","names":["describe","it","meta","Metadata","metadata","country","extractNationalNumberFromPossiblyIncompleteNumber","should","deep","equal","nationalPrefix","undefined","carrierCode","nationalNumber"],"sources":["../../source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport metadata from '../../metadata.min.json' assert { type: 'json' }\r\nimport extractNationalNumberFromPossiblyIncompleteNumber from './extractNationalNumberFromPossiblyIncompleteNumber.js'\r\n\r\ndescribe('extractNationalNumberFromPossiblyIncompleteNumber', () => {\r\n\tit('should parse a carrier code when there is no national prefix transform rule', () => {\r\n\t\tconst meta = new Metadata(metadata)\r\n\t\tmeta.country('AU')\r\n\t\textractNationalNumberFromPossiblyIncompleteNumber('18311800123', meta).should.deep.equal({\r\n\t\t\tnationalPrefix: undefined,\r\n\t\t\tcarrierCode: '1831',\r\n\t\t\tnationalNumber: '1800123'\r\n\t\t})\r\n\t})\r\n})"],"mappings":";;AAAA;;AACA;;AACA;;;;AAEAA,QAAQ,CAAC,mDAAD,EAAsD,YAAM;EACnEC,EAAE,CAAC,6EAAD,EAAgF,YAAM;IACvF,IAAMC,IAAI,GAAG,IAAIC,oBAAJ,CAAaC,uBAAb,CAAb;IACAF,IAAI,CAACG,OAAL,CAAa,IAAb;IACA,IAAAC,6DAAA,EAAkD,aAAlD,EAAiEJ,IAAjE,EAAuEK,MAAvE,CAA8EC,IAA9E,CAAmFC,KAAnF,CAAyF;MACxFC,cAAc,EAAEC,SADwE;MAExFC,WAAW,EAAE,MAF2E;MAGxFC,cAAc,EAAE;IAHwE,CAAzF;EAKA,CARC,CAAF;AASA,CAVO,CAAR"}

View File

@@ -0,0 +1,97 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.RFC3966_PREFIX_ = exports.RFC3966_PHONE_CONTEXT_ = exports.RFC3966_ISDN_SUBADDRESS_ = exports.PLUS_SIGN = void 0;
exports["default"] = extractPhoneContext;
exports.isPhoneContextValid = isPhoneContextValid;
var _constants = require("../constants.js");
// When phone numbers are written in `RFC3966` format — `"tel:+12133734253"` —
// they can have their "calling code" part written separately in a `phone-context` parameter.
// Example: `"tel:12133734253;phone-context=+1"`.
// This function parses the full phone number from the local number and the `phone-context`
// when the `phone-context` contains a `+` sign.
var PLUS_SIGN = '+';
exports.PLUS_SIGN = PLUS_SIGN;
var RFC3966_VISUAL_SEPARATOR_ = '[\\-\\.\\(\\)]?';
var RFC3966_PHONE_DIGIT_ = '(' + '[' + _constants.VALID_DIGITS + ']' + '|' + RFC3966_VISUAL_SEPARATOR_ + ')';
var RFC3966_GLOBAL_NUMBER_DIGITS_ = '^' + '\\' + PLUS_SIGN + RFC3966_PHONE_DIGIT_ + '*' + '[' + _constants.VALID_DIGITS + ']' + RFC3966_PHONE_DIGIT_ + '*' + '$';
/**
* Regular expression of valid global-number-digits for the phone-context
* parameter, following the syntax defined in RFC3966.
*/
var RFC3966_GLOBAL_NUMBER_DIGITS_PATTERN_ = new RegExp(RFC3966_GLOBAL_NUMBER_DIGITS_, 'g'); // In this port of Google's library, we don't accept alpha characters in phone numbers.
// const ALPHANUM_ = VALID_ALPHA_ + VALID_DIGITS
var ALPHANUM_ = _constants.VALID_DIGITS;
var RFC3966_DOMAINLABEL_ = '[' + ALPHANUM_ + ']+((\\-)*[' + ALPHANUM_ + '])*';
var VALID_ALPHA_ = 'a-zA-Z';
var RFC3966_TOPLABEL_ = '[' + VALID_ALPHA_ + ']+((\\-)*[' + ALPHANUM_ + '])*';
var RFC3966_DOMAINNAME_ = '^(' + RFC3966_DOMAINLABEL_ + '\\.)*' + RFC3966_TOPLABEL_ + '\\.?$';
/**
* Regular expression of valid domainname for the phone-context parameter,
* following the syntax defined in RFC3966.
*/
var RFC3966_DOMAINNAME_PATTERN_ = new RegExp(RFC3966_DOMAINNAME_, 'g');
var RFC3966_PREFIX_ = 'tel:';
exports.RFC3966_PREFIX_ = RFC3966_PREFIX_;
var RFC3966_PHONE_CONTEXT_ = ';phone-context=';
exports.RFC3966_PHONE_CONTEXT_ = RFC3966_PHONE_CONTEXT_;
var RFC3966_ISDN_SUBADDRESS_ = ';isub=';
/**
* Extracts the value of the phone-context parameter of `numberToExtractFrom`,
* following the syntax defined in RFC3966.
*
* @param {string} numberToExtractFrom
* @return {string|null} the extracted string (possibly empty), or `null` if no phone-context parameter is found.
*/
exports.RFC3966_ISDN_SUBADDRESS_ = RFC3966_ISDN_SUBADDRESS_;
function extractPhoneContext(numberToExtractFrom) {
var indexOfPhoneContext = numberToExtractFrom.indexOf(RFC3966_PHONE_CONTEXT_); // If no phone-context parameter is present
if (indexOfPhoneContext < 0) {
return null;
}
var phoneContextStart = indexOfPhoneContext + RFC3966_PHONE_CONTEXT_.length; // If phone-context parameter is empty
if (phoneContextStart >= numberToExtractFrom.length) {
return '';
}
var phoneContextEnd = numberToExtractFrom.indexOf(';', phoneContextStart); // If phone-context is not the last parameter
if (phoneContextEnd >= 0) {
return numberToExtractFrom.substring(phoneContextStart, phoneContextEnd);
} else {
return numberToExtractFrom.substring(phoneContextStart);
}
}
/**
* Returns whether the value of phoneContext follows the syntax defined in RFC3966.
*
* @param {string|null} phoneContext
* @return {boolean}
*/
function isPhoneContextValid(phoneContext) {
if (phoneContext === null) {
return true;
}
if (phoneContext.length === 0) {
return false;
} // Does phone-context value match pattern of global-number-digits or domainname.
return RFC3966_GLOBAL_NUMBER_DIGITS_PATTERN_.test(phoneContext) || RFC3966_DOMAINNAME_PATTERN_.test(phoneContext);
}
//# sourceMappingURL=extractPhoneContext.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,72 @@
"use strict";
var _parsePhoneNumber = _interopRequireDefault(require("../parsePhoneNumber.js"));
var _PhoneNumber = _interopRequireDefault(require("../PhoneNumber.js"));
var _metadataMin = _interopRequireDefault(require("../../metadata.min.json"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function parsePhoneNumber() {
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
parameters[_key] = arguments[_key];
}
parameters.push(_metadataMin["default"]);
return _parsePhoneNumber["default"].apply(this, parameters);
}
describe('extractPhoneContext', function () {
it('should parse RFC 3966 phone number URIs', function () {
// context = ";phone-context=" descriptor
// descriptor = domainname / global-number-digits
var NZ_NUMBER = new _PhoneNumber["default"]('64', '33316005', _metadataMin["default"]); // Valid global-phone-digits
expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+64'), NZ_NUMBER);
expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+64;{this isn\'t part of phone-context anymore!}'), NZ_NUMBER);
var nzFromPhoneContext = new _PhoneNumber["default"]('64', '3033316005', _metadataMin["default"]);
expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+64-3'), nzFromPhoneContext);
var brFromPhoneContext = new _PhoneNumber["default"]('55', '5033316005', _metadataMin["default"]);
expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+(555)'), brFromPhoneContext);
var usFromPhoneContext = new _PhoneNumber["default"]('1', '23033316005', _metadataMin["default"]);
expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+-1-2.3()'), usFromPhoneContext); // Valid domainname.
expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=abc.nz', 'NZ'), NZ_NUMBER);
expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=www.PHONE-numb3r.com', 'NZ'), NZ_NUMBER);
expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=a', 'NZ'), NZ_NUMBER);
expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=3phone.J.', 'NZ'), NZ_NUMBER);
expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=a--z', 'NZ'), NZ_NUMBER); // Should strip ISDN subaddress.
expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;isub=/@;phone-context=+64', 'NZ'), NZ_NUMBER); // // Should support incorrectly-written RFC 3966 phone numbers:
// // the ones written without a `tel:` prefix.
// expectPhoneNumbersToBeEqual(
// parsePhoneNumber('033316005;phone-context=+64', 'NZ'),
// NZ_NUMBER
// )
// Invalid descriptor.
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=');
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=+');
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=64');
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=++64');
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=+abc');
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=.');
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=3phone');
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=a-.nz');
expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=a{b}c');
});
});
function expectToThrowForInvalidPhoneContext(string) {
expect(parsePhoneNumber(string)).to.be.undefined;
}
function expectPhoneNumbersToBeEqual(phoneNumber1, phoneNumber2) {
if (!phoneNumber1 || !phoneNumber2) {
return false;
}
return phoneNumber1.number === phoneNumber2.number && phoneNumber1.ext === phoneNumber2.ext;
}
//# sourceMappingURL=extractPhoneContext.test.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,46 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.FIRST_GROUP_PATTERN = void 0;
exports["default"] = formatNationalNumberUsingFormat;
var _applyInternationalSeparatorStyle = _interopRequireDefault(require("./applyInternationalSeparatorStyle.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
// This was originally set to $1 but there are some countries for which the
// first group is not used in the national pattern (e.g. Argentina) so the $1
// group does not match correctly. Therefore, we use `\d`, so that the first
// group actually used in the pattern will be matched.
var FIRST_GROUP_PATTERN = /(\$\d)/;
exports.FIRST_GROUP_PATTERN = FIRST_GROUP_PATTERN;
function formatNationalNumberUsingFormat(number, format, _ref) {
var useInternationalFormat = _ref.useInternationalFormat,
withNationalPrefix = _ref.withNationalPrefix,
carrierCode = _ref.carrierCode,
metadata = _ref.metadata;
var formattedNumber = number.replace(new RegExp(format.pattern()), useInternationalFormat ? format.internationalFormat() : // This library doesn't use `domestic_carrier_code_formatting_rule`,
// because that one is only used when formatting phone numbers
// for dialing from a mobile phone, and this is not a dialing library.
// carrierCode && format.domesticCarrierCodeFormattingRule()
// // First, replace the $CC in the formatting rule with the desired carrier code.
// // Then, replace the $FG in the formatting rule with the first group
// // and the carrier code combined in the appropriate way.
// ? format.format().replace(FIRST_GROUP_PATTERN, format.domesticCarrierCodeFormattingRule().replace('$CC', carrierCode))
// : (
// withNationalPrefix && format.nationalPrefixFormattingRule()
// ? format.format().replace(FIRST_GROUP_PATTERN, format.nationalPrefixFormattingRule())
// : format.format()
// )
withNationalPrefix && format.nationalPrefixFormattingRule() ? format.format().replace(FIRST_GROUP_PATTERN, format.nationalPrefixFormattingRule()) : format.format());
if (useInternationalFormat) {
return (0, _applyInternationalSeparatorStyle["default"])(formattedNumber);
}
return formattedNumber;
}
//# sourceMappingURL=formatNationalNumberUsingFormat.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"formatNationalNumberUsingFormat.js","names":["FIRST_GROUP_PATTERN","formatNationalNumberUsingFormat","number","format","useInternationalFormat","withNationalPrefix","carrierCode","metadata","formattedNumber","replace","RegExp","pattern","internationalFormat","nationalPrefixFormattingRule","applyInternationalSeparatorStyle"],"sources":["../../source/helpers/formatNationalNumberUsingFormat.js"],"sourcesContent":["import applyInternationalSeparatorStyle from './applyInternationalSeparatorStyle.js'\r\n\r\n// This was originally set to $1 but there are some countries for which the\r\n// first group is not used in the national pattern (e.g. Argentina) so the $1\r\n// group does not match correctly. Therefore, we use `\\d`, so that the first\r\n// group actually used in the pattern will be matched.\r\nexport const FIRST_GROUP_PATTERN = /(\\$\\d)/\r\n\r\nexport default function formatNationalNumberUsingFormat(\r\n\tnumber,\r\n\tformat,\r\n\t{\r\n\t\tuseInternationalFormat,\r\n\t\twithNationalPrefix,\r\n\t\tcarrierCode,\r\n\t\tmetadata\r\n\t}\r\n) {\r\n\tconst formattedNumber = number.replace(\r\n\t\tnew RegExp(format.pattern()),\r\n\t\tuseInternationalFormat\r\n\t\t\t? format.internationalFormat()\r\n\t\t\t: (\r\n\t\t\t\t// This library doesn't use `domestic_carrier_code_formatting_rule`,\r\n\t\t\t\t// because that one is only used when formatting phone numbers\r\n\t\t\t\t// for dialing from a mobile phone, and this is not a dialing library.\r\n\t\t\t\t// carrierCode && format.domesticCarrierCodeFormattingRule()\r\n\t\t\t\t// \t// First, replace the $CC in the formatting rule with the desired carrier code.\r\n\t\t\t\t// \t// Then, replace the $FG in the formatting rule with the first group\r\n\t\t\t\t// \t// and the carrier code combined in the appropriate way.\r\n\t\t\t\t// \t? format.format().replace(FIRST_GROUP_PATTERN, format.domesticCarrierCodeFormattingRule().replace('$CC', carrierCode))\r\n\t\t\t\t// \t: (\r\n\t\t\t\t// \t\twithNationalPrefix && format.nationalPrefixFormattingRule()\r\n\t\t\t\t// \t\t\t? format.format().replace(FIRST_GROUP_PATTERN, format.nationalPrefixFormattingRule())\r\n\t\t\t\t// \t\t\t: format.format()\r\n\t\t\t\t// \t)\r\n\t\t\t\twithNationalPrefix && format.nationalPrefixFormattingRule()\r\n\t\t\t\t\t? format.format().replace(FIRST_GROUP_PATTERN, format.nationalPrefixFormattingRule())\r\n\t\t\t\t\t: format.format()\r\n\t\t\t)\r\n\t)\r\n\tif (useInternationalFormat) {\r\n\t\treturn applyInternationalSeparatorStyle(formattedNumber)\r\n\t}\r\n\treturn formattedNumber\r\n}"],"mappings":";;;;;;;;AAAA;;;;AAEA;AACA;AACA;AACA;AACO,IAAMA,mBAAmB,GAAG,QAA5B;;;AAEQ,SAASC,+BAAT,CACdC,MADc,EAEdC,MAFc,QASb;EAAA,IALAC,sBAKA,QALAA,sBAKA;EAAA,IAJAC,kBAIA,QAJAA,kBAIA;EAAA,IAHAC,WAGA,QAHAA,WAGA;EAAA,IAFAC,QAEA,QAFAA,QAEA;EACD,IAAMC,eAAe,GAAGN,MAAM,CAACO,OAAP,CACvB,IAAIC,MAAJ,CAAWP,MAAM,CAACQ,OAAP,EAAX,CADuB,EAEvBP,sBAAsB,GACnBD,MAAM,CAACS,mBAAP,EADmB,GAGpB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACAP,kBAAkB,IAAIF,MAAM,CAACU,4BAAP,EAAtB,GACGV,MAAM,CAACA,MAAP,GAAgBM,OAAhB,CAAwBT,mBAAxB,EAA6CG,MAAM,CAACU,4BAAP,EAA7C,CADH,GAEGV,MAAM,CAACA,MAAP,EApBkB,CAAxB;;EAuBA,IAAIC,sBAAJ,EAA4B;IAC3B,OAAO,IAAAU,4CAAA,EAAiCN,eAAjC,CAAP;EACA;;EACD,OAAOA,eAAP;AACA"}

View File

@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getCountryByCallingCode;
var _getCountryByNationalNumber = _interopRequireDefault(require("./getCountryByNationalNumber.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
function getCountryByCallingCode(callingCode, _ref) {
var nationalPhoneNumber = _ref.nationalNumber,
defaultCountry = _ref.defaultCountry,
metadata = _ref.metadata;
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (metadata.isNonGeographicCallingCode(callingCode)) {
return '001';
}
}
var possibleCountries = metadata.getCountryCodesForCallingCode(callingCode);
if (!possibleCountries) {
return;
} // If there's just one country corresponding to the country code,
// then just return it, without further phone number digits validation.
if (possibleCountries.length === 1) {
return possibleCountries[0];
}
return (0, _getCountryByNationalNumber["default"])(nationalPhoneNumber, {
countries: possibleCountries,
defaultCountry: defaultCountry,
metadata: metadata.metadata
});
}
//# sourceMappingURL=getCountryByCallingCode.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getCountryByCallingCode.js","names":["USE_NON_GEOGRAPHIC_COUNTRY_CODE","getCountryByCallingCode","callingCode","nationalPhoneNumber","nationalNumber","defaultCountry","metadata","isNonGeographicCallingCode","possibleCountries","getCountryCodesForCallingCode","length","getCountryByNationalNumber","countries"],"sources":["../../source/helpers/getCountryByCallingCode.js"],"sourcesContent":["import getCountryByNationalNumber from './getCountryByNationalNumber.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default function getCountryByCallingCode(callingCode, {\r\n\tnationalNumber: nationalPhoneNumber,\r\n\tdefaultCountry,\r\n\tmetadata\r\n}) {\r\n\t/* istanbul ignore if */\r\n\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\tif (metadata.isNonGeographicCallingCode(callingCode)) {\r\n\t\t\treturn '001'\r\n\t\t}\r\n\t}\r\n\tconst possibleCountries = metadata.getCountryCodesForCallingCode(callingCode)\r\n\tif (!possibleCountries) {\r\n\t\treturn\r\n\t}\r\n\t// If there's just one country corresponding to the country code,\r\n\t// then just return it, without further phone number digits validation.\r\n\tif (possibleCountries.length === 1) {\r\n\t\treturn possibleCountries[0]\r\n\t}\r\n\treturn getCountryByNationalNumber(nationalPhoneNumber, {\r\n\t\tcountries: possibleCountries,\r\n\t\tdefaultCountry,\r\n\t\tmetadata: metadata.metadata\r\n\t})\r\n}"],"mappings":";;;;;;;AAAA;;;;AAEA,IAAMA,+BAA+B,GAAG,KAAxC;;AAEe,SAASC,uBAAT,CAAiCC,WAAjC,QAIZ;EAAA,IAHcC,mBAGd,QAHFC,cAGE;EAAA,IAFFC,cAEE,QAFFA,cAEE;EAAA,IADFC,QACE,QADFA,QACE;;EACF;EACA,IAAIN,+BAAJ,EAAqC;IACpC,IAAIM,QAAQ,CAACC,0BAAT,CAAoCL,WAApC,CAAJ,EAAsD;MACrD,OAAO,KAAP;IACA;EACD;;EACD,IAAMM,iBAAiB,GAAGF,QAAQ,CAACG,6BAAT,CAAuCP,WAAvC,CAA1B;;EACA,IAAI,CAACM,iBAAL,EAAwB;IACvB;EACA,CAVC,CAWF;EACA;;;EACA,IAAIA,iBAAiB,CAACE,MAAlB,KAA6B,CAAjC,EAAoC;IACnC,OAAOF,iBAAiB,CAAC,CAAD,CAAxB;EACA;;EACD,OAAO,IAAAG,sCAAA,EAA2BR,mBAA3B,EAAgD;IACtDS,SAAS,EAAEJ,iBAD2C;IAEtDH,cAAc,EAAdA,cAFsD;IAGtDC,QAAQ,EAAEA,QAAQ,CAACA;EAHmC,CAAhD,CAAP;AAKA"}

View File

@@ -0,0 +1,66 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getCountryByNationalNumber;
var _metadata = _interopRequireDefault(require("../metadata.js"));
var _getNumberType = _interopRequireDefault(require("./getNumberType.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function getCountryByNationalNumber(nationalPhoneNumber, _ref) {
var countries = _ref.countries,
defaultCountry = _ref.defaultCountry,
metadata = _ref.metadata;
// Re-create `metadata` because it will be selecting a `country`.
metadata = new _metadata["default"](metadata); // const matchingCountries = []
for (var _iterator = _createForOfIteratorHelperLoose(countries), _step; !(_step = _iterator()).done;) {
var country = _step.value;
metadata.country(country); // "Leading digits" patterns are only defined for about 20% of all countries.
// By definition, matching "leading digits" is a sufficient but not a necessary
// condition for a phone number to belong to a country.
// The point of "leading digits" check is that it's the fastest one to get a match.
// https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md#leading_digits
// I'd suppose that "leading digits" patterns are mutually exclusive for different countries
// because of the intended use of that feature.
if (metadata.leadingDigits()) {
if (nationalPhoneNumber && nationalPhoneNumber.search(metadata.leadingDigits()) === 0) {
return country;
}
} // Else perform full validation with all of those
// fixed-line/mobile/etc regular expressions.
else if ((0, _getNumberType["default"])({
phone: nationalPhoneNumber,
country: country
}, undefined, metadata.metadata)) {
// If both the `defaultCountry` and the "main" one match the phone number,
// don't prefer the `defaultCountry` over the "main" one.
// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/154
return country; // // If the `defaultCountry` is among the `matchingCountries` then return it.
// if (defaultCountry) {
// if (country === defaultCountry) {
// return country
// }
// matchingCountries.push(country)
// } else {
// return country
// }
}
} // // Return the first ("main") one of the `matchingCountries`.
// if (matchingCountries.length > 0) {
// return matchingCountries[0]
// }
}
//# sourceMappingURL=getCountryByNationalNumber.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getCountryByNationalNumber.js","names":["getCountryByNationalNumber","nationalPhoneNumber","countries","defaultCountry","metadata","Metadata","country","leadingDigits","search","getNumberType","phone","undefined"],"sources":["../../source/helpers/getCountryByNationalNumber.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport getNumberType from './getNumberType.js'\r\n\r\nexport default function getCountryByNationalNumber(nationalPhoneNumber, {\r\n\tcountries,\r\n\tdefaultCountry,\r\n\tmetadata\r\n}) {\r\n\t// Re-create `metadata` because it will be selecting a `country`.\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\t// const matchingCountries = []\r\n\r\n\tfor (const country of countries) {\r\n\t\tmetadata.country(country)\r\n\t\t// \"Leading digits\" patterns are only defined for about 20% of all countries.\r\n\t\t// By definition, matching \"leading digits\" is a sufficient but not a necessary\r\n\t\t// condition for a phone number to belong to a country.\r\n\t\t// The point of \"leading digits\" check is that it's the fastest one to get a match.\r\n\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md#leading_digits\r\n\t\t// I'd suppose that \"leading digits\" patterns are mutually exclusive for different countries\r\n\t\t// because of the intended use of that feature.\r\n\t\tif (metadata.leadingDigits()) {\r\n\t\t\tif (nationalPhoneNumber &&\r\n\t\t\t\tnationalPhoneNumber.search(metadata.leadingDigits()) === 0) {\r\n\t\t\t\treturn country\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Else perform full validation with all of those\r\n\t\t// fixed-line/mobile/etc regular expressions.\r\n\t\telse if (getNumberType({ phone: nationalPhoneNumber, country }, undefined, metadata.metadata)) {\r\n\t\t\t// If both the `defaultCountry` and the \"main\" one match the phone number,\r\n\t\t\t// don't prefer the `defaultCountry` over the \"main\" one.\r\n\t\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/154\r\n\t\t\treturn country\r\n\t\t\t// // If the `defaultCountry` is among the `matchingCountries` then return it.\r\n\t\t\t// if (defaultCountry) {\r\n\t\t\t// \tif (country === defaultCountry) {\r\n\t\t\t// \t\treturn country\r\n\t\t\t// \t}\r\n\t\t\t// \tmatchingCountries.push(country)\r\n\t\t\t// } else {\r\n\t\t\t// \treturn country\r\n\t\t\t// }\r\n\t\t}\r\n\t}\r\n\r\n\t// // Return the first (\"main\") one of the `matchingCountries`.\r\n\t// if (matchingCountries.length > 0) {\r\n\t// \treturn matchingCountries[0]\r\n\t// }\r\n}"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;;;AAEe,SAASA,0BAAT,CAAoCC,mBAApC,QAIZ;EAAA,IAHFC,SAGE,QAHFA,SAGE;EAAA,IAFFC,cAEE,QAFFA,cAEE;EAAA,IADFC,QACE,QADFA,QACE;EACF;EACAA,QAAQ,GAAG,IAAIC,oBAAJ,CAAaD,QAAb,CAAX,CAFE,CAIF;;EAEA,qDAAsBF,SAAtB,wCAAiC;IAAA,IAAtBI,OAAsB;IAChCF,QAAQ,CAACE,OAAT,CAAiBA,OAAjB,EADgC,CAEhC;IACA;IACA;IACA;IACA;IACA;IACA;;IACA,IAAIF,QAAQ,CAACG,aAAT,EAAJ,EAA8B;MAC7B,IAAIN,mBAAmB,IACtBA,mBAAmB,CAACO,MAApB,CAA2BJ,QAAQ,CAACG,aAAT,EAA3B,MAAyD,CAD1D,EAC6D;QAC5D,OAAOD,OAAP;MACA;IACD,CALD,CAMA;IACA;IAPA,KAQK,IAAI,IAAAG,yBAAA,EAAc;MAAEC,KAAK,EAAET,mBAAT;MAA8BK,OAAO,EAAPA;IAA9B,CAAd,EAAuDK,SAAvD,EAAkEP,QAAQ,CAACA,QAA3E,CAAJ,EAA0F;MAC9F;MACA;MACA;MACA,OAAOE,OAAP,CAJ8F,CAK9F;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;IACA;EACD,CAtCC,CAwCF;EACA;EACA;EACA;;AACA"}

View File

@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getIddPrefix;
var _metadata = _interopRequireDefault(require("../metadata.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Pattern that makes it easy to distinguish whether a region has a single
* international dialing prefix or not. If a region has a single international
* prefix (e.g. 011 in USA), it will be represented as a string that contains
* a sequence of ASCII digits, and possibly a tilde, which signals waiting for
* the tone. If there are multiple available international prefixes in a
* region, they will be represented as a regex string that always contains one
* or more characters that are not ASCII digits or a tilde.
*/
var SINGLE_IDD_PREFIX_REG_EXP = /^[\d]+(?:[~\u2053\u223C\uFF5E][\d]+)?$/; // For regions that have multiple IDD prefixes
// a preferred IDD prefix is returned.
function getIddPrefix(country, callingCode, metadata) {
var countryMetadata = new _metadata["default"](metadata);
countryMetadata.selectNumberingPlan(country, callingCode);
if (countryMetadata.defaultIDDPrefix()) {
return countryMetadata.defaultIDDPrefix();
}
if (SINGLE_IDD_PREFIX_REG_EXP.test(countryMetadata.IDDPrefix())) {
return countryMetadata.IDDPrefix();
}
}
//# sourceMappingURL=getIddPrefix.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getIddPrefix.js","names":["SINGLE_IDD_PREFIX_REG_EXP","getIddPrefix","country","callingCode","metadata","countryMetadata","Metadata","selectNumberingPlan","defaultIDDPrefix","test","IDDPrefix"],"sources":["../../source/helpers/getIddPrefix.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\n\r\n/**\r\n * Pattern that makes it easy to distinguish whether a region has a single\r\n * international dialing prefix or not. If a region has a single international\r\n * prefix (e.g. 011 in USA), it will be represented as a string that contains\r\n * a sequence of ASCII digits, and possibly a tilde, which signals waiting for\r\n * the tone. If there are multiple available international prefixes in a\r\n * region, they will be represented as a regex string that always contains one\r\n * or more characters that are not ASCII digits or a tilde.\r\n */\r\nconst SINGLE_IDD_PREFIX_REG_EXP = /^[\\d]+(?:[~\\u2053\\u223C\\uFF5E][\\d]+)?$/\r\n\r\n// For regions that have multiple IDD prefixes\r\n// a preferred IDD prefix is returned.\r\nexport default function getIddPrefix(country, callingCode, metadata) {\r\n\tconst countryMetadata = new Metadata(metadata)\r\n\tcountryMetadata.selectNumberingPlan(country, callingCode)\r\n\tif (countryMetadata.defaultIDDPrefix()) {\r\n\t\treturn countryMetadata.defaultIDDPrefix()\r\n\t}\r\n\tif (SINGLE_IDD_PREFIX_REG_EXP.test(countryMetadata.IDDPrefix())) {\r\n\t\treturn countryMetadata.IDDPrefix()\r\n\t}\r\n}\r\n"],"mappings":";;;;;;;AAAA;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMA,yBAAyB,GAAG,wCAAlC,C,CAEA;AACA;;AACe,SAASC,YAAT,CAAsBC,OAAtB,EAA+BC,WAA/B,EAA4CC,QAA5C,EAAsD;EACpE,IAAMC,eAAe,GAAG,IAAIC,oBAAJ,CAAaF,QAAb,CAAxB;EACAC,eAAe,CAACE,mBAAhB,CAAoCL,OAApC,EAA6CC,WAA7C;;EACA,IAAIE,eAAe,CAACG,gBAAhB,EAAJ,EAAwC;IACvC,OAAOH,eAAe,CAACG,gBAAhB,EAAP;EACA;;EACD,IAAIR,yBAAyB,CAACS,IAA1B,CAA+BJ,eAAe,CAACK,SAAhB,EAA/B,CAAJ,EAAiE;IAChE,OAAOL,eAAe,CAACK,SAAhB,EAAP;EACA;AACD"}

View File

@@ -0,0 +1,104 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getNumberType;
exports.isNumberTypeEqualTo = isNumberTypeEqualTo;
var _metadata = _interopRequireDefault(require("../metadata.js"));
var _matchesEntirely = _interopRequireDefault(require("./matchesEntirely.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
var NON_FIXED_LINE_PHONE_TYPES = ['MOBILE', 'PREMIUM_RATE', 'TOLL_FREE', 'SHARED_COST', 'VOIP', 'PERSONAL_NUMBER', 'PAGER', 'UAN', 'VOICEMAIL']; // Finds out national phone number type (fixed line, mobile, etc)
function getNumberType(input, options, metadata) {
// If assigning the `{}` default value is moved to the arguments above,
// code coverage would decrease for some weird reason.
options = options || {}; // When `parse()` returns an empty object — `{}` —
// that means that the phone number is malformed,
// so it can't possibly be valid.
if (!input.country && !input.countryCallingCode) {
return;
}
metadata = new _metadata["default"](metadata);
metadata.selectNumberingPlan(input.country, input.countryCallingCode);
var nationalNumber = options.v2 ? input.nationalNumber : input.phone; // The following is copy-pasted from the original function:
// https://github.com/googlei18n/libphonenumber/blob/3ea547d4fbaa2d0b67588904dfa5d3f2557c27ff/javascript/i18n/phonenumbers/phonenumberutil.js#L2835
// Is this national number even valid for this country
if (!(0, _matchesEntirely["default"])(nationalNumber, metadata.nationalNumberPattern())) {
return;
} // Is it fixed line number
if (isNumberTypeEqualTo(nationalNumber, 'FIXED_LINE', metadata)) {
// Because duplicate regular expressions are removed
// to reduce metadata size, if "mobile" pattern is ""
// then it means it was removed due to being a duplicate of the fixed-line pattern.
//
if (metadata.type('MOBILE') && metadata.type('MOBILE').pattern() === '') {
return 'FIXED_LINE_OR_MOBILE';
} // `MOBILE` type pattern isn't included if it matched `FIXED_LINE` one.
// For example, for "US" country.
// Old metadata (< `1.0.18`) had a specific "types" data structure
// that happened to be `undefined` for `MOBILE` in that case.
// Newer metadata (>= `1.0.18`) has another data structure that is
// not `undefined` for `MOBILE` in that case (it's just an empty array).
// So this `if` is just for backwards compatibility with old metadata.
if (!metadata.type('MOBILE')) {
return 'FIXED_LINE_OR_MOBILE';
} // Check if the number happens to qualify as both fixed line and mobile.
// (no such country in the minimal metadata set)
/* istanbul ignore if */
if (isNumberTypeEqualTo(nationalNumber, 'MOBILE', metadata)) {
return 'FIXED_LINE_OR_MOBILE';
}
return 'FIXED_LINE';
}
for (var _iterator = _createForOfIteratorHelperLoose(NON_FIXED_LINE_PHONE_TYPES), _step; !(_step = _iterator()).done;) {
var type = _step.value;
if (isNumberTypeEqualTo(nationalNumber, type, metadata)) {
return type;
}
}
}
function isNumberTypeEqualTo(nationalNumber, type, metadata) {
type = metadata.type(type);
if (!type || !type.pattern()) {
return false;
} // Check if any possible number lengths are present;
// if so, we use them to avoid checking
// the validation pattern if they don't match.
// If they are absent, this means they match
// the general description, which we have
// already checked before a specific number type.
if (type.possibleLengths() && type.possibleLengths().indexOf(nationalNumber.length) < 0) {
return false;
}
return (0, _matchesEntirely["default"])(nationalNumber, type.pattern());
}
//# sourceMappingURL=getNumberType.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,26 @@
"use strict";
var _getNumberType = _interopRequireDefault(require("./getNumberType.js"));
var _metadataMin = _interopRequireDefault(require("../../test/metadata/1.0.0/metadata.min.json"));
var _metadata = _interopRequireDefault(require("../metadata.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
describe('getNumberType', function () {
it('should get number type when using old metadata', function () {
(0, _getNumberType["default"])({
nationalNumber: '2133734253',
country: 'US'
}, {
v2: true
}, _metadataMin["default"]).should.equal('FIXED_LINE_OR_MOBILE');
});
it('should return `undefined` when the phone number is a malformed one', function () {
expect((0, _getNumberType["default"])({}, {
v2: true
}, _metadataMin["default"])).to.equal(undefined);
});
});
//# sourceMappingURL=getNumberType.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getNumberType.test.js","names":["describe","it","getNumberType","nationalNumber","country","v2","oldMetadata","should","equal","expect","to","undefined"],"sources":["../../source/helpers/getNumberType.test.js"],"sourcesContent":["import getNumberType from './getNumberType.js'\r\n\r\nimport oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' assert { type: 'json' }\r\n\r\nimport Metadata from '../metadata.js'\r\n\r\ndescribe('getNumberType', function() {\r\n\tit('should get number type when using old metadata', function() {\r\n\t\tgetNumberType(\r\n\t\t\t{\r\n\t\t\t\tnationalNumber: '2133734253',\r\n\t\t\t\tcountry: 'US'\r\n\t\t\t},\r\n\t\t\t{ v2: true },\r\n\t\t\toldMetadata\r\n\t\t).should.equal('FIXED_LINE_OR_MOBILE')\r\n\t})\r\n\r\n\tit('should return `undefined` when the phone number is a malformed one', function() {\r\n\t\texpect(getNumberType(\r\n\t\t\t{},\r\n\t\t\t{ v2: true },\r\n\t\t\toldMetadata\r\n\t\t)).to.equal(undefined)\r\n\t})\r\n})"],"mappings":";;AAAA;;AAEA;;AAEA;;;;AAEAA,QAAQ,CAAC,eAAD,EAAkB,YAAW;EACpCC,EAAE,CAAC,gDAAD,EAAmD,YAAW;IAC/D,IAAAC,yBAAA,EACC;MACCC,cAAc,EAAE,YADjB;MAECC,OAAO,EAAE;IAFV,CADD,EAKC;MAAEC,EAAE,EAAE;IAAN,CALD,EAMCC,uBAND,EAOEC,MAPF,CAOSC,KAPT,CAOe,sBAPf;EAQA,CATC,CAAF;EAWAP,EAAE,CAAC,oEAAD,EAAuE,YAAW;IACnFQ,MAAM,CAAC,IAAAP,yBAAA,EACN,EADM,EAEN;MAAEG,EAAE,EAAE;IAAN,CAFM,EAGNC,uBAHM,CAAD,CAAN,CAIGI,EAJH,CAIMF,KAJN,CAIYG,SAJZ;EAKA,CANC,CAAF;AAOA,CAnBO,CAAR"}

View File

@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getPossibleCountriesForNumber;
var _metadata2 = _interopRequireDefault(require("../metadata.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Returns a list of countries that the phone number could potentially belong to.
* @param {string} callingCode — Calling code.
* @param {string} nationalNumber — National (significant) number.
* @param {object} metadata — Metadata.
* @return {string[]} A list of possible countries.
*/
function getPossibleCountriesForNumber(callingCode, nationalNumber, metadata) {
var _metadata = new _metadata2["default"](metadata);
var possibleCountries = _metadata.getCountryCodesForCallingCode(callingCode);
if (!possibleCountries) {
return [];
}
return possibleCountries.filter(function (country) {
return couldNationalNumberBelongToCountry(nationalNumber, country, metadata);
});
}
function couldNationalNumberBelongToCountry(nationalNumber, country, metadata) {
var _metadata = new _metadata2["default"](metadata);
_metadata.selectNumberingPlan(country);
if (_metadata.numberingPlan.possibleLengths().indexOf(nationalNumber.length) >= 0) {
return true;
}
return false;
}
//# sourceMappingURL=getPossibleCountriesForNumber.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getPossibleCountriesForNumber.js","names":["getPossibleCountriesForNumber","callingCode","nationalNumber","metadata","_metadata","Metadata","possibleCountries","getCountryCodesForCallingCode","filter","country","couldNationalNumberBelongToCountry","selectNumberingPlan","numberingPlan","possibleLengths","indexOf","length"],"sources":["../../source/helpers/getPossibleCountriesForNumber.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\n\r\n/**\r\n * Returns a list of countries that the phone number could potentially belong to.\r\n * @param {string} callingCode — Calling code.\r\n * @param {string} nationalNumber — National (significant) number.\r\n * @param {object} metadata — Metadata.\r\n * @return {string[]} A list of possible countries.\r\n */\r\nexport default function getPossibleCountriesForNumber(callingCode, nationalNumber, metadata) {\r\n\tconst _metadata = new Metadata(metadata)\r\n\tlet possibleCountries = _metadata.getCountryCodesForCallingCode(callingCode)\r\n\tif (!possibleCountries) {\r\n\t\treturn []\r\n\t}\r\n\treturn possibleCountries.filter((country) => {\r\n\t\treturn couldNationalNumberBelongToCountry(nationalNumber, country, metadata)\r\n\t})\r\n}\r\n\r\nfunction couldNationalNumberBelongToCountry(nationalNumber, country, metadata) {\r\n\tconst _metadata = new Metadata(metadata)\r\n\t_metadata.selectNumberingPlan(country)\r\n\tif (_metadata.numberingPlan.possibleLengths().indexOf(nationalNumber.length) >= 0) {\r\n\t\treturn true\r\n\t}\r\n\treturn false\r\n}"],"mappings":";;;;;;;AAAA;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,6BAAT,CAAuCC,WAAvC,EAAoDC,cAApD,EAAoEC,QAApE,EAA8E;EAC5F,IAAMC,SAAS,GAAG,IAAIC,qBAAJ,CAAaF,QAAb,CAAlB;;EACA,IAAIG,iBAAiB,GAAGF,SAAS,CAACG,6BAAV,CAAwCN,WAAxC,CAAxB;;EACA,IAAI,CAACK,iBAAL,EAAwB;IACvB,OAAO,EAAP;EACA;;EACD,OAAOA,iBAAiB,CAACE,MAAlB,CAAyB,UAACC,OAAD,EAAa;IAC5C,OAAOC,kCAAkC,CAACR,cAAD,EAAiBO,OAAjB,EAA0BN,QAA1B,CAAzC;EACA,CAFM,CAAP;AAGA;;AAED,SAASO,kCAAT,CAA4CR,cAA5C,EAA4DO,OAA5D,EAAqEN,QAArE,EAA+E;EAC9E,IAAMC,SAAS,GAAG,IAAIC,qBAAJ,CAAaF,QAAb,CAAlB;;EACAC,SAAS,CAACO,mBAAV,CAA8BF,OAA9B;;EACA,IAAIL,SAAS,CAACQ,aAAV,CAAwBC,eAAxB,GAA0CC,OAA1C,CAAkDZ,cAAc,CAACa,MAAjE,KAA4E,CAAhF,EAAmF;IAClF,OAAO,IAAP;EACA;;EACD,OAAO,KAAP;AACA"}

View File

@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = isObject;
var objectConstructor = {}.constructor;
function isObject(object) {
return object !== undefined && object !== null && object.constructor === objectConstructor;
}
//# sourceMappingURL=isObject.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"isObject.js","names":["objectConstructor","constructor","isObject","object","undefined"],"sources":["../../source/helpers/isObject.js"],"sourcesContent":["const objectConstructor = {}.constructor;\r\n\r\nexport default function isObject(object) {\r\n return object !== undefined && object !== null && object.constructor === objectConstructor;\r\n}\r\n"],"mappings":";;;;;;AAAA,IAAMA,iBAAiB,GAAG,GAAGC,WAA7B;;AAEe,SAASC,QAAT,CAAkBC,MAAlB,EAA0B;EACvC,OAAOA,MAAM,KAAKC,SAAX,IAAwBD,MAAM,KAAK,IAAnC,IAA2CA,MAAM,CAACF,WAAP,KAAuBD,iBAAzE;AACD"}

View File

@@ -0,0 +1,85 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.VALID_PHONE_NUMBER_WITH_EXTENSION = exports.VALID_PHONE_NUMBER = void 0;
exports["default"] = isViablePhoneNumber;
exports.isViablePhoneNumberStart = isViablePhoneNumberStart;
var _constants = require("../constants.js");
var _createExtensionPattern = _interopRequireDefault(require("./extension/createExtensionPattern.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
// Regular expression of viable phone numbers. This is location independent.
// Checks we have at least three leading digits, and only valid punctuation,
// alpha characters and digits in the phone number. Does not include extension
// data. The symbol 'x' is allowed here as valid punctuation since it is often
// used as a placeholder for carrier codes, for example in Brazilian phone
// numbers. We also allow multiple '+' characters at the start.
//
// Corresponds to the following:
// [digits]{minLengthNsn}|
// plus_sign*
// (([punctuation]|[star])*[digits]){3,}([punctuation]|[star]|[digits]|[alpha])*
//
// The first reg-ex is to allow short numbers (two digits long) to be parsed if
// they are entered as "15" etc, but only if there is no punctuation in them.
// The second expression restricts the number of digits to three or more, but
// then allows them to be in international form, and to have alpha-characters
// and punctuation. We split up the two reg-exes here and combine them when
// creating the reg-ex VALID_PHONE_NUMBER_PATTERN itself so we can prefix it
// with ^ and append $ to each branch.
//
// "Note VALID_PUNCTUATION starts with a -,
// so must be the first in the range" (c) Google devs.
// (wtf did they mean by saying that; probably nothing)
//
var MIN_LENGTH_PHONE_NUMBER_PATTERN = '[' + _constants.VALID_DIGITS + ']{' + _constants.MIN_LENGTH_FOR_NSN + '}'; //
// And this is the second reg-exp:
// (see MIN_LENGTH_PHONE_NUMBER_PATTERN for a full description of this reg-exp)
//
var VALID_PHONE_NUMBER = '[' + _constants.PLUS_CHARS + ']{0,1}' + '(?:' + '[' + _constants.VALID_PUNCTUATION + ']*' + '[' + _constants.VALID_DIGITS + ']' + '){3,}' + '[' + _constants.VALID_PUNCTUATION + _constants.VALID_DIGITS + ']*'; // This regular expression isn't present in Google's `libphonenumber`
// and is only used to determine whether the phone number being input
// is too short for it to even consider it a "valid" number.
// This is just a way to differentiate between a really invalid phone
// number like "abcde" and a valid phone number that a user has just
// started inputting, like "+1" or "1": both these cases would be
// considered `NOT_A_NUMBER` by Google's `libphonenumber`, but this
// library can provide a more detailed error message — whether it's
// really "not a number", or is it just a start of a valid phone number.
exports.VALID_PHONE_NUMBER = VALID_PHONE_NUMBER;
var VALID_PHONE_NUMBER_START_REG_EXP = new RegExp('^' + '[' + _constants.PLUS_CHARS + ']{0,1}' + '(?:' + '[' + _constants.VALID_PUNCTUATION + ']*' + '[' + _constants.VALID_DIGITS + ']' + '){1,2}' + '$', 'i');
var VALID_PHONE_NUMBER_WITH_EXTENSION = VALID_PHONE_NUMBER + // Phone number extensions
'(?:' + (0, _createExtensionPattern["default"])() + ')?'; // The combined regular expression for valid phone numbers:
//
exports.VALID_PHONE_NUMBER_WITH_EXTENSION = VALID_PHONE_NUMBER_WITH_EXTENSION;
var VALID_PHONE_NUMBER_PATTERN = new RegExp( // Either a short two-digit-only phone number
'^' + MIN_LENGTH_PHONE_NUMBER_PATTERN + '$' + '|' + // Or a longer fully parsed phone number (min 3 characters)
'^' + VALID_PHONE_NUMBER_WITH_EXTENSION + '$', 'i'); // Checks to see if the string of characters could possibly be a phone number at
// all. At the moment, checks to see that the string begins with at least 2
// digits, ignoring any punctuation commonly found in phone numbers. This method
// does not require the number to be normalized in advance - but does assume
// that leading non-number symbols have been removed, such as by the method
// `extract_possible_number`.
//
function isViablePhoneNumber(number) {
return number.length >= _constants.MIN_LENGTH_FOR_NSN && VALID_PHONE_NUMBER_PATTERN.test(number);
} // This is just a way to differentiate between a really invalid phone
// number like "abcde" and a valid phone number that a user has just
// started inputting, like "+1" or "1": both these cases would be
// considered `NOT_A_NUMBER` by Google's `libphonenumber`, but this
// library can provide a more detailed error message — whether it's
// really "not a number", or is it just a start of a valid phone number.
function isViablePhoneNumberStart(number) {
return VALID_PHONE_NUMBER_START_REG_EXP.test(number);
}
//# sourceMappingURL=isViablePhoneNumber.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = matchesEntirely;
/**
* Checks whether the entire input sequence can be matched
* against the regular expression.
* @return {boolean}
*/
function matchesEntirely(text, regular_expression) {
// If assigning the `''` default value is moved to the arguments above,
// code coverage would decrease for some weird reason.
text = text || '';
return new RegExp('^(?:' + regular_expression + ')$').test(text);
}
//# sourceMappingURL=matchesEntirely.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"matchesEntirely.js","names":["matchesEntirely","text","regular_expression","RegExp","test"],"sources":["../../source/helpers/matchesEntirely.js"],"sourcesContent":["/**\r\n * Checks whether the entire input sequence can be matched\r\n * against the regular expression.\r\n * @return {boolean}\r\n */\r\nexport default function matchesEntirely(text, regular_expression) {\r\n\t// If assigning the `''` default value is moved to the arguments above,\r\n\t// code coverage would decrease for some weird reason.\r\n\ttext = text || ''\r\n\treturn new RegExp('^(?:' + regular_expression + ')$').test(text)\r\n}"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACe,SAASA,eAAT,CAAyBC,IAAzB,EAA+BC,kBAA/B,EAAmD;EACjE;EACA;EACAD,IAAI,GAAGA,IAAI,IAAI,EAAf;EACA,OAAO,IAAIE,MAAJ,CAAW,SAASD,kBAAT,GAA8B,IAAzC,EAA+CE,IAA/C,CAAoDH,IAApD,CAAP;AACA"}

View File

@@ -0,0 +1,15 @@
"use strict";
var _matchesEntirely = _interopRequireDefault(require("./matchesEntirely.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
describe('matchesEntirely', function () {
it('should work in edge cases', function () {
// No text.
(0, _matchesEntirely["default"])(undefined, '').should.equal(true); // "OR" in regexp.
(0, _matchesEntirely["default"])('911231231', '4\d{8}|[1-9]\d{7}').should.equal(false);
});
});
//# sourceMappingURL=matchesEntirely.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"matchesEntirely.test.js","names":["describe","it","matchesEntirely","undefined","should","equal"],"sources":["../../source/helpers/matchesEntirely.test.js"],"sourcesContent":["import matchesEntirely from './matchesEntirely.js'\r\n\r\ndescribe('matchesEntirely', () => {\r\n\tit('should work in edge cases', () => {\r\n\t\t// No text.\r\n\t\tmatchesEntirely(undefined, '').should.equal(true)\r\n\r\n\t\t// \"OR\" in regexp.\r\n\t\tmatchesEntirely('911231231', '4\\d{8}|[1-9]\\d{7}').should.equal(false)\r\n\t})\r\n})"],"mappings":";;AAAA;;;;AAEAA,QAAQ,CAAC,iBAAD,EAAoB,YAAM;EACjCC,EAAE,CAAC,2BAAD,EAA8B,YAAM;IACrC;IACA,IAAAC,2BAAA,EAAgBC,SAAhB,EAA2B,EAA3B,EAA+BC,MAA/B,CAAsCC,KAAtC,CAA4C,IAA5C,EAFqC,CAIrC;;IACA,IAAAH,2BAAA,EAAgB,WAAhB,EAA6B,mBAA7B,EAAkDE,MAAlD,CAAyDC,KAAzD,CAA+D,KAA/D;EACA,CANC,CAAF;AAOA,CARO,CAAR"}

View File

@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = mergeArrays;
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
/**
* Merges two arrays.
* @param {*} a
* @param {*} b
* @return {*}
*/
function mergeArrays(a, b) {
var merged = a.slice();
for (var _iterator = _createForOfIteratorHelperLoose(b), _step; !(_step = _iterator()).done;) {
var element = _step.value;
if (a.indexOf(element) < 0) {
merged.push(element);
}
}
return merged.sort(function (a, b) {
return a - b;
}); // ES6 version, requires Set polyfill.
// let merged = new Set(a)
// for (const element of b) {
// merged.add(i)
// }
// return Array.from(merged).sort((a, b) => a - b)
}
//# sourceMappingURL=mergeArrays.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mergeArrays.js","names":["mergeArrays","a","b","merged","slice","element","indexOf","push","sort"],"sources":["../../source/helpers/mergeArrays.js"],"sourcesContent":["/**\r\n * Merges two arrays.\r\n * @param {*} a\r\n * @param {*} b\r\n * @return {*}\r\n */\r\nexport default function mergeArrays(a, b) {\r\n\tconst merged = a.slice()\r\n\r\n\tfor (const element of b) {\r\n\t\tif (a.indexOf(element) < 0) {\r\n\t\t\tmerged.push(element)\r\n\t\t}\r\n\t}\r\n\r\n\treturn merged.sort((a, b) => a - b)\r\n\r\n\t// ES6 version, requires Set polyfill.\r\n\t// let merged = new Set(a)\r\n\t// for (const element of b) {\r\n\t// \tmerged.add(i)\r\n\t// }\r\n\t// return Array.from(merged).sort((a, b) => a - b)\r\n}"],"mappings":";;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,WAAT,CAAqBC,CAArB,EAAwBC,CAAxB,EAA2B;EACzC,IAAMC,MAAM,GAAGF,CAAC,CAACG,KAAF,EAAf;;EAEA,qDAAsBF,CAAtB,wCAAyB;IAAA,IAAdG,OAAc;;IACxB,IAAIJ,CAAC,CAACK,OAAF,CAAUD,OAAV,IAAqB,CAAzB,EAA4B;MAC3BF,MAAM,CAACI,IAAP,CAAYF,OAAZ;IACA;EACD;;EAED,OAAOF,MAAM,CAACK,IAAP,CAAY,UAACP,CAAD,EAAIC,CAAJ;IAAA,OAAUD,CAAC,GAAGC,CAAd;EAAA,CAAZ,CAAP,CATyC,CAWzC;EACA;EACA;EACA;EACA;EACA;AACA"}

View File

@@ -0,0 +1,12 @@
"use strict";
var _mergeArrays = _interopRequireDefault(require("./mergeArrays.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
describe('mergeArrays', function () {
it('should merge arrays', function () {
(0, _mergeArrays["default"])([1, 2], [2, 3]).should.deep.equal([1, 2, 3]);
});
});
//# sourceMappingURL=mergeArrays.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mergeArrays.test.js","names":["describe","it","mergeArrays","should","deep","equal"],"sources":["../../source/helpers/mergeArrays.test.js"],"sourcesContent":["import mergeArrays from './mergeArrays.js'\r\n\r\ndescribe('mergeArrays', () => {\r\n\tit('should merge arrays', () => {\r\n\t\tmergeArrays([1, 2], [2, 3]).should.deep.equal([1, 2, 3])\r\n\t})\r\n})"],"mappings":";;AAAA;;;;AAEAA,QAAQ,CAAC,aAAD,EAAgB,YAAM;EAC7BC,EAAE,CAAC,qBAAD,EAAwB,YAAM;IAC/B,IAAAC,uBAAA,EAAY,CAAC,CAAD,EAAI,CAAJ,CAAZ,EAAoB,CAAC,CAAD,EAAI,CAAJ,CAApB,EAA4BC,MAA5B,CAAmCC,IAAnC,CAAwCC,KAAxC,CAA8C,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAA9C;EACA,CAFC,CAAF;AAGA,CAJO,CAAR"}

View File

@@ -0,0 +1,133 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DIGITS = void 0;
exports["default"] = parseDigits;
exports.parseDigit = parseDigit;
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
// These mappings map a character (key) to a specific digit that should
// replace it for normalization purposes. Non-European digits that
// may be used in phone numbers are mapped to a European equivalent.
//
// E.g. in Iraq they don't write `+442323234` but rather `+٤٤٢٣٢٣٢٣٤`.
//
var DIGITS = {
'0': '0',
'1': '1',
'2': '2',
'3': '3',
'4': '4',
'5': '5',
'6': '6',
'7': '7',
'8': '8',
'9': '9',
"\uFF10": '0',
// Fullwidth digit 0
"\uFF11": '1',
// Fullwidth digit 1
"\uFF12": '2',
// Fullwidth digit 2
"\uFF13": '3',
// Fullwidth digit 3
"\uFF14": '4',
// Fullwidth digit 4
"\uFF15": '5',
// Fullwidth digit 5
"\uFF16": '6',
// Fullwidth digit 6
"\uFF17": '7',
// Fullwidth digit 7
"\uFF18": '8',
// Fullwidth digit 8
"\uFF19": '9',
// Fullwidth digit 9
"\u0660": '0',
// Arabic-indic digit 0
"\u0661": '1',
// Arabic-indic digit 1
"\u0662": '2',
// Arabic-indic digit 2
"\u0663": '3',
// Arabic-indic digit 3
"\u0664": '4',
// Arabic-indic digit 4
"\u0665": '5',
// Arabic-indic digit 5
"\u0666": '6',
// Arabic-indic digit 6
"\u0667": '7',
// Arabic-indic digit 7
"\u0668": '8',
// Arabic-indic digit 8
"\u0669": '9',
// Arabic-indic digit 9
"\u06F0": '0',
// Eastern-Arabic digit 0
"\u06F1": '1',
// Eastern-Arabic digit 1
"\u06F2": '2',
// Eastern-Arabic digit 2
"\u06F3": '3',
// Eastern-Arabic digit 3
"\u06F4": '4',
// Eastern-Arabic digit 4
"\u06F5": '5',
// Eastern-Arabic digit 5
"\u06F6": '6',
// Eastern-Arabic digit 6
"\u06F7": '7',
// Eastern-Arabic digit 7
"\u06F8": '8',
// Eastern-Arabic digit 8
"\u06F9": '9' // Eastern-Arabic digit 9
};
exports.DIGITS = DIGITS;
function parseDigit(character) {
return DIGITS[character];
}
/**
* Parses phone number digits from a string.
* Drops all punctuation leaving only digits.
* Also converts wide-ascii and arabic-indic numerals to conventional numerals.
* E.g. in Iraq they don't write `+442323234` but rather `+٤٤٢٣٢٣٢٣٤`.
* @param {string} string
* @return {string}
* @example
* ```js
* parseDigits('8 (800) 555')
* // Outputs '8800555'.
* ```
*/
function parseDigits(string) {
var result = ''; // Using `.split('')` here instead of normal `for ... of`
// because the importing application doesn't neccessarily include an ES6 polyfill.
// The `.split('')` approach discards "exotic" UTF-8 characters
// (the ones consisting of four bytes) but digits
// (including non-European ones) don't fall into that range
// so such "exotic" characters would be discarded anyway.
for (var _iterator = _createForOfIteratorHelperLoose(string.split('')), _step; !(_step = _iterator()).done;) {
var character = _step.value;
var digit = parseDigit(character);
if (digit) {
result += digit;
}
}
return result;
}
//# sourceMappingURL=parseDigits.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"parseDigits.js","names":["DIGITS","parseDigit","character","parseDigits","string","result","split","digit"],"sources":["../../source/helpers/parseDigits.js"],"sourcesContent":["// These mappings map a character (key) to a specific digit that should\r\n// replace it for normalization purposes. Non-European digits that\r\n// may be used in phone numbers are mapped to a European equivalent.\r\n//\r\n// E.g. in Iraq they don't write `+442323234` but rather `+٤٤٢٣٢٣٢٣٤`.\r\n//\r\nexport const DIGITS = {\r\n\t'0': '0',\r\n\t'1': '1',\r\n\t'2': '2',\r\n\t'3': '3',\r\n\t'4': '4',\r\n\t'5': '5',\r\n\t'6': '6',\r\n\t'7': '7',\r\n\t'8': '8',\r\n\t'9': '9',\r\n\t'\\uFF10': '0', // Fullwidth digit 0\r\n\t'\\uFF11': '1', // Fullwidth digit 1\r\n\t'\\uFF12': '2', // Fullwidth digit 2\r\n\t'\\uFF13': '3', // Fullwidth digit 3\r\n\t'\\uFF14': '4', // Fullwidth digit 4\r\n\t'\\uFF15': '5', // Fullwidth digit 5\r\n\t'\\uFF16': '6', // Fullwidth digit 6\r\n\t'\\uFF17': '7', // Fullwidth digit 7\r\n\t'\\uFF18': '8', // Fullwidth digit 8\r\n\t'\\uFF19': '9', // Fullwidth digit 9\r\n\t'\\u0660': '0', // Arabic-indic digit 0\r\n\t'\\u0661': '1', // Arabic-indic digit 1\r\n\t'\\u0662': '2', // Arabic-indic digit 2\r\n\t'\\u0663': '3', // Arabic-indic digit 3\r\n\t'\\u0664': '4', // Arabic-indic digit 4\r\n\t'\\u0665': '5', // Arabic-indic digit 5\r\n\t'\\u0666': '6', // Arabic-indic digit 6\r\n\t'\\u0667': '7', // Arabic-indic digit 7\r\n\t'\\u0668': '8', // Arabic-indic digit 8\r\n\t'\\u0669': '9', // Arabic-indic digit 9\r\n\t'\\u06F0': '0', // Eastern-Arabic digit 0\r\n\t'\\u06F1': '1', // Eastern-Arabic digit 1\r\n\t'\\u06F2': '2', // Eastern-Arabic digit 2\r\n\t'\\u06F3': '3', // Eastern-Arabic digit 3\r\n\t'\\u06F4': '4', // Eastern-Arabic digit 4\r\n\t'\\u06F5': '5', // Eastern-Arabic digit 5\r\n\t'\\u06F6': '6', // Eastern-Arabic digit 6\r\n\t'\\u06F7': '7', // Eastern-Arabic digit 7\r\n\t'\\u06F8': '8', // Eastern-Arabic digit 8\r\n\t'\\u06F9': '9' // Eastern-Arabic digit 9\r\n}\r\n\r\nexport function parseDigit(character) {\r\n\treturn DIGITS[character]\r\n}\r\n\r\n/**\r\n * Parses phone number digits from a string.\r\n * Drops all punctuation leaving only digits.\r\n * Also converts wide-ascii and arabic-indic numerals to conventional numerals.\r\n * E.g. in Iraq they don't write `+442323234` but rather `+٤٤٢٣٢٣٢٣٤`.\r\n * @param {string} string\r\n * @return {string}\r\n * @example\r\n * ```js\r\n * parseDigits('8 (800) 555')\r\n * // Outputs '8800555'.\r\n * ```\r\n */\r\nexport default function parseDigits(string) {\r\n\tlet result = ''\r\n\t// Using `.split('')` here instead of normal `for ... of`\r\n\t// because the importing application doesn't neccessarily include an ES6 polyfill.\r\n\t// The `.split('')` approach discards \"exotic\" UTF-8 characters\r\n\t// (the ones consisting of four bytes) but digits\r\n\t// (including non-European ones) don't fall into that range\r\n\t// so such \"exotic\" characters would be discarded anyway.\r\n\tfor (const character of string.split('')) {\r\n\t\tconst digit = parseDigit(character)\r\n\t\tif (digit) {\r\n\t\t\tresult += digit\r\n\t\t}\r\n\t}\r\n\treturn result\r\n}"],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,MAAM,GAAG;EACrB,KAAK,GADgB;EAErB,KAAK,GAFgB;EAGrB,KAAK,GAHgB;EAIrB,KAAK,GAJgB;EAKrB,KAAK,GALgB;EAMrB,KAAK,GANgB;EAOrB,KAAK,GAPgB;EAQrB,KAAK,GARgB;EASrB,KAAK,GATgB;EAUrB,KAAK,GAVgB;EAWrB,UAAU,GAXW;EAWN;EACf,UAAU,GAZW;EAYN;EACf,UAAU,GAbW;EAaN;EACf,UAAU,GAdW;EAcN;EACf,UAAU,GAfW;EAeN;EACf,UAAU,GAhBW;EAgBN;EACf,UAAU,GAjBW;EAiBN;EACf,UAAU,GAlBW;EAkBN;EACf,UAAU,GAnBW;EAmBN;EACf,UAAU,GApBW;EAoBN;EACf,UAAU,GArBW;EAqBN;EACf,UAAU,GAtBW;EAsBN;EACf,UAAU,GAvBW;EAuBN;EACf,UAAU,GAxBW;EAwBN;EACf,UAAU,GAzBW;EAyBN;EACf,UAAU,GA1BW;EA0BN;EACf,UAAU,GA3BW;EA2BN;EACf,UAAU,GA5BW;EA4BN;EACf,UAAU,GA7BW;EA6BN;EACf,UAAU,GA9BW;EA8BN;EACf,UAAU,GA/BW;EA+BN;EACf,UAAU,GAhCW;EAgCN;EACf,UAAU,GAjCW;EAiCN;EACf,UAAU,GAlCW;EAkCN;EACf,UAAU,GAnCW;EAmCN;EACf,UAAU,GApCW;EAoCN;EACf,UAAU,GArCW;EAqCN;EACf,UAAU,GAtCW;EAsCN;EACf,UAAU,GAvCW;EAuCN;EACf,UAAU,GAxCW,CAwCN;;AAxCM,CAAf;;;AA2CA,SAASC,UAAT,CAAoBC,SAApB,EAA+B;EACrC,OAAOF,MAAM,CAACE,SAAD,CAAb;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASC,WAAT,CAAqBC,MAArB,EAA6B;EAC3C,IAAIC,MAAM,GAAG,EAAb,CAD2C,CAE3C;EACA;EACA;EACA;EACA;EACA;;EACA,qDAAwBD,MAAM,CAACE,KAAP,CAAa,EAAb,CAAxB,wCAA0C;IAAA,IAA/BJ,SAA+B;IACzC,IAAMK,KAAK,GAAGN,UAAU,CAACC,SAAD,CAAxB;;IACA,IAAIK,KAAJ,EAAW;MACVF,MAAM,IAAIE,KAAV;IACA;EACD;;EACD,OAAOF,MAAP;AACA"}

View File

@@ -0,0 +1,12 @@
"use strict";
var _parseDigits = _interopRequireDefault(require("./parseDigits.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
describe('parseDigits', function () {
it('should parse digits', function () {
(0, _parseDigits["default"])('+٤٤٢٣٢٣٢٣٤').should.equal('442323234');
});
});
//# sourceMappingURL=parseDigits.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"parseDigits.test.js","names":["describe","it","parseDigits","should","equal"],"sources":["../../source/helpers/parseDigits.test.js"],"sourcesContent":["import parseDigits from './parseDigits.js'\r\n\r\ndescribe('parseDigits', () => {\r\n\tit('should parse digits', () => {\r\n\t\tparseDigits('+٤٤٢٣٢٣٢٣٤').should.equal('442323234')\r\n\t})\r\n})"],"mappings":";;AAAA;;;;AAEAA,QAAQ,CAAC,aAAD,EAAgB,YAAM;EAC7BC,EAAE,CAAC,qBAAD,EAAwB,YAAM;IAC/B,IAAAC,uBAAA,EAAY,YAAZ,EAA0BC,MAA1B,CAAiCC,KAAjC,CAAuC,WAAvC;EACA,CAFC,CAAF;AAGA,CAJO,CAAR"}

View File

@@ -0,0 +1,46 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = stripIddPrefix;
var _metadata = _interopRequireDefault(require("../metadata.js"));
var _constants = require("../constants.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var CAPTURING_DIGIT_PATTERN = new RegExp('([' + _constants.VALID_DIGITS + '])');
function stripIddPrefix(number, country, callingCode, metadata) {
if (!country) {
return;
} // Check if the number is IDD-prefixed.
var countryMetadata = new _metadata["default"](metadata);
countryMetadata.selectNumberingPlan(country, callingCode);
var IDDPrefixPattern = new RegExp(countryMetadata.IDDPrefix());
if (number.search(IDDPrefixPattern) !== 0) {
return;
} // Strip IDD prefix.
number = number.slice(number.match(IDDPrefixPattern)[0].length); // If there're any digits after an IDD prefix,
// then those digits are a country calling code.
// Since no country code starts with a `0`,
// the code below validates that the next digit (if present) is not `0`.
var matchedGroups = number.match(CAPTURING_DIGIT_PATTERN);
if (matchedGroups && matchedGroups[1] != null && matchedGroups[1].length > 0) {
if (matchedGroups[1] === '0') {
return;
}
}
return number;
}
//# sourceMappingURL=stripIddPrefix.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"stripIddPrefix.js","names":["CAPTURING_DIGIT_PATTERN","RegExp","VALID_DIGITS","stripIddPrefix","number","country","callingCode","metadata","countryMetadata","Metadata","selectNumberingPlan","IDDPrefixPattern","IDDPrefix","search","slice","match","length","matchedGroups"],"sources":["../../source/helpers/stripIddPrefix.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport { VALID_DIGITS } from '../constants.js'\r\n\r\nconst CAPTURING_DIGIT_PATTERN = new RegExp('([' + VALID_DIGITS + '])')\r\n\r\nexport default function stripIddPrefix(number, country, callingCode, metadata) {\r\n\tif (!country) {\r\n\t\treturn\r\n\t}\r\n\t// Check if the number is IDD-prefixed.\r\n\tconst countryMetadata = new Metadata(metadata)\r\n\tcountryMetadata.selectNumberingPlan(country, callingCode)\r\n\tconst IDDPrefixPattern = new RegExp(countryMetadata.IDDPrefix())\r\n\tif (number.search(IDDPrefixPattern) !== 0) {\r\n\t\treturn\r\n\t}\r\n\t// Strip IDD prefix.\r\n\tnumber = number.slice(number.match(IDDPrefixPattern)[0].length)\r\n\t// If there're any digits after an IDD prefix,\r\n\t// then those digits are a country calling code.\r\n\t// Since no country code starts with a `0`,\r\n\t// the code below validates that the next digit (if present) is not `0`.\r\n\tconst matchedGroups = number.match(CAPTURING_DIGIT_PATTERN)\r\n\tif (matchedGroups && matchedGroups[1] != null && matchedGroups[1].length > 0) {\r\n\t\tif (matchedGroups[1] === '0') {\r\n\t\t\treturn\r\n\t\t}\r\n\t}\r\n\treturn number\r\n}"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA,IAAMA,uBAAuB,GAAG,IAAIC,MAAJ,CAAW,OAAOC,uBAAP,GAAsB,IAAjC,CAAhC;;AAEe,SAASC,cAAT,CAAwBC,MAAxB,EAAgCC,OAAhC,EAAyCC,WAAzC,EAAsDC,QAAtD,EAAgE;EAC9E,IAAI,CAACF,OAAL,EAAc;IACb;EACA,CAH6E,CAI9E;;;EACA,IAAMG,eAAe,GAAG,IAAIC,oBAAJ,CAAaF,QAAb,CAAxB;EACAC,eAAe,CAACE,mBAAhB,CAAoCL,OAApC,EAA6CC,WAA7C;EACA,IAAMK,gBAAgB,GAAG,IAAIV,MAAJ,CAAWO,eAAe,CAACI,SAAhB,EAAX,CAAzB;;EACA,IAAIR,MAAM,CAACS,MAAP,CAAcF,gBAAd,MAAoC,CAAxC,EAA2C;IAC1C;EACA,CAV6E,CAW9E;;;EACAP,MAAM,GAAGA,MAAM,CAACU,KAAP,CAAaV,MAAM,CAACW,KAAP,CAAaJ,gBAAb,EAA+B,CAA/B,EAAkCK,MAA/C,CAAT,CAZ8E,CAa9E;EACA;EACA;EACA;;EACA,IAAMC,aAAa,GAAGb,MAAM,CAACW,KAAP,CAAaf,uBAAb,CAAtB;;EACA,IAAIiB,aAAa,IAAIA,aAAa,CAAC,CAAD,CAAb,IAAoB,IAArC,IAA6CA,aAAa,CAAC,CAAD,CAAb,CAAiBD,MAAjB,GAA0B,CAA3E,EAA8E;IAC7E,IAAIC,aAAa,CAAC,CAAD,CAAb,KAAqB,GAAzB,EAA8B;MAC7B;IACA;EACD;;EACD,OAAOb,MAAP;AACA"}

View File

@@ -0,0 +1,23 @@
"use strict";
var _stripIddPrefix = _interopRequireDefault(require("./stripIddPrefix.js"));
var _metadataMin = _interopRequireDefault(require("../../metadata.min.json"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
describe('stripIddPrefix', function () {
it('should strip a valid IDD prefix', function () {
(0, _stripIddPrefix["default"])('01178005553535', 'US', '1', _metadataMin["default"]).should.equal('78005553535');
});
it('should strip a valid IDD prefix (no country calling code)', function () {
(0, _stripIddPrefix["default"])('011', 'US', '1', _metadataMin["default"]).should.equal('');
});
it('should strip a valid IDD prefix (valid country calling code)', function () {
(0, _stripIddPrefix["default"])('0117', 'US', '1', _metadataMin["default"]).should.equal('7');
});
it('should strip a valid IDD prefix (not a valid country calling code)', function () {
expect((0, _stripIddPrefix["default"])('0110', 'US', '1', _metadataMin["default"])).to.be.undefined;
});
});
//# sourceMappingURL=stripIddPrefix.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"stripIddPrefix.test.js","names":["describe","it","stripIddPrefix","metadata","should","equal","expect","to","be","undefined"],"sources":["../../source/helpers/stripIddPrefix.test.js"],"sourcesContent":["import stripIddPrefix from './stripIddPrefix.js'\r\n\r\nimport metadata from '../../metadata.min.json' assert { type: 'json' }\r\n\r\ndescribe('stripIddPrefix', () => {\r\n\tit('should strip a valid IDD prefix', () => {\r\n\t\tstripIddPrefix('01178005553535', 'US', '1', metadata).should.equal('78005553535')\r\n\t})\r\n\r\n\tit('should strip a valid IDD prefix (no country calling code)', () => {\r\n\t\tstripIddPrefix('011', 'US', '1', metadata).should.equal('')\r\n\t})\r\n\r\n\tit('should strip a valid IDD prefix (valid country calling code)', () => {\r\n\t\tstripIddPrefix('0117', 'US', '1', metadata).should.equal('7')\r\n\t})\r\n\r\n\tit('should strip a valid IDD prefix (not a valid country calling code)', () => {\r\n\t\texpect(stripIddPrefix('0110', 'US', '1', metadata)).to.be.undefined\r\n\t})\r\n})"],"mappings":";;AAAA;;AAEA;;;;AAEAA,QAAQ,CAAC,gBAAD,EAAmB,YAAM;EAChCC,EAAE,CAAC,iCAAD,EAAoC,YAAM;IAC3C,IAAAC,0BAAA,EAAe,gBAAf,EAAiC,IAAjC,EAAuC,GAAvC,EAA4CC,uBAA5C,EAAsDC,MAAtD,CAA6DC,KAA7D,CAAmE,aAAnE;EACA,CAFC,CAAF;EAIAJ,EAAE,CAAC,2DAAD,EAA8D,YAAM;IACrE,IAAAC,0BAAA,EAAe,KAAf,EAAsB,IAAtB,EAA4B,GAA5B,EAAiCC,uBAAjC,EAA2CC,MAA3C,CAAkDC,KAAlD,CAAwD,EAAxD;EACA,CAFC,CAAF;EAIAJ,EAAE,CAAC,8DAAD,EAAiE,YAAM;IACxE,IAAAC,0BAAA,EAAe,MAAf,EAAuB,IAAvB,EAA6B,GAA7B,EAAkCC,uBAAlC,EAA4CC,MAA5C,CAAmDC,KAAnD,CAAyD,GAAzD;EACA,CAFC,CAAF;EAIAJ,EAAE,CAAC,oEAAD,EAAuE,YAAM;IAC9EK,MAAM,CAAC,IAAAJ,0BAAA,EAAe,MAAf,EAAuB,IAAvB,EAA6B,GAA7B,EAAkCC,uBAAlC,CAAD,CAAN,CAAoDI,EAApD,CAAuDC,EAAvD,CAA0DC,SAA1D;EACA,CAFC,CAAF;AAGA,CAhBO,CAAR"}