matchPhoneNumberStringAgainstPhoneNumber.js.map 3.9 KB

1
  1. {"version":3,"file":"matchPhoneNumberStringAgainstPhoneNumber.js","names":["parsePhoneNumber","matchPhoneNumberStringAgainstPhoneNumber","phoneNumberString","phoneNumber","metadata","phoneNumberStringContainsCallingCode","parsedPhoneNumber","defaultCallingCode","countryCallingCode","ext","number","nationalNumber","indexOf"],"sources":["../../source/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js"],"sourcesContent":["import parsePhoneNumber from '../parsePhoneNumber.js'\r\n\r\n/**\r\n * Matches a phone number object against a phone number string.\r\n * @param {string} phoneNumberString\r\n * @param {PhoneNumber} phoneNumber\r\n * @param {object} metadata — Metadata JSON\r\n * @return {'INVALID_NUMBER'|'NO_MATCH'|'SHORT_NSN_MATCH'|'NSN_MATCH'|'EXACT_MATCH'}\r\n */\r\nexport default function matchPhoneNumberStringAgainstPhoneNumber(phoneNumberString, phoneNumber, metadata) {\r\n\t// Parse `phoneNumberString`.\r\n\tlet phoneNumberStringContainsCallingCode = true\r\n\tlet parsedPhoneNumber = parsePhoneNumber(phoneNumberString, metadata)\r\n\tif (!parsedPhoneNumber) {\r\n\t\t// If `phoneNumberString` didn't contain a country calling code\r\n\t\t// then substitute it with the `phoneNumber`'s country calling code.\r\n\t\tphoneNumberStringContainsCallingCode = false\r\n\t\tparsedPhoneNumber = parsePhoneNumber(phoneNumberString, { defaultCallingCode: phoneNumber.countryCallingCode }, metadata)\r\n\t}\r\n\tif (!parsedPhoneNumber) {\r\n\t\treturn 'INVALID_NUMBER'\r\n\t}\r\n\r\n\t// Check that the extensions match.\r\n\tif (phoneNumber.ext) {\r\n\t\tif (parsedPhoneNumber.ext !== phoneNumber.ext) {\r\n\t\t\treturn 'NO_MATCH'\r\n\t\t}\r\n\t} else {\r\n\t\tif (parsedPhoneNumber.ext) {\r\n\t\t\treturn 'NO_MATCH'\r\n\t\t}\r\n\t}\r\n\r\n\t// Check that country calling codes match.\r\n\tif (phoneNumberStringContainsCallingCode) {\r\n\t\tif (phoneNumber.countryCallingCode !== parsedPhoneNumber.countryCallingCode) {\r\n\t\t\treturn 'NO_MATCH'\r\n\t\t}\r\n\t}\r\n\r\n\t// Check if the whole numbers match.\r\n\tif (phoneNumber.number === parsedPhoneNumber.number) {\r\n\t\tif (phoneNumberStringContainsCallingCode) {\r\n\t\t\treturn 'EXACT_MATCH'\r\n\t\t} else {\r\n\t\t\treturn 'NSN_MATCH'\r\n\t\t}\r\n\t}\r\n\r\n\t// Check if one national number is a \"suffix\" of the other.\r\n\tif (\r\n\t\tphoneNumber.nationalNumber.indexOf(parsedPhoneNumber.nationalNumber) === 0 ||\r\n\t\tparsedPhoneNumber.nationalNumber.indexOf(phoneNumber.nationalNumber) === 0\r\n\t) {\r\n\t\t// \"A SHORT_NSN_MATCH occurs if there is a difference because of the\r\n\t\t// presence or absence of an 'Italian leading zero', the presence or\r\n\t\t// absence of an extension, or one NSN being a shorter variant of the\r\n\t\t// other.\"\r\n\t\treturn 'SHORT_NSN_MATCH'\r\n\t}\r\n\r\n\treturn 'NO_MATCH'\r\n}"],"mappings":"AAAA,OAAOA,gBAAP,MAA6B,wBAA7B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,wCAAT,CAAkDC,iBAAlD,EAAqEC,WAArE,EAAkFC,QAAlF,EAA4F;EAC1G;EACA,IAAIC,oCAAoC,GAAG,IAA3C;EACA,IAAIC,iBAAiB,GAAGN,gBAAgB,CAACE,iBAAD,EAAoBE,QAApB,CAAxC;;EACA,IAAI,CAACE,iBAAL,EAAwB;IACvB;IACA;IACAD,oCAAoC,GAAG,KAAvC;IACAC,iBAAiB,GAAGN,gBAAgB,CAACE,iBAAD,EAAoB;MAAEK,kBAAkB,EAAEJ,WAAW,CAACK;IAAlC,CAApB,EAA4EJ,QAA5E,CAApC;EACA;;EACD,IAAI,CAACE,iBAAL,EAAwB;IACvB,OAAO,gBAAP;EACA,CAZyG,CAc1G;;;EACA,IAAIH,WAAW,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