1 |
- {"version":3,"file":"parsePhoneNumberWithError.test.js","names":["parsePhoneNumber","parameters","push","metadata","_parsePhoneNumber","apply","parsePhoneNumberFull","metadataFull","describe","it","phoneNumber","country","should","equal","countryCallingCode","nationalNumber","number","isPossible","isValid","getType","expect","to","be","undefined","carrierCode","ext","format","formatNational","formatInternational","getURI"],"sources":["../source/parsePhoneNumberWithError.test.js"],"sourcesContent":["import _parsePhoneNumber from './parsePhoneNumberWithError.js'\r\nimport metadata from '../metadata.min.json' assert { type: 'json' }\r\nimport metadataFull from '../metadata.max.json' assert { type: 'json' }\r\n\r\nfunction parsePhoneNumber(...parameters) {\r\n\tparameters.push(metadata)\r\n\treturn _parsePhoneNumber.apply(this, parameters)\r\n}\r\n\r\nfunction parsePhoneNumberFull(...parameters) {\r\n\tparameters.push(metadataFull)\r\n\treturn _parsePhoneNumber.apply(this, parameters)\r\n}\r\n\r\ndescribe('parsePhoneNumberWithError', () => {\r\n\tit('should parse phone numbers', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('The phone number is: 8 (800) 555 35 35. Some other text.', 'RU')\r\n\t\tphoneNumber.country.should.equal('RU')\r\n\t\tphoneNumber.countryCallingCode.should.equal('7')\r\n\t\tphoneNumber.nationalNumber.should.equal('8005553535')\r\n\t\tphoneNumber.number.should.equal('+78005553535')\r\n\t\tphoneNumber.isPossible().should.equal(true)\r\n\t\tphoneNumber.isValid().should.equal(true)\r\n\t\t// phoneNumber.isValidForRegion('RU').should.equal(true)\r\n\t\t// Russian phone type regexps aren't included in default metadata.\r\n\t\tparsePhoneNumberFull('Phone: 8 (800) 555 35 35.', 'RU').getType().should.equal('TOLL_FREE')\r\n\t})\r\n\r\n\tit('shouldn\\'t set country when it\\'s non-derivable', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('+7 111 555 35 35')\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.countryCallingCode.should.equal('7')\r\n\t\tphoneNumber.nationalNumber.should.equal('1115553535')\r\n\t})\r\n\r\n\tit('should parse carrier code', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('0 15 21 5555-5555', 'BR')\r\n\t\tphoneNumber.carrierCode.should.equal('15')\r\n\t})\r\n\r\n\tit('should parse phone extension', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('Phone: 8 (800) 555 35 35 ext. 1234.', 'RU')\r\n\t\tphoneNumber.ext.should.equal('1234')\r\n\t})\r\n\r\n\tit('should validate numbers for countries with no type regular expressions', () => {\r\n\t\tparsePhoneNumber('+380391234567').isValid().should.equal(true)\r\n\t\tparsePhoneNumber('+380191234567').isValid().should.equal(false)\r\n\t})\r\n\r\n\tit('should format numbers', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('Phone: 8 (800) 555 35 35.', 'RU')\r\n\t\tphoneNumber.format('NATIONAL').should.equal('8 (800) 555-35-35')\r\n\t\tphoneNumber.formatNational().should.equal('8 (800) 555-35-35')\r\n\t\tphoneNumber.format('INTERNATIONAL').should.equal('+7 800 555 35 35')\r\n\t\tphoneNumber.formatInternational().should.equal('+7 800 555 35 35')\r\n\t})\r\n\r\n\tit('should get tel: URI', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('Phone: 8 (800) 555 35 35 ext. 1234.', 'RU')\r\n\t\tphoneNumber.getURI().should.equal('tel:+78005553535;ext=1234')\r\n\t})\r\n\r\n\tit('should work in edge cases', () => {\r\n\t\texpect(() => parsePhoneNumber('+78005553535', -1, {})).to.throw('Invalid second argument')\r\n\t})\r\n\r\n\tit('should throw parse errors', () => {\r\n\t\texpect(() => parsePhoneNumber('8005553535', 'XX')).to.throw('INVALID_COUNTRY')\r\n\t\texpect(() => parsePhoneNumber('+', 'RU')).to.throw('NOT_A_NUMBER')\r\n\t\texpect(() => parsePhoneNumber('a', 'RU')).to.throw('NOT_A_NUMBER')\r\n\t\texpect(() => parsePhoneNumber('1', 'RU')).to.throw('TOO_SHORT')\r\n\t\texpect(() => parsePhoneNumber('+4')).to.throw('TOO_SHORT')\r\n\t\texpect(() => parsePhoneNumber('+44')).to.throw('TOO_SHORT')\r\n\t\texpect(() => parsePhoneNumber('+443')).to.throw('TOO_SHORT')\r\n\t\texpect(() => parsePhoneNumber('+370')).to.throw('TOO_SHORT')\r\n\t\texpect(() => parsePhoneNumber('88888888888888888888', 'RU')).to.throw('TOO_LONG')\r\n\t\texpect(() => parsePhoneNumber('8 (800) 555 35 35')).to.throw('INVALID_COUNTRY')\r\n\t\texpect(() => parsePhoneNumber('+9991112233')).to.throw('INVALID_COUNTRY')\r\n\t\texpect(() => parsePhoneNumber('+9991112233', 'US')).to.throw('INVALID_COUNTRY')\r\n\t\texpect(() => parsePhoneNumber('8005553535 ', 'RU')).to.throw('TOO_LONG')\r\n\t})\r\n\r\n\tit('should parse incorrect international phone numbers', () => {\r\n\t\t// Parsing national prefixes and carrier codes\r\n\t\t// is only required for local phone numbers\r\n\t\t// but some people don't understand that\r\n\t\t// and sometimes write international phone numbers\r\n\t\t// with national prefixes (or maybe even carrier codes).\r\n\t\t// http://ucken.blogspot.ru/2016/03/trunk-prefixes-in-skype4b.html\r\n\t\t// Google's original library forgives such mistakes\r\n\t\t// and so does this library, because it has been requested:\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/127\r\n\r\n\t\tlet phoneNumber\r\n\r\n\t\t// For complete numbers it should strip national prefix.\r\n\t\tphoneNumber = parsePhoneNumber('+1 1877 215 5230')\r\n\t\tphoneNumber.nationalNumber.should.equal('8772155230')\r\n\t\tphoneNumber.country.should.equal('US')\r\n\r\n\t\t// For complete numbers it should strip national prefix.\r\n\t\tphoneNumber = parsePhoneNumber('+7 8800 555 3535')\r\n\t\tphoneNumber.nationalNumber.should.equal('8005553535')\r\n\t\tphoneNumber.country.should.equal('RU')\r\n\r\n\t\t// For incomplete numbers it shouldn't strip national prefix.\r\n\t\tphoneNumber = parsePhoneNumber('+7 8800 555 353')\r\n\t\tphoneNumber.nationalNumber.should.equal('8800555353')\r\n\t\tphoneNumber.country.should.equ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