1 |
- {"version":3,"file":"PhoneNumberMatcher.test.js","names":["test","text","defaultCountry","expectedNumbers","nationalNumber","matcher","PhoneNumberMatcher","v2","metadata","hasNext","number","next","phoneNumber","shift","startsAt","undefined","should","equal","endsAt","country","length","describe","it","expect","leniency","to"],"sources":["../source/PhoneNumberMatcher.test.js"],"sourcesContent":["import PhoneNumberMatcher from './PhoneNumberMatcher.js'\r\nimport metadata from '../metadata.min.json' assert { type: 'json' }\r\n\r\nfunction test(text, defaultCountry, expectedNumbers) {\r\n\tif (typeof expectedNumbers === 'string') {\r\n\t\texpectedNumbers = [{\r\n\t\t\tnationalNumber: expectedNumbers\r\n\t\t}]\r\n\t}\r\n\tconst matcher = new PhoneNumberMatcher(text, { defaultCountry, v2: true }, metadata)\r\n\twhile (matcher.hasNext()) {\r\n\t\tconst number = matcher.next()\r\n\t\tconst phoneNumber = expectedNumbers.shift()\r\n\t\tif (phoneNumber.startsAt !== undefined) {\r\n\t\t\tnumber.startsAt.should.equal(phoneNumber.startsAt)\r\n\t\t}\r\n\t\tif (phoneNumber.endsAt !== undefined) {\r\n\t\t\tnumber.endsAt.should.equal(phoneNumber.endsAt)\r\n\t\t}\r\n\t\tnumber.number.country.should.equal(phoneNumber.country || defaultCountry)\r\n\t\tnumber.number.nationalNumber.should.equal(phoneNumber.nationalNumber)\r\n\t}\r\n\texpectedNumbers.length.should.equal(0)\r\n}\r\n\r\ndescribe('PhoneNumberMatcher', () => {\r\n\tit('should find phone numbers', () => {\r\n\t\ttest(\r\n\t\t\t'The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.',\r\n\t\t\t'US',\r\n\t\t\t[{\r\n\t\t\t\tcountry: 'RU',\r\n\t\t\t\tnationalNumber: '8005553535',\r\n\t\t\t\tstartsAt: 14,\r\n\t\t\t\tendsAt: 32\r\n\t\t\t}, {\r\n\t\t\t\tcountry: 'US',\r\n\t\t\t\tnationalNumber: '2133734253',\r\n\t\t\t\tstartsAt: 41,\r\n\t\t\t\tendsAt: 55\r\n\t\t\t}]\r\n\t\t)\r\n\t})\r\n\r\n\tit('should find phone numbers from Mexico', () => {\r\n\t\t// Test parsing fixed-line numbers of Mexico.\r\n\t\ttest('+52 (449)978-0001', 'MX', '4499780001')\r\n\t\ttest('01 (449)978-0001', 'MX', '4499780001')\r\n\t\ttest('(449)978-0001', 'MX', '4499780001')\r\n\t\t// Test parsing mobile numbers of Mexico.\r\n\t\ttest('+52 1 33 1234-5678', 'MX', '3312345678')\r\n\t\ttest('044 (33) 1234-5678', 'MX', '3312345678')\r\n\t\ttest('045 33 1234-5678', 'MX', '3312345678')\r\n\t})\r\n\r\n\tit('should find phone numbers from Argentina', () => {\r\n\t\t// Test parsing mobile numbers of Argentina.\r\n\t\ttest('+54 9 343 555 1212', 'AR', '93435551212')\r\n\t\ttest('0343 15-555-1212', 'AR', '93435551212')\r\n\r\n\t\ttest('+54 9 3715 65 4320', 'AR', '93715654320')\r\n\t\ttest('03715 15 65 4320', 'AR', '93715654320')\r\n\r\n\t\t// Test parsing fixed-line numbers of Argentina.\r\n\t\ttest('+54 11 3797 0000', 'AR', '1137970000')\r\n\t\ttest('011 3797 0000', 'AR', '1137970000')\r\n\r\n\t\ttest('+54 3715 65 4321', 'AR', '3715654321')\r\n\t\ttest('03715 65 4321', 'AR', '3715654321')\r\n\r\n\t\ttest('+54 23 1234 0000', 'AR', '2312340000')\r\n\t\ttest('023 1234 0000', 'AR', '2312340000')\r\n\t})\r\n\r\n\tit('should only support the supported leniency values', function() {\r\n\t\texpect(() => new PhoneNumberMatcher('+54 23 1234 0000', { leniency: 'STRICT_GROUPING', v2: true }, metadata)).to.throw('Supported values: \"POSSIBLE\", \"VALID\".')\r\n\t})\r\n})"],"mappings":";;AAAA;;AACA;;;;AAEA,SAASA,IAAT,CAAcC,IAAd,EAAoBC,cAApB,EAAoCC,eAApC,EAAqD;EACpD,IAAI,OAAOA,eAAP,KAA2B,QAA/B,EAAyC;IACxCA,eAAe,GAAG,CAAC;MAClBC,cAAc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