UNPKG

libphonenumber-js

Version:

A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript

914 lines (834 loc) 71.3 kB
"use strict"; var _mocha = require("mocha"); var _chai = require("chai"); var _metadataMin = _interopRequireDefault(require("../metadata.min.json")); var _AsYouType = _interopRequireDefault(require("./AsYouType.js")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } var AsYouType = /*#__PURE__*/function (_AsYouType_) { function AsYouType(country_code) { _classCallCheck(this, AsYouType); return _callSuper(this, AsYouType, [country_code, _metadataMin["default"]]); } _inherits(AsYouType, _AsYouType_); return _createClass(AsYouType); }(_AsYouType["default"]); var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false; (0, _mocha.describe)('AsYouType', function () { (0, _mocha.it)('should use "national_prefix_formatting_rule"', function () { // With national prefix (full). (0, _chai.expect)(new AsYouType('RU').input('88005553535')).to.equal('8 (800) 555-35-35'); // With national prefix (partial). (0, _chai.expect)(new AsYouType('RU').input('880055535')).to.equal('8 (800) 555-35'); }); (0, _mocha.it)('should populate national number template (digit by digit)', function () { var formatter = new AsYouType('US'); formatter.input('1'); // formatter.formatter.template.should.equal('x (xxx) xxx-xxxx') (0, _chai.expect)(formatter.formatter.template).to.equal('x xxx-xxxx'); // formatter.formatter.populatedNationalNumberTemplate.should.equal('1 (xxx) xxx-xxxx') (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.equal('1 xxx-xxxx'); formatter.input('213'); (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.equal('1 (213) xxx-xxxx'); formatter.input('3734253'); (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.equal('1 (213) 373-4253'); }); (0, _mocha.it)('should populate international number template (digit by digit) (default country)', function () { var formatter = new AsYouType('US'); (0, _chai.expect)(formatter.formatter.template).to.be.undefined; (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined; (0, _chai.expect)(formatter.input('')).to.equal(''); (0, _chai.expect)(formatter.formatter.template).to.be.undefined; (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined; (0, _chai.expect)(formatter.input('+')).to.equal('+'); (0, _chai.expect)(formatter.getTemplate()).to.equal('x'); (0, _chai.expect)(formatter.formatter.template).to.be.undefined; (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined; (0, _chai.expect)(formatter.input('1')).to.equal('+1'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xx'); // Hasn't started formatting the phone number using the template yet. // formatter.formatter.template.should.equal('xx xxx xxx xxxx') (0, _chai.expect)(formatter.formatter.template).to.equal('xx xxx xxxx'); // formatter.formatter.populatedNationalNumberTemplate.should.equal('xxx xxx xxxx') (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.equal('xxx xxxx'); // Has some national number digits, starts formatting the phone number using the template. formatter.input('213'); (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.equal('213 xxx xxxx'); formatter.input('3734253'); (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.equal('213 373 4253'); }); (0, _mocha.it)('should populate international number template (digit by digit)', function () { var formatter = new AsYouType(); (0, _chai.expect)(formatter.formatter.template).to.be.undefined; (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined; (0, _chai.expect)(formatter.input('')).to.equal(''); (0, _chai.expect)(formatter.formatter.template).to.be.undefined; (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined; (0, _chai.expect)(formatter.input('+')).to.equal('+'); (0, _chai.expect)(formatter.formatter.template).to.be.undefined; (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined; (0, _chai.expect)(formatter.input('1')).to.equal('+1'); // formatter.formatter.template.should.equal('xx xxx xxx xxxx') (0, _chai.expect)(formatter.formatter.template).to.equal('xx xxx xxxx'); // Hasn't yet started formatting the phone number using the template. // formatter.formatter.populatedNationalNumberTemplate.should.equal('xxx xxx xxxx') (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.equal('xxx xxxx'); // Has some national number digits, starts formatting the phone number using the template. formatter.input('213'); (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.equal('213 xxx xxxx'); formatter.input('3734253'); (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.equal('213 373 4253'); }); (0, _mocha.it)('should populate national number template (attempt to format complete number)', function () { var formatter = new AsYouType('US'); (0, _chai.expect)(formatter.input('12133734253')).to.equal('1 (213) 373-4253'); (0, _chai.expect)(formatter.formatter.template).to.equal('x (xxx) xxx-xxxx'); (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.equal('1 (213) 373-4253'); }); (0, _mocha.it)('should parse and format phone numbers as you type', function () { // International number test (0, _chai.expect)(new AsYouType().input('+12133734')).to.equal('+1 213 373 4'); // Local number test (0, _chai.expect)(new AsYouType('US').input('2133734')).to.equal('(213) 373-4'); // US national number retains national prefix. (0, _chai.expect)(new AsYouType('US').input('12133734')).to.equal('1 (213) 373-4'); // US national number retains national prefix (full number). (0, _chai.expect)(new AsYouType('US').input('12133734253')).to.equal('1 (213) 373-4253'); var formatter; // // Should discard national prefix from a "complete" phone number. // new AsYouType('RU').input('8800555353').should.equal('880 055-53-53') // Shouldn't extract national prefix when inputting in international format. (0, _chai.expect)(new AsYouType('RU').input('+7800555353')).to.equal('+7 800 555 35 3'); (0, _chai.expect)(new AsYouType('CH').input('044-668-1')).to.equal('044 668 1'); // Test International phone number (international) formatter = new AsYouType(); // formatter.valid.should.be.false (0, _chai.expect)(type(formatter.getCountry())).to.equal('undefined'); (0, _chai.expect)(type(formatter.getCountryCallingCode())).to.equal('undefined'); (0, _chai.expect)(formatter.getTemplate()).to.equal(''); (0, _chai.expect)(formatter.input('+')).to.equal('+'); // formatter.valid.should.be.false (0, _chai.expect)(type(formatter.getCountry())).to.equal('undefined'); (0, _chai.expect)(type(formatter.getCountryCallingCode())).to.equal('undefined'); (0, _chai.expect)(formatter.getTemplate()).to.equal('x'); (0, _chai.expect)(formatter.input('1')).to.equal('+1'); // formatter.valid.should.be.false (0, _chai.expect)(type(formatter.getCountry())).to.equal('undefined'); (0, _chai.expect)(formatter.getCountryCallingCode()).to.equal('1'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xx'); (0, _chai.expect)(formatter.input('2')).to.equal('+1 2'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xx x'); // formatter.valid.should.be.false (0, _chai.expect)(type(formatter.getCountry())).to.equal('undefined'); (0, _chai.expect)(formatter.input('1')).to.equal('+1 21'); (0, _chai.expect)(formatter.input('3')).to.equal('+1 213'); (0, _chai.expect)(formatter.input(' ')).to.equal('+1 213'); (0, _chai.expect)(formatter.input('3')).to.equal('+1 213 3'); (0, _chai.expect)(formatter.input('3')).to.equal('+1 213 33'); (0, _chai.expect)(formatter.input('3')).to.equal('+1 213 333'); (0, _chai.expect)(formatter.input('4')).to.equal('+1 213 333 4'); (0, _chai.expect)(formatter.input('4')).to.equal('+1 213 333 44'); (0, _chai.expect)(formatter.input('4')).to.equal('+1 213 333 444'); // formatter.valid.should.be.false (0, _chai.expect)(type(formatter.getCountry())).to.equal('undefined'); (0, _chai.expect)(formatter.input('4')).to.equal('+1 213 333 4444'); // formatter.valid.should.be.true (0, _chai.expect)(formatter.getCountry()).to.equal('US'); // This one below contains "punctuation spaces" // along with the regular spaces (0, _chai.expect)(formatter.getTemplate()).to.equal('xx xxx xxx xxxx'); (0, _chai.expect)(formatter.input('5')).to.equal('+1 21333344445'); // formatter.valid.should.be.false (0, _chai.expect)(formatter.getCountry()).to.be.undefined; (0, _chai.expect)(formatter.getCountryCallingCode()).to.equal('1'); (0, _chai.expect)(formatter.formatter.template).to.be.undefined; // Check that clearing an international formatter // also clears country metadata. formatter.reset(); (0, _chai.expect)(formatter.input('+')).to.equal('+'); (0, _chai.expect)(formatter.input('7')).to.equal('+7'); (0, _chai.expect)(formatter.input('9')).to.equal('+7 9'); (0, _chai.expect)(formatter.input('99 111 22 33')).to.equal('+7 999 111 22 33'); // Test Switzerland phone numbers formatter = new AsYouType('CH'); (0, _chai.expect)(formatter.input(' ')).to.equal(''); (0, _chai.expect)(formatter.input('0')).to.equal('0'); (0, _chai.expect)(formatter.input('4')).to.equal('04'); (0, _chai.expect)(formatter.input(' ')).to.equal('04'); (0, _chai.expect)(formatter.input('-')).to.equal('04'); (0, _chai.expect)(formatter.input('4')).to.equal('044'); (0, _chai.expect)(formatter.input('-')).to.equal('044'); (0, _chai.expect)(formatter.input('6')).to.equal('044 6'); (0, _chai.expect)(formatter.input('6')).to.equal('044 66'); (0, _chai.expect)(formatter.input('8')).to.equal('044 668'); (0, _chai.expect)(formatter.input('-')).to.equal('044 668'); (0, _chai.expect)(formatter.input('1')).to.equal('044 668 1'); (0, _chai.expect)(formatter.input('8')).to.equal('044 668 18'); // formatter.valid.should.be.false (0, _chai.expect)(formatter.getCountry()).to.equal('CH'); (0, _chai.expect)(formatter.formatter.template).to.equal('xxx xxx xx xx'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxx xxx xx'); (0, _chai.expect)(formatter.input(' 00')).to.equal('044 668 18 00'); // formatter.valid.should.be.true (0, _chai.expect)(formatter.getCountry()).to.equal('CH'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxx xxx xx xx'); (0, _chai.expect)(formatter.input('9')).to.equal('04466818009'); // formatter.valid.should.be.false (0, _chai.expect)(formatter.getCountry()).to.equal('CH'); (0, _chai.expect)(formatter.formatter.template).to.be.undefined; // Kazakhstan (non-main country for +7 country phone code) formatter = new AsYouType(); formatter.input('+77172580659'); (0, _chai.expect)(formatter.getCountry()).to.equal('KZ'); // Brazil formatter = new AsYouType('BR'); (0, _chai.expect)(formatter.input('11987654321')).to.equal('(11) 98765-4321'); // UK (Jersey) (non-main country for +44 country phone code) formatter = new AsYouType(); (0, _chai.expect)(formatter.input('+447700300000')).to.equal('+44 7700 300000'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxx xxxx xxxxxx'); (0, _chai.expect)(formatter.getCountry()).to.equal('JE'); // Braces must be part of the template. formatter = new AsYouType('RU'); (0, _chai.expect)(formatter.input('88005553535')).to.equal('8 (800) 555-35-35'); (0, _chai.expect)(formatter.getTemplate()).to.equal('x (xxx) xxx-xx-xx'); // Test Russian phone numbers // (with optional national prefix `8`) formatter = new AsYouType('RU'); (0, _chai.expect)(formatter.input('8')).to.equal('8'); (0, _chai.expect)(formatter.input('9')).to.equal('8 9'); (0, _chai.expect)(formatter.input('9')).to.equal('8 99'); (0, _chai.expect)(formatter.input('9')).to.equal('8 (999)'); (0, _chai.expect)(formatter.input('-')).to.equal('8 (999)'); (0, _chai.expect)(formatter.input('1234')).to.equal('8 (999) 123-4'); (0, _chai.expect)(formatter.input('567')).to.equal('8 (999) 123-45-67'); (0, _chai.expect)(formatter.input('8')).to.equal('899912345678'); // Shouldn't strip national prefix if it is optional // and if it's a valid phone number (international). formatter = new AsYouType('RU'); // formatter.input('8005553535').should.equal('(800) 555-35-35') (0, _chai.expect)(formatter.input('+78005553535')).to.equal('+7 800 555 35 35'); (0, _chai.expect)(formatter.getNationalNumber()).to.equal('8005553535'); // Check that clearing an national formatter: // * doesn't clear country metadata // * clears all other things formatter.reset(); (0, _chai.expect)(formatter.input('8')).to.equal('8'); (0, _chai.expect)(formatter.input('9')).to.equal('8 9'); (0, _chai.expect)(formatter.input('9')).to.equal('8 99'); (0, _chai.expect)(formatter.input('9')).to.equal('8 (999)'); (0, _chai.expect)(formatter.input('-')).to.equal('8 (999)'); (0, _chai.expect)(formatter.input('1234')).to.equal('8 (999) 123-4'); (0, _chai.expect)(formatter.input('567')).to.equal('8 (999) 123-45-67'); (0, _chai.expect)(formatter.input('8')).to.equal('899912345678'); // National prefix should not be prepended // when formatting local NANPA phone numbers. (0, _chai.expect)(new AsYouType('US').input('1')).to.equal('1'); (0, _chai.expect)(new AsYouType('US').input('12')).to.equal('1 2'); (0, _chai.expect)(new AsYouType('US').input('123')).to.equal('1 23'); // Bulgaria // (should not prepend national prefix `0`) (0, _chai.expect)(new AsYouType('BG').input('111 222 3')).to.equal('1112223'); // Deutchland (0, _chai.expect)(new AsYouType().input('+4915539898001')).to.equal('+49 15539 898001'); // KZ detection formatter = new AsYouType(); formatter.input('+7 702 211 1111'); (0, _chai.expect)(formatter.getCountry()).to.equal('KZ'); // formatter.valid.should.equal(true) // New Zealand formatting fix (issue #89) (0, _chai.expect)(new AsYouType('NZ').input('0212')).to.equal('021 2'); // South Korea formatter = new AsYouType(); (0, _chai.expect)(formatter.input('+82111111111')).to.equal('+82 11 111 1111'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxx xx xxx xxxx'); }); (0, _mocha.it)('should filter out formats that require a national prefix and no national prefix has been input', function () { // Afghanistan. var formatter = new AsYouType('AF'); // No national prefix, and national prefix is required in the format. // (not `"national_prefix_is_optional_when_formatting": true`) (0, _chai.expect)(formatter.input('44444444')).to.equal('44444444'); (0, _chai.expect)(formatter.formatter.template).to.be.undefined; // With national prefix (0, _chai.expect)(formatter.reset().input('044444444')).to.equal('044 444 444'); (0, _chai.expect)(formatter.formatter.template).to.equal('xxx xxx xxxx'); }); (0, _mocha.it)('should work when a digit is not a national prefix but a part of a valid national number', function () { // In Russia, `8` could be both a valid national prefix // and a part of a valid national number. var formatter = new AsYouType('RU'); // The formatter could try both variants: // with extracting national prefix // and without extracting it, // and then choose whichever way has `this.matchingFormats`. // Or there could be two instances of the formatter: // one that extracts national prefix and one that doesn't, // and then the one that has `this.matchingFormats` would be // used to format the phone number. // Something like an option `extractNationalPrefix: false` // and creating `this.withNationalPrefixFormatter = new AsYouType(this.defaultCountry || this.defaultCallingCode, { metadata, extractNationalPrefix: false })` // and something like `this.withNationalPrefixFormatter.input(nextDigits)` in `input(nextDigits)`. // But, for this specific case, it's not required: // in Russia, people are used to inputting `800` numbers with national prefix `8`: // `8 800 555 35 35`. // formatter.input('8005553535').should.equal('(800) 555-35-35') (0, _chai.expect)(formatter.input('8005553535')).to.equal('8005553535'); formatter.reset(); (0, _chai.expect)(formatter.input('+78005553535')).to.equal('+7 800 555 35 35'); }); (0, _mocha.it)('should match formats that require a national prefix and no national prefix has been input (national prefix is mandatory for a format)', function () { var formatter = new AsYouType('FR'); (0, _chai.expect)(formatter.input('612345678')).to.equal('612345678'); formatter.reset(); (0, _chai.expect)(formatter.input('0612345678')).to.equal('06 12 34 56 78'); }); (0, _mocha.it)('should match formats that require a national prefix and no national prefix has been input (national prefix is not mandatory for a format)', function () { var formatter = new AsYouType('RU'); // Without national prefix. (0, _chai.expect)(formatter.input('9991234567')).to.equal('999 123-45-67'); formatter.reset(); // With national prefix. (0, _chai.expect)(formatter.input('89991234567')).to.equal('8 (999) 123-45-67'); }); (0, _mocha.it)('should not use `national_prefix_formatting_rule` when formatting international phone numbers', function () { // Brazil. // `national_prefix_formatting_rule` is `($1)`. // Should not add braces around `12` when being input in international format. (0, _chai.expect)(new AsYouType().input('+55123456789')).to.equal('+55 12 3456 789'); (0, _chai.expect)(new AsYouType('BR').input('+55123456789')).to.equal('+55 12 3456 789'); (0, _chai.expect)(new AsYouType('BR').input('123456789')).to.equal('(12) 3456-789'); }); (0, _mocha.it)('should support incorrectly entered international phone numbers (with a national prefix)', function () { var formatter; formatter = new AsYouType(); (0, _chai.expect)(formatter.input('+1 1 877 215 5230')).to.equal('+1 1 877 215 5230'); // formatter.input('+1 1 877 215 5230').should.equal('+1 1 8772155230') (0, _chai.expect)(formatter.getNationalNumber()).to.equal('8772155230'); // They've added another number format that has `8` leading digit // and 14 digits. Maybe it's something related to Kazakhstan. // formatter = new AsYouType() // formatter.input('+78800555353').should.equal('+7 880 055 53 53') // formatter.input('5').should.equal('+7 8 800 555 35 35') // formatter.getNationalNumber().should.equal('8005553535') }); (0, _mocha.it)('should return a partial template for current value', function () { var asYouType = new AsYouType('US'); (0, _chai.expect)(asYouType.input('')).to.equal(''); (0, _chai.expect)(asYouType.getTemplate()).to.equal(''); (0, _chai.expect)(asYouType.input('2')).to.equal('2'); // asYouType.getTemplate().should.equal('x') // Doesn't format for a single digit. (0, _chai.expect)(asYouType.getTemplate()).to.equal('x'); (0, _chai.expect)(asYouType.input('1')).to.equal('21'); (0, _chai.expect)(asYouType.getTemplate()).to.equal('xx'); (0, _chai.expect)(asYouType.input('3')).to.equal('(213)'); (0, _chai.expect)(asYouType.getTemplate()).to.equal('(xxx)'); }); (0, _mocha.it)("should fall back to the default country", function () { var formatter = new AsYouType('RU'); (0, _chai.expect)(formatter.input('8')).to.equal('8'); (0, _chai.expect)(formatter.input('9')).to.equal('8 9'); (0, _chai.expect)(formatter.input('9')).to.equal('8 99'); (0, _chai.expect)(formatter.input('9')).to.equal('8 (999)'); // formatter.valid.should.be.false (0, _chai.expect)(formatter.formatter.template).to.equal('x (xxx) xxx-xx-xx'); (0, _chai.expect)(formatter.getCountry()).to.equal('RU'); // formatter.getCountryCallingCode().should.equal('7') (0, _chai.expect)(formatter.input('000000000000')).to.equal('8999000000000000'); // formatter.valid.should.be.false (0, _chai.expect)(formatter.formatter.template).to.be.undefined; (0, _chai.expect)(formatter.getCountry()).to.equal('RU'); // formatter.getCountryCallingCode().should.equal('7') formatter.reset(); // formatter.valid.should.be.false (0, _chai.expect)(formatter.formatter.template).to.be.undefined; (0, _chai.expect)(formatter.getCountry()).to.be.undefined; // formatter.getCountryCallingCode().should.equal('7') (0, _chai.expect)(formatter.input('+1-213-373-4253')).to.equal('+1 213 373 4253'); // formatter.valid.should.be.true (0, _chai.expect)(formatter.getTemplate()).to.equal('xx xxx xxx xxxx'); (0, _chai.expect)(formatter.getCountry()).to.equal('US'); (0, _chai.expect)(formatter.getCountryCallingCode()).to.equal('1'); }); (0, _mocha.it)('should work in edge cases', function () { var formatter; var thrower; // No metadata thrower = function thrower() { return new _AsYouType["default"]('RU'); }; (0, _chai.expect)(thrower).to["throw"]('`metadata` argument not passed'); // Second '+' sign formatter = new AsYouType('RU'); (0, _chai.expect)(formatter.input('+')).to.equal('+'); (0, _chai.expect)(formatter.input('7')).to.equal('+7'); (0, _chai.expect)(formatter.input('+')).to.equal('+7'); // Out-of-position '+' sign formatter = new AsYouType('RU'); (0, _chai.expect)(formatter.input('8')).to.equal('8'); (0, _chai.expect)(formatter.input('+')).to.equal('8'); // No format matched formatter = new AsYouType('RU'); (0, _chai.expect)(formatter.input('88005553535')).to.equal('8 (800) 555-35-35'); (0, _chai.expect)(formatter.input('0')).to.equal('880055535350'); // Invalid country phone code formatter = new AsYouType(); (0, _chai.expect)(formatter.input('+0123')).to.equal('+0123'); // No country specified and not an international number formatter = new AsYouType(); (0, _chai.expect)(formatter.input('88005553535')).to.equal('88005553535'); // Extract national prefix when no `national_prefix` is set formatter = new AsYouType('AD'); (0, _chai.expect)(formatter.input('155555')).to.equal('155 555'); // Typing nonsense formatter = new AsYouType('RU'); (0, _chai.expect)(formatter.input('+1abc2')).to.equal('+1'); // Should reset default country when explicitly // typing in an international phone number formatter = new AsYouType('RU'); formatter.input('+'); (0, _chai.expect)(type(formatter.getCountry())).to.equal('undefined'); (0, _chai.expect)(type(formatter.getCountryCallingCode())).to.equal('undefined'); // Country not inferrable from the phone number, // while the phone number itself can already be formatted "completely". formatter = new AsYouType(); formatter.input('+12223333333'); (0, _chai.expect)(type(formatter.getCountry())).to.equal('undefined'); (0, _chai.expect)(formatter.getCountryCallingCode()).to.equal('1'); // Reset a chosen format when it no longer applies given the new leading digits. // If Google changes metadata for England then this test might not cover the case. formatter = new AsYouType('GB'); (0, _chai.expect)(formatter.input('0845')).to.equal('0845'); // New leading digits don't match the format previously chosen. // Reset the format. (0, _chai.expect)(formatter.input('0')).to.equal('0845 0'); }); (0, _mocha.it)('should choose between matching formats based on the absence or presence of a national prefix', function () { // The first matching format: // { // "pattern": "(\\d{2})(\\d{5,6})", // "leading_digits_patterns": [ // "(?:10|2[0-57-9])[19]", // "(?:10|2[0-57-9])(?:10|9[56])", // "(?:10|2[0-57-9])(?:100|9[56])" // ], // "national_prefix_formatting_rule": "0$1", // "format": "$1 $2", // "domestic_carrier_code_formatting_rule": "$CC $FG" // } // // The second matching format: // { // "pattern": "(\\d{2})(\\d{4})(\\d{4})", // "leading_digits_patterns": [ // "10|2(?:[02-57-9]|1[1-9])", // "10|2(?:[02-57-9]|1[1-9])", // "10[0-79]|2(?:[02-57-9]|1[1-79])|(?:10|21)8(?:0[1-9]|[1-9])" // ], // "national_prefix_formatting_rule": "0$1", // "national_prefix_is_optional_when_formatting": true, // "format": "$1 $2 $3", // "domestic_carrier_code_formatting_rule": "$CC $FG" // } // var formatter = new AsYouType('CN'); // National prefix has been input. // Chooses the first format. (0, _chai.expect)(formatter.input('01010000')).to.equal('010 10000'); formatter.reset(); // No national prefix has been input, // and `national_prefix_for_parsing` not matched. // The first format won't match, because it doesn't have // `"national_prefix_is_optional_when_formatting": true`. // The second format will match, because it does have // `"national_prefix_is_optional_when_formatting": true`. (0, _chai.expect)(formatter.input('1010000')).to.equal('10 1000 0'); }); (0, _mocha.it)('should not accept phone number extensions', function () { (0, _chai.expect)(new AsYouType().input('+1-213-373-4253 ext. 123')).to.equal('+1 213 373 4253'); }); (0, _mocha.it)('should parse non-European digits', function () { (0, _chai.expect)(new AsYouType().input('+١٢١٢٢٣٢٣٢٣٢')).to.equal('+1 212 232 3232'); }); (0, _mocha.it)('should return a PhoneNumber instance', function () { var formatter = new AsYouType('BR'); // No country calling code. (0, _chai.expect)(formatter.getNumber()).to.be.undefined; formatter.input('+1'); // No national number digits. (0, _chai.expect)(formatter.getNumber()).to.be.undefined; formatter.input('213-373-4253'); var phoneNumber = formatter.getNumber(); (0, _chai.expect)(phoneNumber.country).to.equal('US'); (0, _chai.expect)(phoneNumber.countryCallingCode).to.equal('1'); (0, _chai.expect)(phoneNumber.number).to.equal('+12133734253'); (0, _chai.expect)(phoneNumber.nationalNumber).to.equal('2133734253'); formatter.reset(); formatter.input('+1-113-373-4253'); phoneNumber = formatter.getNumber(); (0, _chai.expect)(phoneNumber.country).to.be.undefined; (0, _chai.expect)(phoneNumber.countryCallingCode).to.equal('1'); // An incorrect NANPA international phone number. // (contains national prefix in an international phone number) formatter.reset(); formatter.input('+1-1'); // Before leading digits < 3 matching was implemented: // // phoneNumber = formatter.getNumber() // expect(phoneNumber).to.not.be.undefined // // formatter.input('1') // phoneNumber = formatter.getNumber() // expect(phoneNumber.country).to.be.undefined // phoneNumber.countryCallingCode.should.equal('1') // phoneNumber.number.should.equal('+111') // After leading digits < 3 matching was implemented: // phoneNumber = formatter.getNumber(); (0, _chai.expect)(phoneNumber).to.be.undefined; // formatter.input('1'); phoneNumber = formatter.getNumber(); (0, _chai.expect)(phoneNumber.country).to.be.undefined; (0, _chai.expect)(phoneNumber.countryCallingCode).to.equal('1'); (0, _chai.expect)(phoneNumber.number).to.equal('+11'); }); (0, _mocha.it)('should work with countries that add digits to national (significant) number', function () { // When formatting Argentinian mobile numbers in international format, // a `9` is prepended, when compared to national format. var asYouType = new AsYouType('AR'); (0, _chai.expect)(asYouType.input('+5493435551212')).to.equal('+54 9 3435 55 1212'); asYouType.reset(); // Digits shouldn't be changed when formatting in national format. // (no `9` is prepended). // First parses national (significant) number by prepending `9` to it // and stripping `15` from it. // Then uses `$2 15-$3-$4` format that strips the leading `9` // and adds `15`. (0, _chai.expect)(asYouType.input('0343515551212')).to.equal('03435 15-55-1212'); }); (0, _mocha.it)('should return non-formatted phone number when no format matches and national (significant) number has digits added', function () { // When inputting "0343515551212999" Argentinian mobile number, // the parsed national (significant) number is "93435551212999". // There, one can see how it stripped "0" national prefix and prepended a "9", // because that's how it is instructed to do in Argentina's metadata. // // So in this case, national (significant) number doesn't match the input // and, therefore, `state.nationalSignificantNumberIsModified` flag is `true`. // var asYouType = new AsYouType('AR'); // This line checks that the formatter didn't alter the output digits compared to the input digits. (0, _chai.expect)(asYouType.input('0343515551212999')).to.equal('0343515551212999'); }); (0, _mocha.it)('should format Argentina numbers (starting with 011) (digit by digit)', function () { // Inputting a number digit-by-digit and as a whole a two different cases // in case of this library compared to Google's `libphonenumber` // that always inputs a number digit-by-digit. // https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/23 // nextDigits 0111523456789 // nationalNumber 91123456789 var formatter = new AsYouType('AR'); (0, _chai.expect)(formatter.input('0')).to.equal('0'); (0, _chai.expect)(formatter.getTemplate()).to.equal('x'); (0, _chai.expect)(formatter.input('1')).to.equal('01'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xx'); (0, _chai.expect)(formatter.input('1')).to.equal('011'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxx'); (0, _chai.expect)(formatter.input('1')).to.equal('011 1'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxx x'); (0, _chai.expect)(formatter.input('5')).to.equal('011 15'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxx xx'); (0, _chai.expect)(formatter.input('2')).to.equal('011 152'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxx xxx'); (0, _chai.expect)(formatter.input('3')).to.equal('011 1523'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxx xxxx'); (0, _chai.expect)(formatter.input('4')).to.equal('011 1523-4'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxx xxxx-x'); (0, _chai.expect)(formatter.input('5')).to.equal('011 1523-45'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxx xxxx-xx'); (0, _chai.expect)(formatter.input('6')).to.equal('011 1523-456'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxx xxxx-xxx'); (0, _chai.expect)(formatter.input('7')).to.equal('011 1523-4567'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxx xxxx-xxxx'); (0, _chai.expect)(formatter.input('8')).to.equal('011152345678'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxxxxxxxxxxx'); (0, _chai.expect)(formatter.input('9')).to.equal('011 15-2345-6789'); (0, _chai.expect)(formatter.getTemplate()).to.equal('xxx xx-xxxx-xxxx'); // Private property (not public API). (0, _chai.expect)(formatter.state.nationalSignificantNumber).to.equal('91123456789'); // Private property (not public API). // `formatter.digits` is not always `formatter.nationalPrefix` // plus `formatter.nationalNumberDigits`. (0, _chai.expect)(formatter.state.nationalPrefix).to.equal('0'); (0, _chai.expect)(formatter.isPossible()).to.equal(true); (0, _chai.expect)(formatter.isValid()).to.equal(true); }); (0, _mocha.it)('should format Argentina numbers (starting with 011)', function () { // Inputting a number digit-by-digit and as a whole a two different cases // in case of this library compared to Google's `libphonenumber` // that always inputs a number digit-by-digit. // https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/23 // nextDigits 0111523456789 // nationalNumber 91123456789 var formatter = new AsYouType('AR'); (0, _chai.expect)(formatter.input('0111523456789')).to.equal('011 15-2345-6789'); // Private property (not public API). (0, _chai.expect)(formatter.state.nationalSignificantNumber).to.equal('91123456789'); // Private property (not public API). // `formatter.digits` is not always `formatter.nationalPrefix` // plus `formatter.nationalNumberDigits`. (0, _chai.expect)(formatter.state.nationalPrefix).to.equal('0'); // expect(formatter.nationalPrefix).to.be.undefined (0, _chai.expect)(formatter.isPossible()).to.equal(true); (0, _chai.expect)(formatter.isValid()).to.equal(true); }); // https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/93 (0, _mocha.it)('should format Indonesian numbers', function () { var formatter = new AsYouType('ID'); (0, _chai.expect)(formatter.getChars()).to.equal(''); // Before leading digits < 3 matching was implemented: // formatter.input('081').should.equal('(081)') // After leading digits < 3 matching was implemented: (0, _chai.expect)(formatter.input('081')).to.equal('081'); }); (0, _mocha.it)('should prepend `prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix` (not a complete number)', function () { // A country having `national_prefix_for_parsing` with a "capturing group". // National prefix is either not used in a format or is optional. // Input phone number without a national prefix. var formatter = new AsYouType('AU'); (0, _chai.expect)(formatter.input('1831130345678')).to.equal('1831 1303 456 78'); // Private property (not public API). (0, _chai.expect)(formatter.state.nationalSignificantNumber).to.equal('130345678'); // Private property (not public API). // `formatter.digits` is not always `formatter.nationalPrefix` // plus `formatter.nationalNumberDigits`. (0, _chai.expect)(formatter.state.nationalPrefix).to.be.undefined; (0, _chai.expect)(formatter.state.prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix).to.equal('1831'); }); (0, _mocha.it)('should prepend `prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix` (complete number)', function () { // A country having `national_prefix_for_parsing` with a "capturing group". // National prefix is either not used in a format or is optional. // Input phone number without a national prefix. var formatter = new AsYouType('AU'); (0, _chai.expect)(formatter.input('18311303456789')).to.equal('1831 1303 456 789'); // Private property (not public API). (0, _chai.expect)(formatter.state.nationalSignificantNumber).to.equal('1303456789'); // Private property (not public API). // `formatter.digits` is not always `formatter.nationalPrefix` // plus `formatter.nationalNumberDigits`. (0, _chai.expect)(formatter.state.nationalPrefix).to.be.undefined; (0, _chai.expect)(formatter.state.prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix).to.equal('1831'); }); (0, _mocha.it)('should work with Mexico numbers', function () { var asYouType = new AsYouType('MX'); // Fixed line. International. (0, _chai.expect)(asYouType.input('+52(449)978-000')).to.equal('+52 449 978 000'); (0, _chai.expect)(asYouType.input('1')).to.equal('+52 449 978 0001'); asYouType.reset(); // "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are // no longer valid since August 2019." // // Fixed line. National. With national prefix "01". // asYouType.input('01449978000').should.equal('01449 978 000') // asYouType.getTemplate().should.equal('xxxxx xxx xxx') // asYouType.input('1').should.equal('01449 978 0001') // asYouType.getTemplate().should.equal('xxxxx xxx xxxx') // asYouType.reset() // Fixed line. National. Without national prefix. (0, _chai.expect)(asYouType.input('(449)978-000')).to.equal('449 978 000'); (0, _chai.expect)(asYouType.getTemplate()).to.equal('xxx xxx xxx'); (0, _chai.expect)(asYouType.input('1')).to.equal('449 978 0001'); (0, _chai.expect)(asYouType.getTemplate()).to.equal('xxx xxx xxxx'); asYouType.reset(); // Mobile. (0, _chai.expect)(asYouType.input('+52331234567')).to.equal('+52 33 1234 567'); (0, _chai.expect)(asYouType.input('8')).to.equal('+52 33 1234 5678'); asYouType.reset(); // "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are // no longer valid since August 2019." // // Mobile. // // With `1` prepended before area code to mobile numbers in international format. // asYouType.input('+521331234567').should.equal('+52 133 1234 567') // asYouType.getTemplate().should.equal('xxx xxx xxxx xxx') // // Google's `libphonenumber` seems to not able to format this type of number. // // https://issuetracker.google.com/issues/147938979 // asYouType.input('8').should.equal('+52 133 1234 5678') // asYouType.getTemplate().should.equal('xxx xxx xxxx xxxx') // asYouType.reset() // // // Mobile. National. With "044" prefix. // asYouType.input('044331234567').should.equal('04433 1234 567') // asYouType.input('8').should.equal('04433 1234 5678') // asYouType.reset() // // // Mobile. National. With "045" prefix. // asYouType.input('045331234567').should.equal('04533 1234 567') // asYouType.input('8').should.equal('04533 1234 5678') }); (0, _mocha.it)('should just prepend national prefix if national_prefix_formatting_rule does not produce a suitable number', function () { // "national_prefix": "8" // "national_prefix_for_parsing": "0|80?" var formatter = new AsYouType('BY'); // "national_prefix_formatting_rule": "8 $1" // That `national_prefix_formatting_rule` isn't used // because the user didn't input national prefix `8`. (0, _chai.expect)(formatter.input('0800123')).to.equal('0 800 123'); (0, _chai.expect)(formatter.getTemplate()).to.equal('x xxx xxx'); }); (0, _mocha.it)('should not duplicate area code for certain countries', function () { // https://github.com/catamphetamine/libphonenumber-js/issues/318 var asYouType = new AsYouType('VI'); // Even though `parse("3406934")` would return a // "(340) 340-6934" national number, still // "As You Type" formatter should leave it as "(340) 6934". (0, _chai.expect)(asYouType.input('340693')).to.equal('(340) 693'); (0, _chai.expect)(asYouType.input('4')).to.equal('(340) 693-4'); (0, _chai.expect)(asYouType.input('123')).to.equal('(340) 693-4123'); }); (0, _mocha.it)('shouldn\'t throw when passed a non-existent default country', function () { (0, _chai.expect)(new AsYouType('XX').input('+78005553535')).to.equal('+7 800 555 35 35'); (0, _chai.expect)(new AsYouType('XX').input('88005553535')).to.equal('88005553535'); }); (0, _mocha.it)('should parse carrier codes', function () { var formatter = new AsYouType('BR'); formatter.input('0 15 21 5555-5555'); var phoneNumber = formatter.getNumber(); (0, _chai.expect)(phoneNumber.carrierCode).to.equal('15'); formatter.reset(); formatter.input('+1-213-373-4253'); phoneNumber = formatter.getNumber(); (0, _chai.expect)(phoneNumber.carrierCode).to.be.undefined; }); (0, _mocha.it)('should format when default country calling code is configured', function () { var formatter = new AsYouType({ defaultCallingCode: '7' }); (0, _chai.expect)(formatter.input('88005553535')).to.equal('8 (800) 555-35-35'); (0, _chai.expect)(formatter.getNumber().countryCallingCode).to.equal('7'); (0, _chai.expect)(formatter.getNumber().country).to.equal('RU'); }); (0, _mocha.it)('shouldn\'t return PhoneNumber if country calling code hasn\'t been input yet', function () { var formatter = new AsYouType(); formatter.input('+80'); (0, _chai.expect)(formatter.getNumber()).to.be.undefined; }); (0, _mocha.it)('should format non-geographic numbering plan phone numbers', function () { var formatter = new AsYouType(); (0, _chai.expect)(formatter.input('+')).to.equal('+'); (0, _chai.expect)(formatter.input('8')).to.equal('+8'); (0, _chai.expect)(formatter.input('7')).to.equal('+87'); (0, _chai.expect)(formatter.getCountry()).to.be.undefined; (0, _chai.expect)(formatter.input('0')).to.equal('+870'); if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) { (0, _chai.expect)(formatter.getCountry()).to.equal('001'); } else { (0, _chai.expect)(formatter.getCountry()).to.be.undefined; } (0, _chai.expect)(formatter.input('7')).to.equal('+870 7'); (0, _chai.expect)(formatter.input('7')).to.equal('+870 77'); (0, _chai.expect)(formatter.input('3')).to.equal('+870 773'); (0, _chai.expect)(formatter.input('1')).to.equal('+870 773 1'); (0, _chai.expect)(formatter.input('1')).to.equal('+870 773 11'); (0, _chai.expect)(formatter.input('1')).to.equal('+870 773 111'); (0, _chai.expect)(formatter.input('6')).to.equal('+870 773 111 6'); (0, _chai.expect)(formatter.input('3')).to.equal('+870 773 111 63'); (0, _chai.expect)(formatter.input('2')).to.equal('+870 773 111 632'); if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) { (0, _chai.expect)(formatter.getNumber().country).to.equal('001'); } else { (0, _chai.expect)(formatter.getCountry()).to.be.undefined; } (0, _chai.expect)(formatter.getNumber().countryCallingCode).to.equal('870'); }); (0, _mocha.it)('should format non-geographic numbering plan phone numbers (default country calling code)', function () { var formatter = new AsYouType({ defaultCallingCode: '870' }); if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) { (0, _chai.expect)(formatter.getNumber().country).to.equal('001'); } else { (0, _chai.expect)(formatter.getCountry()).to.be.undefined; } (0, _chai.expect)(formatter.input('7')).to.equal('7'); (0, _chai.expect)(formatter.input('7')).to.equal('77'); (0, _chai.expect)(formatter.input('3')).to.equal('773'); (0, _chai.expect)(formatter.input('1')).to.equal('773 1'); (0, _chai.expect)(formatter.input('1')).to.equal('773 11'); (0, _chai.expect)(formatter.input('1')).to.equal('773 111'); (0, _chai.expect)(formatter.input('6')).to.equal('773 111 6'); (0, _chai.expect)(formatter.input('3')).to.equal('773 111 63'); (0, _chai.expect)(formatter.input('2')).to.equal('773 111 632'); if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) { (0, _chai.expect)(formatter.getNumber().country).to.equal('001'); } else { (0, _chai.expect)(formatter.getCountry()).to.be.undefined; } (0, _chai.expect)(formatter.getNumber().countryCallingCode).to.equal('870'); }); (0, _mocha.it)('should not format non-geographic numbering plan phone numbers (default country 001)', function () { var formatter = new AsYouType('001'); (0, _chai.expect)(formatter.defaultCountry).to.be.undefined; (0, _chai.expect)(formatter.defaultCallingCode).to.be.undefined; (0, _chai.expect)(formatter.input('7')).to.equal('7'); (0, _chai.expect)(formatter.input('7')).to.equal('77'); (0, _chai.expect)(formatter.input('3')).to.equal('773'); (0, _chai.expect)(formatter.input('1')).to.equal('7731'); (0, _chai.expect)(formatter.input('1')).to.equal('77311'); (0, _chai.expect)(formatter.input('1')).to.equal('773111'); (0, _chai.expect)(formatter.input('6')).to.equal('7731116'); (0, _chai.expect)(formatter.input('3')).to.equal('77311163'); (0, _chai.expect)(formatter.input('2')).to.equal('773111632'); (0, _chai.expect)(formatter.getCountry()).to.be.undefined; (0, _chai.expect)(formatter.getNumber()).to.be.undefined; }); (0, _mocha.it)('should return PhoneNumber (should strip national prefix `1` in E.164 value)', function () { var formatter = new AsYouType('RU'); formatter.input('+1111'); (0, _chai.expect)(formatter.getNumber().number).to.equal('+111'); }); (0, _mocha.it)('should return PhoneNumber with autocorrected international numbers without leading +', function () { // https://github.com/catamphetamine/libphonenumber-js/issues/316 var formatter = new AsYouType('FR'); (0, _chai.expect)(formatter.input('33612902554')).to.equal('33 6 12 90 25 54'); (0, _chai.expect)(formatter.getNumber().country).to.equal('FR'); (0, _chai.expect)(formatter.getNumber().nationalNumber).to.equal('612902554'); (0, _chai.expect)(formatter.getNumber().number).to.equal('+33612902554'); // Should also strip national prefix. formatter.reset(); (0, _chai.expect)(formatter.input('330612902554')).to.equal('33 06 12 90 25 54'); (0, _chai.expect)(formatter.getNumber().country).to.equal('FR'); (0, _chai.expect)(formatter.getNumber().nationalNumber).to.equal('612902554'); (0, _chai.expect)(formatter.getNumber().number).to.equal('+33612902554'); // On second thought, this "prepend default area code" feature won't be added, // because when a user selects "British Virgin Islands" and inputs // "2291234", then they see "(229) 123-4" which clearly indicates that // they should input the complete phone number (with area code). // So, unless a user completely doesn't understand what they're doing, // they'd input the complete phone number (with area code). // // Should prepend the default area code in British Virgin Islands. // // https://github.com/catamphetamine/react-phone-number-input/issues/335 // const formatter2 = new AsYouType('VG') // formatter2.input('2291234').should.equal('(229) 123-4') // formatter2.getNumber().country.should.equal('VG') // formatter2.getNumber().nationalNumber.should.equal('2842291234') // formatter2.getNumber().number.should.equal('+12842291234') }); (0, _mocha.it)('should work with out-of-country dialing prefix (like 00)', function () { var formatter = new AsYouType('DE'); (0, _chai.expect)(formatter.input('00498911196611')).to.equal('00 49 89 11196611'); (0, _chai.expect)(formatter.getCountry()).to.equal('DE'); (0, _chai.expect)(formatter.formatter.template).to.equal('xx xx xx xxxxxxxx'); (0, _chai.expect)(formatter.formatter.populatedNationalNumberTemplate).to.equal('89 11196611'); (0, _chai.e