libphonenumber-js 1.9.38 → 1.9.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +8 -8
- package/build/AsYouType.test.js +25 -3
- package/build/AsYouType.test.js.map +1 -1
- package/build/AsYouTypeFormatter.PatternMatcher.js +435 -0
- package/build/AsYouTypeFormatter.PatternMatcher.js.map +1 -0
- package/build/AsYouTypeFormatter.PatternMatcher.test.js +447 -0
- package/build/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -0
- package/build/AsYouTypeFormatter.js +57 -10
- package/build/AsYouTypeFormatter.js.map +1 -1
- package/build/PhoneNumber.test.js +9 -9
- package/build/PhoneNumber.test.js.map +1 -1
- package/build/findNumbers.test.js +23 -23
- package/build/findNumbers.test.js.map +1 -1
- package/build/getExampleNumber.test.js +4 -4
- package/build/getExampleNumber.test.js.map +1 -1
- package/build/getNumberType.test.js +3 -3
- package/build/getNumberType.test.js.map +1 -1
- package/build/helpers/checkNumberLength.test.js +3 -3
- package/build/helpers/checkNumberLength.test.js.map +1 -1
- package/build/helpers/extractCountryCallingCode.test.js +4 -4
- package/build/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/build/parsePhoneNumber.test.js +2 -2
- package/build/parsePhoneNumber.test.js.map +1 -1
- package/bundle/libphonenumber-js.min.js +1 -1
- package/bundle/libphonenumber-js.min.js.map +1 -1
- package/bundle/libphonenumber-max.js +1 -1
- package/bundle/libphonenumber-max.js.map +1 -1
- package/bundle/libphonenumber-min.js +1 -1
- package/bundle/libphonenumber-min.js.map +1 -1
- package/bundle/libphonenumber-mobile.js +1 -1
- package/bundle/libphonenumber-mobile.js.map +1 -1
- package/es6/AsYouType.test.js +25 -3
- package/es6/AsYouType.test.js.map +1 -1
- package/es6/AsYouTypeFormatter.PatternMatcher.js +428 -0
- package/es6/AsYouTypeFormatter.PatternMatcher.js.map +1 -0
- package/es6/AsYouTypeFormatter.PatternMatcher.test.js +442 -0
- package/es6/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -0
- package/es6/AsYouTypeFormatter.js +56 -10
- package/es6/AsYouTypeFormatter.js.map +1 -1
- package/es6/PhoneNumber.test.js +1 -1
- package/es6/PhoneNumber.test.js.map +1 -1
- package/es6/findNumbers.test.js +1 -1
- package/es6/findNumbers.test.js.map +1 -1
- package/es6/getExampleNumber.test.js +2 -2
- package/es6/getExampleNumber.test.js.map +1 -1
- package/es6/getNumberType.test.js +1 -1
- package/es6/getNumberType.test.js.map +1 -1
- package/es6/helpers/checkNumberLength.test.js +1 -1
- package/es6/helpers/checkNumberLength.test.js.map +1 -1
- package/es6/helpers/extractCountryCallingCode.test.js +1 -1
- package/es6/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/es6/parsePhoneNumber.test.js +1 -1
- package/es6/parsePhoneNumber.test.js.map +1 -1
- package/exports/README.md +78 -0
- package/exports/examples.mobile.json/index.js +1 -0
- package/exports/metadata.max.json/index.js +1 -0
- package/exports/metadata.min.json/index.js +1 -0
- package/exports/metadata.mobile.json/index.js +1 -0
- package/exports/package.exports.json +55 -0
- package/max/index.commonjs.js +1 -1
- package/max/metadata.js +1 -1
- package/metadata.full.json +1 -1
- package/metadata.full.json.js +1 -1
- package/metadata.max.json +1 -0
- package/metadata.max.json.d.ts +4 -0
- package/metadata.max.json.js +4 -0
- package/metadata.min.json +1 -1
- package/metadata.min.json.js +1 -1
- package/metadata.mobile.json +1 -1
- package/metadata.mobile.json.js +1 -1
- package/package.json +4 -2
- package/source/AsYouType.test.js +26 -3
- package/source/AsYouTypeFormatter.PatternMatcher.js +343 -0
- package/source/AsYouTypeFormatter.PatternMatcher.test.js +596 -0
- package/source/AsYouTypeFormatter.js +58 -9
- package/source/PhoneNumber.test.js +1 -1
- package/source/findNumbers.test.js +1 -1
- package/source/getExampleNumber.test.js +2 -2
- package/source/getNumberType.test.js +1 -1
- package/source/helpers/checkNumberLength.test.js +1 -1
- package/source/helpers/extractCountryCallingCode.test.js +1 -1
- package/source/parsePhoneNumber.test.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/AsYouTypeFormatter.js"],"names":["DUMMY_DIGIT","LONGEST_NATIONAL_PHONE_NUMBER_LENGTH","LONGEST_DUMMY_PHONE_NUMBER","NATIONAL_PREFIX_SEPARATORS_PATTERN","SUPPORT_LEGACY_FORMATTING_PATTERNS","CREATE_CHARACTER_CLASS_PATTERN","CREATE_STANDALONE_DIGIT_PATTERN","NON_ALTERING_FORMAT_REG_EXP","RegExp","VALID_PUNCTUATION","MIN_LEADING_DIGITS_LENGTH","AsYouTypeFormatter","state","metadata","format","isNANP","nationalPrefixFormattingRule","test","international","nationalPrefix","usesNationalPrefix","resetFormat","chosenFormat","undefined","template","nationalNumberTemplate","populatedNationalNumberTemplate","populatedNationalNumberTemplatePosition","numberingPlan","callingCode","matchingFormats","formats","nationalSignificantNumber","narrowDownMatchingFormats","nextDigits","formattedCompleteNumber","shouldTryNationalPrefixFormattingRule","getSeparatorAfterNationalPrefix","setNationalNumberTemplate","replace","DIGIT_PLACEHOLDER","lastIndexOf","formatNationalNumberWithNextDigits","previouslyChosenFormat","newlyChosenFormat","chooseFormat","formatNextNationalNumberDigits","getNationalDigits","leadingDigits","leadingDigitsPatternIndex","length","filter","formatSuits","formatMatches","indexOf","nationalPrefixIsOptionalWhenFormattingInNationalFormat","nationalPrefixIsMandatoryWhenFormattingInNationalFormat","leadingDigitsPatternsCount","leadingDigitsPatterns","Math","min","leadingDigitsPattern","internationalFormat","getFormatFormat","createTemplateForFormat","_","slice","pattern","getTemplateForFormat","options","IDDPrefix","missingPlus","spacing","index","i","internationalPrefix","getInternationalPrefixBeforeCountryCallingCode","getDigitsWithoutInternationalPrefix","complexPrefixBeforeNationalSignificantNumber","digits","match","strictPattern","nationalNumberDummyDigits","numberFormat","nationalPrefixIncludedInTemplate","numberFormatWithNationalPrefix","FIRST_GROUP_PATTERN","result"],"mappings":";;;;;;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AAA,QAAQ,GAAG,gCAAOgB,qCAAP,EAA0BsC,4CAA4C,CAAC5B,MAAvE,IACV,GADU,GAEV1B,QAFD;AAGA,SALD,MAKO,IAAIL,cAAJ,EAAoB;AAC1B;AACAK,UAAAA,QAAQ,GAAG,gCAAOgB,qCAAP,EAA0BrB,cAAc,CAAC+B,MAAzC,IACV,KAAKb,+BAAL,CAAqCvB,MAArC,CADU,GAEVU,QAFD;AAGA;AACD;;AAED,UAAIN,aAAJ,EAAmB;AAClBM,QAAAA,QAAQ,GAAG,kDAAiCA,QAAjC,CAAX;AACA;;AAED,aAAOA,QAAP;AACA;;;mDAE8BuD,M,EAAQ;AACtC,UAAMQ,MAAM,GAAG,oDACd,KAAK7D,+BADS,EAEd,KAAKC,uCAFS,EAGdoD,MAHc,CAAf;;AAMA,UAAI,CAACQ,MAAL,EAAa;AACZ;AACA,aAAKlE,WAAL;AACA;AACA;;AAED,WAAKK,+BAAL,GAAuC6D,MAAM,CAAC,CAAD,CAA7C;AACA,WAAK5D,uCAAL,GAA+C4D,MAAM,CAAC,CAAD,CAArD,CAdsC,CAgBtC;;AACA,aAAO,oDAA2B,KAAK7D,+BAAhC,EAAiE,KAAKC,uCAAL,GAA+C,CAAhH,CAAP,CAjBsC,CAmBtC;AACA;AACA;AACA;AACA","sourcesContent":["import {\r\n\tDIGIT_PLACEHOLDER,\r\n\tcountOccurences,\r\n\trepeat,\r\n\tcutAndStripNonPairedParens,\r\n\tcloseNonPairedParens,\r\n\tstripNonPairedParens,\r\n\tpopulateTemplateWithDigits\r\n} from './AsYouTypeFormatter.util'\r\n\r\nimport formatCompleteNumber, {\r\n\tcanFormatCompleteNumber\r\n} from './AsYouTypeFormatter.complete'\r\n\r\nimport parseDigits from './helpers/parseDigits'\r\nexport { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.util'\r\nimport { FIRST_GROUP_PATTERN } from './helpers/formatNationalNumberUsingFormat'\r\nimport { VALID_PUNCTUATION } from './constants'\r\nimport applyInternationalSeparatorStyle from './helpers/applyInternationalSeparatorStyle'\r\n\r\n// Used in phone number format template creation.\r\n// Could be any digit, I guess.\r\nconst DUMMY_DIGIT = '9'\r\n// I don't know why is it exactly `15`\r\nconst LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15\r\n// Create a phone number consisting only of the digit 9 that matches the\r\n// `number_pattern` by applying the pattern to the \"longest phone number\" string.\r\nconst LONGEST_DUMMY_PHONE_NUMBER = repeat(DUMMY_DIGIT, LONGEST_NATIONAL_PHONE_NUMBER_LENGTH)\r\n\r\n// A set of characters that, if found in a national prefix formatting rules, are an indicator to\r\n// us that we should separate the national prefix from the number when formatting.\r\nconst NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/\r\n\r\n// Deprecated: Google has removed some formatting pattern related code from their repo.\r\n// https://github.com/googlei18n/libphonenumber/commit/a395b4fef3caf57c4bc5f082e1152a4d2bd0ba4c\r\n// \"We no longer have numbers in formatting matching patterns, only \\d.\"\r\n// Because this library supports generating custom metadata\r\n// some users may still be using old metadata so the relevant\r\n// code seems to stay until some next major version update.\r\nconst SUPPORT_LEGACY_FORMATTING_PATTERNS = true\r\n\r\n// A pattern that is used to match character classes in regular expressions.\r\n// An example of a character class is \"[1-4]\".\r\nconst CREATE_CHARACTER_CLASS_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\[([^\\[\\]])*\\]/g)\r\n\r\n// Any digit in a regular expression that actually denotes a digit. For\r\n// example, in the regular expression \"80[0-2]\\d{6,10}\", the first 2 digits\r\n// (8 and 0) are standalone digits, but the rest are not.\r\n// Two look-aheads are needed because the number following \\\\d could be a\r\n// two-digit number, since the phone number can be as long as 15 digits.\r\nconst CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\d(?=[^,}][^,}])/g)\r\n\r\n// A regular expression that is used to determine if a `format` is\r\n// suitable to be used in the \"as you type formatter\".\r\n// A `format` is suitable when the resulting formatted number has\r\n// the same digits as the user has entered.\r\n//\r\n// In the simplest case, that would mean that the format\r\n// doesn't add any additional digits when formatting a number.\r\n// Google says that it also shouldn't add \"star\" (`*`) characters,\r\n// like it does in some Israeli formats.\r\n// Such basic format would only contain \"valid punctuation\"\r\n// and \"captured group\" identifiers ($1, $2, etc).\r\n//\r\n// An example of a format that adds additional digits:\r\n//\r\n// Country: `AR` (Argentina).\r\n// Format:\r\n// {\r\n// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n// \"leading_digits_patterns\": [\"91\"],\r\n// \"national_prefix_formatting_rule\": \"0$1\",\r\n// \"format\": \"$2 15-$3-$4\",\r\n// \"international_format\": \"$1 $2 $3-$4\"\r\n// }\r\n//\r\n// In the format above, the `format` adds `15` to the digits when formatting a number.\r\n// A sidenote: this format actually is suitable because `national_prefix_for_parsing`\r\n// has previously removed `15` from a national number, so re-adding `15` in `format`\r\n// doesn't actually result in any extra digits added to user's input.\r\n// But verifying that would be a complex procedure, so the code chooses a simpler path:\r\n// it simply filters out all `format`s that contain anything but \"captured group\" ids.\r\n//\r\n// This regular expression is called `ELIGIBLE_FORMAT_PATTERN` in Google's\r\n// `libphonenumber` code.\r\n//\r\nconst NON_ALTERING_FORMAT_REG_EXP = new RegExp(\r\n\t'^' +\r\n\t'[' + VALID_PUNCTUATION + ']*' +\r\n\t'(\\\\$\\\\d[' + VALID_PUNCTUATION + ']*)+' +\r\n\t'$'\r\n)\r\n\r\n// This is the minimum length of the leading digits of a phone number\r\n// to guarantee the first \"leading digits pattern\" for a phone number format\r\n// to be preemptive.\r\nconst MIN_LEADING_DIGITS_LENGTH = 3\r\n\r\nexport default class AsYouTypeFormatter {\r\n\tconstructor({\r\n\t\tstate,\r\n\t\tmetadata\r\n\t}) {\r\n\t\tthis.metadata = metadata\r\n\t\tthis.resetFormat()\r\n\t}\r\n\r\n\tresetFormat() {\r\n\t\tthis.chosenFormat = undefined\r\n\t\tthis.template = undefined\r\n\t\tthis.nationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t}\r\n\r\n\treset(numberingPlan, state) {\r\n\t\tthis.resetFormat()\r\n\t\tif (numberingPlan) {\r\n\t\t\tthis.isNANP = numberingPlan.callingCode() === '1'\r\n\t\t\tthis.matchingFormats = numberingPlan.formats()\r\n\t\t\tif (state.nationalSignificantNumber) {\r\n\t\t\t\tthis.narrowDownMatchingFormats(state)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tthis.isNANP = undefined\r\n\t\t\tthis.matchingFormats = []\r\n\t\t}\r\n\t}\r\n\r\n\tformat(nextDigits, state) {\r\n\t\t// See if the phone number digits can be formatted as a complete phone number.\r\n\t\t// If not, use the results from `formatNationalNumberWithNextDigits()`,\r\n\t\t// which formats based on the chosen formatting pattern.\r\n\t\t//\r\n\t\t// Attempting to format complete phone number first is how it's done\r\n\t\t// in Google's `libphonenumber`, so this library just follows it.\r\n\t\t// Google's `libphonenumber` code doesn't explain in detail why does it\r\n\t\t// attempt to format digits as a complete phone number\r\n\t\t// instead of just going with a previoulsy (or newly) chosen `format`:\r\n\t\t//\r\n\t\t// \"Checks to see if there is an exact pattern match for these digits.\r\n\t\t// If so, we should use this instead of any other formatting template\r\n\t\t// whose leadingDigitsPattern also matches the input.\"\r\n\t\t//\r\n\t\tif (canFormatCompleteNumber(state.nationalSignificantNumber, this.metadata)) {\r\n\t\t\tfor (const format of this.matchingFormats) {\r\n\t\t\t\tconst formattedCompleteNumber = formatCompleteNumber(\r\n\t\t\t\t\tstate,\r\n\t\t\t\t\tformat,\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmetadata: this.metadata,\r\n\t\t\t\t\t\tshouldTryNationalPrefixFormattingRule: format => this.shouldTryNationalPrefixFormattingRule(format, {\r\n\t\t\t\t\t\t\tinternational: state.international,\r\n\t\t\t\t\t\t\tnationalPrefix: state.nationalPrefix\r\n\t\t\t\t\t\t}),\r\n\t\t\t\t\t\tgetSeparatorAfterNationalPrefix: this.getSeparatorAfterNationalPrefix\r\n\t\t\t\t\t}\r\n\t\t\t\t)\r\n\t\t\t\tif (formattedCompleteNumber) {\r\n\t\t\t\t\tthis.resetFormat()\r\n\t\t\t\t\tthis.chosenFormat = format\r\n\t\t\t\t\tthis.setNationalNumberTemplate(formattedCompleteNumber.replace(/\\d/g, DIGIT_PLACEHOLDER), state)\r\n\t\t\t\t\tthis.populatedNationalNumberTemplate = formattedCompleteNumber\r\n\t\t\t\t\t// With a new formatting template, the matched position\r\n\t\t\t\t\t// using the old template needs to be reset.\r\n\t\t\t\t\tthis.populatedNationalNumberTemplatePosition = this.template.lastIndexOf(DIGIT_PLACEHOLDER)\r\n\t\t\t\t\treturn formattedCompleteNumber\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Format the digits as a partial (incomplete) phone number\r\n\t\t// using the previously chosen formatting pattern (or a newly chosen one).\r\n\t\treturn this.formatNationalNumberWithNextDigits(nextDigits, state)\r\n\t}\r\n\r\n\t// Formats the next phone number digits.\r\n\tformatNationalNumberWithNextDigits(nextDigits, state) {\r\n\t\tconst previouslyChosenFormat = this.chosenFormat\r\n\t\t// Choose a format from the list of matching ones.\r\n\t\tconst newlyChosenFormat = this.chooseFormat(state)\r\n\t\tif (newlyChosenFormat) {\r\n\t\t\tif (newlyChosenFormat === previouslyChosenFormat) {\r\n\t\t\t\t// If it can format the next (current) digits\r\n\t\t\t\t// using the previously chosen phone number format\r\n\t\t\t\t// then return the updated formatted number.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(nextDigits)\r\n\t\t\t} else {\r\n\t\t\t\t// If a more appropriate phone number format\r\n\t\t\t\t// has been chosen for these \"leading digits\",\r\n\t\t\t\t// then re-format the national phone number part\r\n\t\t\t\t// using the newly selected format.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(state.getNationalDigits())\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tnarrowDownMatchingFormats({\r\n\t\tnationalSignificantNumber,\r\n\t\tnationalPrefix,\r\n\t\tinternational\r\n\t}) {\r\n\t\tconst leadingDigits = nationalSignificantNumber\r\n\r\n\t\t// \"leading digits\" pattern list starts with a\r\n\t\t// \"leading digits\" pattern fitting a maximum of 3 leading digits.\r\n\t\t// So, after a user inputs 3 digits of a national (significant) phone number\r\n\t\t// this national (significant) number can already be formatted.\r\n\t\t// The next \"leading digits\" pattern is for 4 leading digits max,\r\n\t\t// and the \"leading digits\" pattern after it is for 5 leading digits max, etc.\r\n\r\n\t\t// This implementation is different from Google's\r\n\t\t// in that it searches for a fitting format\r\n\t\t// even if the user has entered less than\r\n\t\t// `MIN_LEADING_DIGITS_LENGTH` digits of a national number.\r\n\t\t// Because some leading digit patterns already match for a single first digit.\r\n\t\tlet leadingDigitsPatternIndex = leadingDigits.length - MIN_LEADING_DIGITS_LENGTH\r\n\t\tif (leadingDigitsPatternIndex < 0) {\r\n\t\t\tleadingDigitsPatternIndex = 0\r\n\t\t}\r\n\r\n\t\tthis.matchingFormats = this.matchingFormats.filter(\r\n\t\t\tformat => this.formatSuits(format, international, nationalPrefix)\r\n\t\t\t\t&& this.formatMatches(format, leadingDigits, leadingDigitsPatternIndex)\r\n\t\t)\r\n\r\n\t\t// If there was a phone number format chosen\r\n\t\t// and it no longer holds given the new leading digits then reset it.\r\n\t\t// The test for this `if` condition is marked as:\r\n\t\t// \"Reset a chosen format when it no longer holds given the new leading digits\".\r\n\t\t// To construct a valid test case for this one can find a country\r\n\t\t// in `PhoneNumberMetadata.xml` yielding one format for 3 `<leadingDigits>`\r\n\t\t// and yielding another format for 4 `<leadingDigits>` (Australia in this case).\r\n\t\tif (this.chosenFormat && this.matchingFormats.indexOf(this.chosenFormat) === -1) {\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t}\r\n\r\n\tformatSuits(format, international, nationalPrefix) {\r\n\t\t// When a prefix before a national (significant) number is\r\n\t\t// simply a national prefix, then it's parsed as `this.nationalPrefix`.\r\n\t\t// In more complex cases, a prefix before national (significant) number\r\n\t\t// could include a national prefix as well as some \"capturing groups\",\r\n\t\t// and in that case there's no info whether a national prefix has been parsed.\r\n\t\t// If national prefix is not used when formatting a phone number\r\n\t\t// using this format, but a national prefix has been entered by the user,\r\n\t\t// and was extracted, then discard such phone number format.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L175-L184\r\n\t\tif (nationalPrefix &&\r\n\t\t\t!format.usesNationalPrefix() &&\r\n\t\t\t// !format.domesticCarrierCodeFormattingRule() &&\r\n\t\t\t!format.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\t// If national prefix is mandatory for this phone number format\r\n\t\t// and there're no guarantees that a national prefix is present in user input\r\n\t\t// then discard this phone number format as not suitable.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L185-L193\r\n\t\tif (!international &&\r\n\t\t\t!nationalPrefix &&\r\n\t\t\tformat.nationalPrefixIsMandatoryWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n\r\n\tformatMatches(format, leadingDigits, leadingDigitsPatternIndex) {\r\n\t\tconst leadingDigitsPatternsCount = format.leadingDigitsPatterns().length\r\n\t\t// If this format is not restricted to a certain\r\n\t\t// leading digits pattern then it fits.\r\n\t\tif (leadingDigitsPatternsCount === 0) {\r\n\t\t\treturn true\r\n\t\t}\r\n\t\t// Start excluding any non-matching formats only when the\r\n\t\t// national number entered so far is at least 3 digits long,\r\n\t\t// otherwise format matching would give false negatives.\r\n\t\t// For example, when the digits entered so far are `2`\r\n\t\t// and the leading digits pattern is `21` –\r\n\t\t// it's quite obvious in this case that the format could be the one\r\n\t\t// but due to the absence of further digits it would give false negative.\r\n\t\tif (leadingDigits.length < MIN_LEADING_DIGITS_LENGTH) {\r\n\t\t\treturn true\r\n\t\t}\r\n\t\t// If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are available\r\n\t\t// then format matching starts narrowing down the list of possible formats\r\n\t\t// (only previously matched formats are considered for next digits).\r\n\t\tleadingDigitsPatternIndex = Math.min(leadingDigitsPatternIndex, leadingDigitsPatternsCount - 1)\r\n\t\tconst leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex]\r\n\t\t// Brackets are required for `^` to be applied to\r\n\t\t// all or-ed (`|`) parts, not just the first one.\r\n\t\treturn new RegExp(`^(${leadingDigitsPattern})`).test(leadingDigits)\r\n\t}\r\n\r\n\tgetFormatFormat(format, international) {\r\n\t\treturn international ? format.internationalFormat() : format.format()\r\n\t}\r\n\r\n\tchooseFormat(state) {\r\n\t\t// When there are multiple available formats, the formatter uses the first\r\n\t\t// format where a formatting template could be created.\r\n\t\tfor (const format of this.matchingFormats.slice()) {\r\n\t\t\t// If this format is currently being used\r\n\t\t\t// and is still suitable, then stick to it.\r\n\t\t\tif (this.chosenFormat === format) {\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\t// Sometimes, a formatting rule inserts additional digits in a phone number,\r\n\t\t\t// and \"as you type\" formatter can't do that: it should only use the digits\r\n\t\t\t// that the user has input.\r\n\t\t\t//\r\n\t\t\t// For example, in Argentina, there's a format for mobile phone numbers:\r\n\t\t\t//\r\n\t\t\t// {\r\n\t\t\t// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n\t\t\t// \"leading_digits_patterns\": [\"91\"],\r\n\t\t\t// \"national_prefix_formatting_rule\": \"0$1\",\r\n\t\t\t// \"format\": \"$2 15-$3-$4\",\r\n\t\t\t// \"international_format\": \"$1 $2 $3-$4\"\r\n\t\t\t// }\r\n\t\t\t//\r\n\t\t\t// In that format, `international_format` is used instead of `format`\r\n\t\t\t// because `format` inserts `15` in the formatted number,\r\n\t\t\t// and `AsYouType` formatter should only use the digits\r\n\t\t\t// the user has actually input, without adding any extra digits.\r\n\t\t\t// In this case, it wouldn't make a difference, because the `15`\r\n\t\t\t// is first stripped when applying `national_prefix_for_parsing`\r\n\t\t\t// and then re-added when using `format`, so in reality it doesn't\r\n\t\t\t// add any new digits to the number, but to detect that, the code\r\n\t\t\t// would have to be more complex: it would have to try formatting\r\n\t\t\t// the digits using the format and then see if any digits have\r\n\t\t\t// actually been added or removed, and then, every time a new digit\r\n\t\t\t// is input, it should re-check whether the chosen format doesn't\r\n\t\t\t// alter the digits.\r\n\t\t\t//\r\n\t\t\t// Google's code doesn't go that far, and so does this library:\r\n\t\t\t// it simply requires that a `format` doesn't add any additonal\r\n\t\t\t// digits to user's input.\r\n\t\t\t//\r\n\t\t\t// Also, people in general should move from inputting phone numbers\r\n\t\t\t// in national format (possibly with national prefixes)\r\n\t\t\t// and use international phone number format instead:\r\n\t\t\t// it's a logical thing in the modern age of mobile phones,\r\n\t\t\t// globalization and the internet.\r\n\t\t\t//\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (!NON_ALTERING_FORMAT_REG_EXP.test(this.getFormatFormat(format, state.international))) {\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tif (!this.createTemplateForFormat(format, state)) {\r\n\t\t\t\t// Remove the format if it can't generate a template.\r\n\t\t\t\tthis.matchingFormats = this.matchingFormats.filter(_ => _ !== format)\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tthis.chosenFormat = format\r\n\t\t\tbreak\r\n\t\t}\r\n\t\tif (!this.chosenFormat) {\r\n\t\t\t// No format matches the national (significant) phone number.\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t\treturn this.chosenFormat\r\n\t}\r\n\r\n\tcreateTemplateForFormat(format, state) {\r\n\t\t// The formatter doesn't format numbers when numberPattern contains '|', e.g.\r\n\t\t// (20|3)\\d{4}. In those cases we quickly return.\r\n\t\t// (Though there's no such format in current metadata)\r\n\t\t/* istanbul ignore if */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS && format.pattern().indexOf('|') >= 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Get formatting template for this phone number format\r\n\t\tconst template = this.getTemplateForFormat(format, state)\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (template) {\r\n\t\t\tthis.setNationalNumberTemplate(template, state)\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\r\n\tgetSeparatorAfterNationalPrefix = (format) => {\r\n\t\t// `US` metadata doesn't have a `national_prefix_formatting_rule`,\r\n\t\t// so the `if` condition below doesn't apply to `US`,\r\n\t\t// but in reality there shoudl be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\t// So `US` national prefix separator is a \"special\" \"hardcoded\" case.\r\n\t\tif (this.isNANP) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// If a `format` has a `national_prefix_formatting_rule`\r\n\t\t// and that rule has a separator after a national prefix,\r\n\t\t// then it means that there should be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\tif (format &&\r\n\t\t\tformat.nationalPrefixFormattingRule() &&\r\n\t\t\tNATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// At this point, there seems to be no clear evidence that\r\n\t\t// there should be a separator between a national prefix\r\n\t\t// and a national (significant) number. So don't insert one.\r\n\t\treturn ''\r\n\t}\r\n\r\n\tgetInternationalPrefixBeforeCountryCallingCode({ IDDPrefix, missingPlus }, options) {\r\n\t\tif (IDDPrefix) {\r\n\t\t\treturn options && options.spacing === false ? IDDPrefix : IDDPrefix + ' '\r\n\t\t}\r\n\t\tif (missingPlus) {\r\n\t\t\treturn ''\r\n\t\t}\r\n\t\treturn '+'\r\n\t}\r\n\r\n\tgetTemplate(state) {\r\n\t\tif (!this.template) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// `this.template` holds the template for a \"complete\" phone number.\r\n\t\t// The currently entered phone number is most likely not \"complete\",\r\n\t\t// so trim all non-populated digits.\r\n\t\tlet index = -1\r\n\t\tlet i = 0\r\n\t\tconst internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state, { spacing: false }) : ''\r\n\t\twhile (i < internationalPrefix.length + state.getDigitsWithoutInternationalPrefix().length) {\r\n\t\t\tindex = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1)\r\n\t\t\ti++\r\n\t\t}\r\n\t\treturn cutAndStripNonPairedParens(this.template, index + 1)\r\n\t}\r\n\r\n\tsetNationalNumberTemplate(template, state) {\r\n\t\tthis.nationalNumberTemplate = template\r\n\t\tthis.populatedNationalNumberTemplate = template\r\n\t\t// With a new formatting template, the matched position\r\n\t\t// using the old template needs to be reset.\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t\t// For convenience, the public `.template` property\r\n\t\t// contains the whole international number\r\n\t\t// if the phone number being input is international:\r\n\t\t// 'x' for the '+' sign, 'x'es for the country phone code,\r\n\t\t// a spacebar and then the template for the formatted national number.\r\n\t\tif (state.international) {\r\n\t\t\tthis.template =\r\n\t\t\t\tthis.getInternationalPrefixBeforeCountryCallingCode(state).replace(/[\\d\\+]/g, DIGIT_PLACEHOLDER) +\r\n\t\t\t\trepeat(DIGIT_PLACEHOLDER, state.callingCode.length) +\r\n\t\t\t\t' ' +\r\n\t\t\t\ttemplate\r\n\t\t} else {\r\n\t\t\tthis.template = template\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Generates formatting template for a national phone number,\r\n\t * optionally containing a national prefix, for a format.\r\n\t * @param {Format} format\r\n\t * @param {string} nationalPrefix\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplateForFormat(format, {\r\n\t\tnationalSignificantNumber,\r\n\t\tinternational,\r\n\t\tnationalPrefix,\r\n\t\tcomplexPrefixBeforeNationalSignificantNumber\r\n\t}) {\r\n\t\tlet pattern = format.pattern()\r\n\r\n\t\t/* istanbul ignore else */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS) {\r\n\t\t\tpattern = pattern\r\n\t\t\t\t// Replace anything in the form of [..] with \\d\r\n\t\t\t\t.replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\\\d')\r\n\t\t\t\t// Replace any standalone digit (not the one in `{}`) with \\d\r\n\t\t\t\t.replace(CREATE_STANDALONE_DIGIT_PATTERN(), '\\\\d')\r\n\t\t}\r\n\r\n\t\t// Generate a dummy national number (consisting of `9`s)\r\n\t\t// that fits this format's `pattern`.\r\n\t\t//\r\n\t\t// This match will always succeed,\r\n\t\t// because the \"longest dummy phone number\"\r\n\t\t// has enough length to accomodate any possible\r\n\t\t// national phone number format pattern.\r\n\t\t//\r\n\t\tlet digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0]\r\n\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (nationalSignificantNumber.length > digits.length) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// Get a formatting template which can be used to efficiently format\r\n\t\t// a partial number where digits are added one by one.\r\n\r\n\t\t// Below `strictPattern` is used for the\r\n\t\t// regular expression (with `^` and `$`).\r\n\t\t// This wasn't originally in Google's `libphonenumber`\r\n\t\t// and I guess they don't really need it\r\n\t\t// because they're not using \"templates\" to format phone numbers\r\n\t\t// but I added `strictPattern` after encountering\r\n\t\t// South Korean phone number formatting bug.\r\n\t\t//\r\n\t\t// Non-strict regular expression bug demonstration:\r\n\t\t//\r\n\t\t// this.nationalSignificantNumber : `111111111` (9 digits)\r\n\t\t//\r\n\t\t// pattern : (\\d{2})(\\d{3,4})(\\d{4})\r\n\t\t// format : `$1 $2 $3`\r\n\t\t// digits : `9999999999` (10 digits)\r\n\t\t//\r\n\t\t// '9999999999'.replace(new RegExp(/(\\d{2})(\\d{3,4})(\\d{4})/g), '$1 $2 $3') = \"99 9999 9999\"\r\n\t\t//\r\n\t\t// template : xx xxxx xxxx\r\n\t\t//\r\n\t\t// But the correct template in this case is `xx xxx xxxx`.\r\n\t\t// The template was generated incorrectly because of the\r\n\t\t// `{3,4}` variability in the `pattern`.\r\n\t\t//\r\n\t\t// The fix is, if `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then `this.nationalSignificantNumber`\r\n\t\t// is used instead of `digits`.\r\n\r\n\t\tconst strictPattern = new RegExp('^' + pattern + '$')\r\n\t\tconst nationalNumberDummyDigits = nationalSignificantNumber.replace(/\\d/g, DUMMY_DIGIT)\r\n\r\n\t\t// If `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then use it\r\n\t\t// instead of `digits`.\r\n\t\tif (strictPattern.test(nationalNumberDummyDigits)) {\r\n\t\t\tdigits = nationalNumberDummyDigits\r\n\t\t}\r\n\r\n\t\tlet numberFormat = this.getFormatFormat(format, international)\r\n\t\tlet nationalPrefixIncludedInTemplate\r\n\r\n\t\t// If a user did input a national prefix (and that's guaranteed),\r\n\t\t// and if a `format` does have a national prefix formatting rule,\r\n\t\t// then see if that national prefix formatting rule\r\n\t\t// prepends exactly the same national prefix the user has input.\r\n\t\t// If that's the case, then use the `format` with the national prefix formatting rule.\r\n\t\t// Otherwise, use the `format` without the national prefix formatting rule,\r\n\t\t// and prepend a national prefix manually to it.\r\n\t\tif (this.shouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix })) {\r\n\t\t\tconst numberFormatWithNationalPrefix = numberFormat.replace(\r\n\t\t\t\tFIRST_GROUP_PATTERN,\r\n\t\t\t\tformat.nationalPrefixFormattingRule()\r\n\t\t\t)\r\n\t\t\t// If `national_prefix_formatting_rule` of a `format` simply prepends\r\n\t\t\t// national prefix at the start of a national (significant) number,\r\n\t\t\t// then such formatting can be used with `AsYouType` formatter.\r\n\t\t\t// There seems to be no `else` case: everywhere in metadata,\r\n\t\t\t// national prefix formatting rule is national prefix + $1,\r\n\t\t\t// or `($1)`, in which case such format isn't even considered\r\n\t\t\t// when the user has input a national prefix.\r\n\t\t\t/* istanbul ignore else */\r\n\t\t\tif (parseDigits(format.nationalPrefixFormattingRule()) === (nationalPrefix || '') + parseDigits('$1')) {\r\n\t\t\t\tnumberFormat = numberFormatWithNationalPrefix\r\n\t\t\t\tnationalPrefixIncludedInTemplate = true\r\n\t\t\t\t// Replace all digits of the national prefix in the formatting template\r\n\t\t\t\t// with `DIGIT_PLACEHOLDER`s.\r\n\t\t\t\tif (nationalPrefix) {\r\n\t\t\t\t\tlet i = nationalPrefix.length\r\n\t\t\t\t\twhile (i > 0) {\r\n\t\t\t\t\t\tnumberFormat = numberFormat.replace(/\\d/, DIGIT_PLACEHOLDER)\r\n\t\t\t\t\t\ti--\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Generate formatting template for this phone number format.\r\n\t\tlet template = digits\r\n\t\t\t// Format the dummy phone number according to the format.\r\n\t\t\t.replace(new RegExp(pattern), numberFormat)\r\n\t\t\t// Replace each dummy digit with a DIGIT_PLACEHOLDER.\r\n\t\t\t.replace(new RegExp(DUMMY_DIGIT, 'g'), DIGIT_PLACEHOLDER)\r\n\r\n\t\t// If a prefix of a national (significant) number is not as simple\r\n\t\t// as just a basic national prefix, then just prepend such prefix\r\n\t\t// before the national (significant) number, optionally spacing\r\n\t\t// the two with a whitespace.\r\n\t\tif (!nationalPrefixIncludedInTemplate) {\r\n\t\t\tif (complexPrefixBeforeNationalSignificantNumber) {\r\n\t\t\t\t// Prepend the prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, complexPrefixBeforeNationalSignificantNumber.length) +\r\n\t\t\t\t\t' ' +\r\n\t\t\t\t\ttemplate\r\n\t\t\t} else if (nationalPrefix) {\r\n\t\t\t\t// Prepend national prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, nationalPrefix.length) +\r\n\t\t\t\t\tthis.getSeparatorAfterNationalPrefix(format) +\r\n\t\t\t\t\ttemplate\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (international) {\r\n\t\t\ttemplate = applyInternationalSeparatorStyle(template)\r\n\t\t}\r\n\r\n\t\treturn template\r\n\t}\r\n\r\n\tformatNextNationalNumberDigits(digits) {\r\n\t\tconst result = populateTemplateWithDigits(\r\n\t\t\tthis.populatedNationalNumberTemplate,\r\n\t\t\tthis.populatedNationalNumberTemplatePosition,\r\n\t\t\tdigits\r\n\t\t)\r\n\r\n\t\tif (!result) {\r\n\t\t\t// Reset the format.\r\n\t\t\tthis.resetFormat()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tthis.populatedNationalNumberTemplate = result[0]\r\n\t\tthis.populatedNationalNumberTemplatePosition = result[1]\r\n\r\n\t\t// Return the formatted phone number so far.\r\n\t\treturn cutAndStripNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\r\n\t\t// The old way which was good for `input-format` but is not so good\r\n\t\t// for `react-phone-number-input`'s default input (`InputBasic`).\r\n\t\t// return closeNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\t\t// \t.replace(new RegExp(DIGIT_PLACEHOLDER, 'g'), ' ')\r\n\t}\r\n\r\n\tshouldTryNationalPrefixFormattingRule = (format, { international, nationalPrefix }) => {\r\n\t\tif (format.nationalPrefixFormattingRule()) {\r\n\t\t\t// In some countries, `national_prefix_formatting_rule` is `($1)`,\r\n\t\t\t// so it applies even if the user hasn't input a national prefix.\r\n\t\t\t// `format.usesNationalPrefix()` detects such cases.\r\n\t\t\tconst usesNationalPrefix = format.usesNationalPrefix()\r\n\t\t\tif ((usesNationalPrefix && nationalPrefix) ||\r\n\t\t\t\t(!usesNationalPrefix && !international)) {\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}"],"file":"AsYouTypeFormatter.js"}
|
|
1
|
+
{"version":3,"sources":["../source/AsYouTypeFormatter.js"],"names":["DUMMY_DIGIT","LONGEST_NATIONAL_PHONE_NUMBER_LENGTH","LONGEST_DUMMY_PHONE_NUMBER","NATIONAL_PREFIX_SEPARATORS_PATTERN","SUPPORT_LEGACY_FORMATTING_PATTERNS","CREATE_CHARACTER_CLASS_PATTERN","CREATE_STANDALONE_DIGIT_PATTERN","NON_ALTERING_FORMAT_REG_EXP","RegExp","VALID_PUNCTUATION","MIN_LEADING_DIGITS_LENGTH","AsYouTypeFormatter","state","metadata","format","isNANP","nationalPrefixFormattingRule","test","international","nationalPrefix","usesNationalPrefix","resetFormat","chosenFormat","undefined","template","nationalNumberTemplate","populatedNationalNumberTemplate","populatedNationalNumberTemplatePosition","numberingPlan","callingCode","matchingFormats","formats","nationalSignificantNumber","narrowDownMatchingFormats","nextDigits","formattedCompleteNumber","shouldTryNationalPrefixFormattingRule","getSeparatorAfterNationalPrefix","setNationalNumberTemplate","replace","DIGIT_PLACEHOLDER","lastIndexOf","formatNationalNumberWithNextDigits","previouslyChosenFormat","newlyChosenFormat","chooseFormat","formatNextNationalNumberDigits","getNationalDigits","leadingDigits","leadingDigitsPatternIndex","length","filter","formatSuits","formatMatches","indexOf","nationalPrefixIsOptionalWhenFormattingInNationalFormat","nationalPrefixIsMandatoryWhenFormattingInNationalFormat","leadingDigitsPatternsCount","leadingDigitsPatterns","Math","min","leadingDigitsPattern","PatternMatcher","match","allowOverflow","error","console","internationalFormat","getFormatFormat","createTemplateForFormat","_","slice","pattern","getTemplateForFormat","options","IDDPrefix","missingPlus","spacing","index","i","internationalPrefix","getInternationalPrefixBeforeCountryCallingCode","getDigitsWithoutInternationalPrefix","complexPrefixBeforeNationalSignificantNumber","digits","strictPattern","nationalNumberDummyDigits","numberFormat","nationalPrefixIncludedInTemplate","numberFormatWithNationalPrefix","FIRST_GROUP_PATTERN","result"],"mappings":";;;;;;;;;;;;;AAAA;;AAUA;;AAIA;;AAEA;;AAEA;;AACA;;AACA;;;;;;;;;;;;;;AAEA;AACA;AACA,IAAMA,WAAW,GAAG,GAApB,C,CACA;;AACA,IAAMC,oCAAoC,GAAG,EAA7C,C,CACA;AACA;;AACA,IAAMC,0BAA0B,GAAG,gCAAOF,WAAP,EAAoBC,oCAApB,CAAnC,C,CAEA;AACA;;AACA,IAAME,kCAAkC,GAAG,MAA3C,C,CAEA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,kCAAkC,GAAG,IAA3C,C,CAEA;AACA;;AACA,IAAMC,8BAA8B,GAAGD,kCAAkC,IAAK;AAAA,SAAM,iBAAN;AAAA,CAA9E,C,CAEA;AACA;AACA;AACA;AACA;;;AACA,IAAME,+BAA+B,GAAGF,kCAAkC,IAAK;AAAA,SAAM,mBAAN;AAAA,CAA/E,C,CAEA;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;AACA;AACA;AACA;AACA;;;AACA,IAAMG,2BAA2B,GAAG,IAAIC,MAAJ,CACnC,MACA,GADA,GACMC,4BADN,GAC0B,IAD1B,GAEA,UAFA,GAEaA,4BAFb,GAEiC,MAFjC,GAGA,GAJmC,CAApC,C,CAOA;AACA;AACA;;AACA,IAAMC,yBAAyB,GAAG,CAAlC;;IAEqBC,kB;;;AACpB,oCAGG;AAAA;;AAAA,QAFFC,KAEE,QAFFA,KAEE;AAAA,QADFC,QACE,QADFA,QACE;;AAAA;;AAAA,6DAwU+B,UAACC,MAAD,EAAY;AAC7C;AACA;AACA;AACA;AACA;AACA,UAAI,KAAI,CAACC,MAAT,EAAiB;AAChB,eAAO,GAAP;AACA,OAR4C,CAS7C;AACA;AACA;AACA;;;AACA,UAAID,MA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CAjBsC,CAmBtC;AACA;AACA;AACA;AACA","sourcesContent":["import {\r\n\tDIGIT_PLACEHOLDER,\r\n\tcountOccurences,\r\n\trepeat,\r\n\tcutAndStripNonPairedParens,\r\n\tcloseNonPairedParens,\r\n\tstripNonPairedParens,\r\n\tpopulateTemplateWithDigits\r\n} from './AsYouTypeFormatter.util'\r\n\r\nimport formatCompleteNumber, {\r\n\tcanFormatCompleteNumber\r\n} from './AsYouTypeFormatter.complete'\r\n\r\nimport PatternMatcher from './AsYouTypeFormatter.PatternMatcher'\r\n\r\nimport parseDigits from './helpers/parseDigits'\r\nexport { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.util'\r\nimport { FIRST_GROUP_PATTERN } from './helpers/formatNationalNumberUsingFormat'\r\nimport { VALID_PUNCTUATION } from './constants'\r\nimport applyInternationalSeparatorStyle from './helpers/applyInternationalSeparatorStyle'\r\n\r\n// Used in phone number format template creation.\r\n// Could be any digit, I guess.\r\nconst DUMMY_DIGIT = '9'\r\n// I don't know why is it exactly `15`\r\nconst LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15\r\n// Create a phone number consisting only of the digit 9 that matches the\r\n// `number_pattern` by applying the pattern to the \"longest phone number\" string.\r\nconst LONGEST_DUMMY_PHONE_NUMBER = repeat(DUMMY_DIGIT, LONGEST_NATIONAL_PHONE_NUMBER_LENGTH)\r\n\r\n// A set of characters that, if found in a national prefix formatting rules, are an indicator to\r\n// us that we should separate the national prefix from the number when formatting.\r\nconst NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/\r\n\r\n// Deprecated: Google has removed some formatting pattern related code from their repo.\r\n// https://github.com/googlei18n/libphonenumber/commit/a395b4fef3caf57c4bc5f082e1152a4d2bd0ba4c\r\n// \"We no longer have numbers in formatting matching patterns, only \\d.\"\r\n// Because this library supports generating custom metadata\r\n// some users may still be using old metadata so the relevant\r\n// code seems to stay until some next major version update.\r\nconst SUPPORT_LEGACY_FORMATTING_PATTERNS = true\r\n\r\n// A pattern that is used to match character classes in regular expressions.\r\n// An example of a character class is \"[1-4]\".\r\nconst CREATE_CHARACTER_CLASS_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\[([^\\[\\]])*\\]/g)\r\n\r\n// Any digit in a regular expression that actually denotes a digit. For\r\n// example, in the regular expression \"80[0-2]\\d{6,10}\", the first 2 digits\r\n// (8 and 0) are standalone digits, but the rest are not.\r\n// Two look-aheads are needed because the number following \\\\d could be a\r\n// two-digit number, since the phone number can be as long as 15 digits.\r\nconst CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\d(?=[^,}][^,}])/g)\r\n\r\n// A regular expression that is used to determine if a `format` is\r\n// suitable to be used in the \"as you type formatter\".\r\n// A `format` is suitable when the resulting formatted number has\r\n// the same digits as the user has entered.\r\n//\r\n// In the simplest case, that would mean that the format\r\n// doesn't add any additional digits when formatting a number.\r\n// Google says that it also shouldn't add \"star\" (`*`) characters,\r\n// like it does in some Israeli formats.\r\n// Such basic format would only contain \"valid punctuation\"\r\n// and \"captured group\" identifiers ($1, $2, etc).\r\n//\r\n// An example of a format that adds additional digits:\r\n//\r\n// Country: `AR` (Argentina).\r\n// Format:\r\n// {\r\n// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n// \"leading_digits_patterns\": [\"91\"],\r\n// \"national_prefix_formatting_rule\": \"0$1\",\r\n// \"format\": \"$2 15-$3-$4\",\r\n// \"international_format\": \"$1 $2 $3-$4\"\r\n// }\r\n//\r\n// In the format above, the `format` adds `15` to the digits when formatting a number.\r\n// A sidenote: this format actually is suitable because `national_prefix_for_parsing`\r\n// has previously removed `15` from a national number, so re-adding `15` in `format`\r\n// doesn't actually result in any extra digits added to user's input.\r\n// But verifying that would be a complex procedure, so the code chooses a simpler path:\r\n// it simply filters out all `format`s that contain anything but \"captured group\" ids.\r\n//\r\n// This regular expression is called `ELIGIBLE_FORMAT_PATTERN` in Google's\r\n// `libphonenumber` code.\r\n//\r\nconst NON_ALTERING_FORMAT_REG_EXP = new RegExp(\r\n\t'^' +\r\n\t'[' + VALID_PUNCTUATION + ']*' +\r\n\t'(\\\\$\\\\d[' + VALID_PUNCTUATION + ']*)+' +\r\n\t'$'\r\n)\r\n\r\n// This is the minimum length of the leading digits of a phone number\r\n// to guarantee the first \"leading digits pattern\" for a phone number format\r\n// to be preemptive.\r\nconst MIN_LEADING_DIGITS_LENGTH = 3\r\n\r\nexport default class AsYouTypeFormatter {\r\n\tconstructor({\r\n\t\tstate,\r\n\t\tmetadata\r\n\t}) {\r\n\t\tthis.metadata = metadata\r\n\t\tthis.resetFormat()\r\n\t}\r\n\r\n\tresetFormat() {\r\n\t\tthis.chosenFormat = undefined\r\n\t\tthis.template = undefined\r\n\t\tthis.nationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t}\r\n\r\n\treset(numberingPlan, state) {\r\n\t\tthis.resetFormat()\r\n\t\tif (numberingPlan) {\r\n\t\t\tthis.isNANP = numberingPlan.callingCode() === '1'\r\n\t\t\tthis.matchingFormats = numberingPlan.formats()\r\n\t\t\tif (state.nationalSignificantNumber) {\r\n\t\t\t\tthis.narrowDownMatchingFormats(state)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tthis.isNANP = undefined\r\n\t\t\tthis.matchingFormats = []\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Formats an updated phone number.\r\n\t * @param {string} nextDigits — Additional phone number digits.\r\n\t * @param {object} state — `AsYouType` state.\r\n\t * @return {[string]} Returns undefined if the updated phone number can't be formatted using any of the available formats.\r\n\t */\r\n\tformat(nextDigits, state) {\r\n\t\t// See if the phone number digits can be formatted as a complete phone number.\r\n\t\t// If not, use the results from `formatNationalNumberWithNextDigits()`,\r\n\t\t// which formats based on the chosen formatting pattern.\r\n\t\t//\r\n\t\t// Attempting to format complete phone number first is how it's done\r\n\t\t// in Google's `libphonenumber`, so this library just follows it.\r\n\t\t// Google's `libphonenumber` code doesn't explain in detail why does it\r\n\t\t// attempt to format digits as a complete phone number\r\n\t\t// instead of just going with a previoulsy (or newly) chosen `format`:\r\n\t\t//\r\n\t\t// \"Checks to see if there is an exact pattern match for these digits.\r\n\t\t// If so, we should use this instead of any other formatting template\r\n\t\t// whose leadingDigitsPattern also matches the input.\"\r\n\t\t//\r\n\t\tif (canFormatCompleteNumber(state.nationalSignificantNumber, this.metadata)) {\r\n\t\t\tfor (const format of this.matchingFormats) {\r\n\t\t\t\tconst formattedCompleteNumber = formatCompleteNumber(\r\n\t\t\t\t\tstate,\r\n\t\t\t\t\tformat,\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmetadata: this.metadata,\r\n\t\t\t\t\t\tshouldTryNationalPrefixFormattingRule: format => this.shouldTryNationalPrefixFormattingRule(format, {\r\n\t\t\t\t\t\t\tinternational: state.international,\r\n\t\t\t\t\t\t\tnationalPrefix: state.nationalPrefix\r\n\t\t\t\t\t\t}),\r\n\t\t\t\t\t\tgetSeparatorAfterNationalPrefix: this.getSeparatorAfterNationalPrefix\r\n\t\t\t\t\t}\r\n\t\t\t\t)\r\n\t\t\t\tif (formattedCompleteNumber) {\r\n\t\t\t\t\tthis.resetFormat()\r\n\t\t\t\t\tthis.chosenFormat = format\r\n\t\t\t\t\tthis.setNationalNumberTemplate(formattedCompleteNumber.replace(/\\d/g, DIGIT_PLACEHOLDER), state)\r\n\t\t\t\t\tthis.populatedNationalNumberTemplate = formattedCompleteNumber\r\n\t\t\t\t\t// With a new formatting template, the matched position\r\n\t\t\t\t\t// using the old template needs to be reset.\r\n\t\t\t\t\tthis.populatedNationalNumberTemplatePosition = this.template.lastIndexOf(DIGIT_PLACEHOLDER)\r\n\t\t\t\t\treturn formattedCompleteNumber\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Format the digits as a partial (incomplete) phone number\r\n\t\t// using the previously chosen formatting pattern (or a newly chosen one).\r\n\t\treturn this.formatNationalNumberWithNextDigits(nextDigits, state)\r\n\t}\r\n\r\n\t// Formats the next phone number digits.\r\n\tformatNationalNumberWithNextDigits(nextDigits, state) {\r\n\t\tconst previouslyChosenFormat = this.chosenFormat\r\n\t\t// Choose a format from the list of matching ones.\r\n\t\tconst newlyChosenFormat = this.chooseFormat(state)\r\n\t\tif (newlyChosenFormat) {\r\n\t\t\tif (newlyChosenFormat === previouslyChosenFormat) {\r\n\t\t\t\t// If it can format the next (current) digits\r\n\t\t\t\t// using the previously chosen phone number format\r\n\t\t\t\t// then return the updated formatted number.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(nextDigits)\r\n\t\t\t} else {\r\n\t\t\t\t// If a more appropriate phone number format\r\n\t\t\t\t// has been chosen for these \"leading digits\",\r\n\t\t\t\t// then re-format the national phone number part\r\n\t\t\t\t// using the newly selected format.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(state.getNationalDigits())\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tnarrowDownMatchingFormats({\r\n\t\tnationalSignificantNumber,\r\n\t\tnationalPrefix,\r\n\t\tinternational\r\n\t}) {\r\n\t\tconst leadingDigits = nationalSignificantNumber\r\n\r\n\t\t// \"leading digits\" pattern list starts with a\r\n\t\t// \"leading digits\" pattern fitting a maximum of 3 leading digits.\r\n\t\t// So, after a user inputs 3 digits of a national (significant) phone number\r\n\t\t// this national (significant) number can already be formatted.\r\n\t\t// The next \"leading digits\" pattern is for 4 leading digits max,\r\n\t\t// and the \"leading digits\" pattern after it is for 5 leading digits max, etc.\r\n\r\n\t\t// This implementation is different from Google's\r\n\t\t// in that it searches for a fitting format\r\n\t\t// even if the user has entered less than\r\n\t\t// `MIN_LEADING_DIGITS_LENGTH` digits of a national number.\r\n\t\t// Because some leading digit patterns already match for a single first digit.\r\n\t\tlet leadingDigitsPatternIndex = leadingDigits.length - MIN_LEADING_DIGITS_LENGTH\r\n\t\tif (leadingDigitsPatternIndex < 0) {\r\n\t\t\tleadingDigitsPatternIndex = 0\r\n\t\t}\r\n\r\n\t\tthis.matchingFormats = this.matchingFormats.filter(\r\n\t\t\tformat => this.formatSuits(format, international, nationalPrefix)\r\n\t\t\t\t&& this.formatMatches(format, leadingDigits, leadingDigitsPatternIndex)\r\n\t\t)\r\n\r\n\t\t// If there was a phone number format chosen\r\n\t\t// and it no longer holds given the new leading digits then reset it.\r\n\t\t// The test for this `if` condition is marked as:\r\n\t\t// \"Reset a chosen format when it no longer holds given the new leading digits\".\r\n\t\t// To construct a valid test case for this one can find a country\r\n\t\t// in `PhoneNumberMetadata.xml` yielding one format for 3 `<leadingDigits>`\r\n\t\t// and yielding another format for 4 `<leadingDigits>` (Australia in this case).\r\n\t\tif (this.chosenFormat && this.matchingFormats.indexOf(this.chosenFormat) === -1) {\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t}\r\n\r\n\tformatSuits(format, international, nationalPrefix) {\r\n\t\t// When a prefix before a national (significant) number is\r\n\t\t// simply a national prefix, then it's parsed as `this.nationalPrefix`.\r\n\t\t// In more complex cases, a prefix before national (significant) number\r\n\t\t// could include a national prefix as well as some \"capturing groups\",\r\n\t\t// and in that case there's no info whether a national prefix has been parsed.\r\n\t\t// If national prefix is not used when formatting a phone number\r\n\t\t// using this format, but a national prefix has been entered by the user,\r\n\t\t// and was extracted, then discard such phone number format.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L175-L184\r\n\t\tif (nationalPrefix &&\r\n\t\t\t!format.usesNationalPrefix() &&\r\n\t\t\t// !format.domesticCarrierCodeFormattingRule() &&\r\n\t\t\t!format.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\t// If national prefix is mandatory for this phone number format\r\n\t\t// and there're no guarantees that a national prefix is present in user input\r\n\t\t// then discard this phone number format as not suitable.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L185-L193\r\n\t\tif (!international &&\r\n\t\t\t!nationalPrefix &&\r\n\t\t\tformat.nationalPrefixIsMandatoryWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n\r\n\tformatMatches(format, leadingDigits, leadingDigitsPatternIndex) {\r\n\t\tconst leadingDigitsPatternsCount = format.leadingDigitsPatterns().length\r\n\r\n\t\t// If this format is not restricted to a certain\r\n\t\t// leading digits pattern then it fits.\r\n\t\tif (leadingDigitsPatternsCount === 0) {\r\n\t\t\treturn true\r\n\t\t}\r\n\r\n\t\t// Start narrowing down the list of possible formats based on the leading digits.\r\n\t\t// (only previously matched formats take part in the narrowing down process)\r\n\r\n\t\t// `leading_digits_patterns` start with 3 digits min\r\n\t\t// and then go up from there one digit at a time.\r\n\t\tleadingDigitsPatternIndex = Math.min(leadingDigitsPatternIndex, leadingDigitsPatternsCount - 1)\r\n\t\tconst leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex]\r\n\r\n\t\t// Google imposes a requirement on the leading digits\r\n\t\t// to be minimum 3 digits long in order to be eligible\r\n\t\t// for checking those with a leading digits pattern.\r\n\t\t//\r\n\t\t// Since `leading_digits_patterns` start with 3 digits min,\r\n\t\t// Google's original `libphonenumber` library only starts\r\n\t\t// excluding any non-matching formats only when the\r\n\t\t// national number entered so far is at least 3 digits long,\r\n\t\t// otherwise format matching would give false negatives.\r\n\t\t//\r\n\t\t// For example, when the digits entered so far are `2`\r\n\t\t// and the leading digits pattern is `21` –\r\n\t\t// it's quite obvious in this case that the format could be the one\r\n\t\t// but due to the absence of further digits it would give false negative.\r\n\t\t//\r\n\t\t// Also, `leading_digits_patterns` doesn't always correspond to a single\r\n\t\t// digits count. For example, `60|8` pattern would already match `8`\r\n\t\t// but the `60` part would require having at least two leading digits,\r\n\t\t// so the whole pattern would require inputting two digits first in order to\r\n\t\t// decide on whether it matches the input, even when the input is \"80\".\r\n\t\t//\r\n\t\t// This library — `libphonenumber-js` — allows filtering by `leading_digits_patterns`\r\n\t\t// even when there's only 1 or 2 digits of the national (significant) number.\r\n\t\t// To do that, it uses a non-strict pattern matcher written specifically for that.\r\n\t\t//\r\n\t\tif (leadingDigits.length < MIN_LEADING_DIGITS_LENGTH) {\r\n\t\t\t// Before leading digits < 3 matching was implemented:\r\n\t\t\t// return true\r\n\t\t\t//\r\n\t\t\t// After leading digits < 3 matching was implemented:\r\n\t\t\ttry {\r\n\t\t\t\treturn new PatternMatcher(leadingDigitsPattern).match(leadingDigits, { allowOverflow: true }) !== undefined\r\n\t\t\t} catch (error) {\r\n\t\t\t\t// There's a slight possibility that there could be some undiscovered bug\r\n\t\t\t\t// in the pattern matcher code. Since the \"leading digits < 3 matching\"\r\n\t\t\t\t// feature is not \"essential\" for operation, it can fall back to the old way\r\n\t\t\t\t// in case of any issues rather than halting the application's execution.\r\n\t\t\t\tconsole.error(error)\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are\r\n\t\t// available then use the usual regular expression matching.\r\n\t\t//\r\n\t\t// The whole pattern is wrapped in round brackets (`()`) because\r\n\t\t// the pattern can use \"or\" operator (`|`) at the top level of the pattern.\r\n\t\t//\r\n\t\treturn new RegExp(`^(${leadingDigitsPattern})`).test(leadingDigits)\r\n\t}\r\n\r\n\tgetFormatFormat(format, international) {\r\n\t\treturn international ? format.internationalFormat() : format.format()\r\n\t}\r\n\r\n\tchooseFormat(state) {\r\n\t\t// When there are multiple available formats, the formatter uses the first\r\n\t\t// format where a formatting template could be created.\r\n\t\tfor (const format of this.matchingFormats.slice()) {\r\n\t\t\t// If this format is currently being used\r\n\t\t\t// and is still suitable, then stick to it.\r\n\t\t\tif (this.chosenFormat === format) {\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\t// Sometimes, a formatting rule inserts additional digits in a phone number,\r\n\t\t\t// and \"as you type\" formatter can't do that: it should only use the digits\r\n\t\t\t// that the user has input.\r\n\t\t\t//\r\n\t\t\t// For example, in Argentina, there's a format for mobile phone numbers:\r\n\t\t\t//\r\n\t\t\t// {\r\n\t\t\t// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n\t\t\t// \"leading_digits_patterns\": [\"91\"],\r\n\t\t\t// \"national_prefix_formatting_rule\": \"0$1\",\r\n\t\t\t// \"format\": \"$2 15-$3-$4\",\r\n\t\t\t// \"international_format\": \"$1 $2 $3-$4\"\r\n\t\t\t// }\r\n\t\t\t//\r\n\t\t\t// In that format, `international_format` is used instead of `format`\r\n\t\t\t// because `format` inserts `15` in the formatted number,\r\n\t\t\t// and `AsYouType` formatter should only use the digits\r\n\t\t\t// the user has actually input, without adding any extra digits.\r\n\t\t\t// In this case, it wouldn't make a difference, because the `15`\r\n\t\t\t// is first stripped when applying `national_prefix_for_parsing`\r\n\t\t\t// and then re-added when using `format`, so in reality it doesn't\r\n\t\t\t// add any new digits to the number, but to detect that, the code\r\n\t\t\t// would have to be more complex: it would have to try formatting\r\n\t\t\t// the digits using the format and then see if any digits have\r\n\t\t\t// actually been added or removed, and then, every time a new digit\r\n\t\t\t// is input, it should re-check whether the chosen format doesn't\r\n\t\t\t// alter the digits.\r\n\t\t\t//\r\n\t\t\t// Google's code doesn't go that far, and so does this library:\r\n\t\t\t// it simply requires that a `format` doesn't add any additonal\r\n\t\t\t// digits to user's input.\r\n\t\t\t//\r\n\t\t\t// Also, people in general should move from inputting phone numbers\r\n\t\t\t// in national format (possibly with national prefixes)\r\n\t\t\t// and use international phone number format instead:\r\n\t\t\t// it's a logical thing in the modern age of mobile phones,\r\n\t\t\t// globalization and the internet.\r\n\t\t\t//\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (!NON_ALTERING_FORMAT_REG_EXP.test(this.getFormatFormat(format, state.international))) {\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tif (!this.createTemplateForFormat(format, state)) {\r\n\t\t\t\t// Remove the format if it can't generate a template.\r\n\t\t\t\tthis.matchingFormats = this.matchingFormats.filter(_ => _ !== format)\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tthis.chosenFormat = format\r\n\t\t\tbreak\r\n\t\t}\r\n\t\tif (!this.chosenFormat) {\r\n\t\t\t// No format matches the national (significant) phone number.\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t\treturn this.chosenFormat\r\n\t}\r\n\r\n\tcreateTemplateForFormat(format, state) {\r\n\t\t// The formatter doesn't format numbers when numberPattern contains '|', e.g.\r\n\t\t// (20|3)\\d{4}. In those cases we quickly return.\r\n\t\t// (Though there's no such format in current metadata)\r\n\t\t/* istanbul ignore if */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS && format.pattern().indexOf('|') >= 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Get formatting template for this phone number format\r\n\t\tconst template = this.getTemplateForFormat(format, state)\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (template) {\r\n\t\t\tthis.setNationalNumberTemplate(template, state)\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\r\n\tgetSeparatorAfterNationalPrefix = (format) => {\r\n\t\t// `US` metadata doesn't have a `national_prefix_formatting_rule`,\r\n\t\t// so the `if` condition below doesn't apply to `US`,\r\n\t\t// but in reality there shoudl be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\t// So `US` national prefix separator is a \"special\" \"hardcoded\" case.\r\n\t\tif (this.isNANP) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// If a `format` has a `national_prefix_formatting_rule`\r\n\t\t// and that rule has a separator after a national prefix,\r\n\t\t// then it means that there should be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\tif (format &&\r\n\t\t\tformat.nationalPrefixFormattingRule() &&\r\n\t\t\tNATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// At this point, there seems to be no clear evidence that\r\n\t\t// there should be a separator between a national prefix\r\n\t\t// and a national (significant) number. So don't insert one.\r\n\t\treturn ''\r\n\t}\r\n\r\n\tgetInternationalPrefixBeforeCountryCallingCode({ IDDPrefix, missingPlus }, options) {\r\n\t\tif (IDDPrefix) {\r\n\t\t\treturn options && options.spacing === false ? IDDPrefix : IDDPrefix + ' '\r\n\t\t}\r\n\t\tif (missingPlus) {\r\n\t\t\treturn ''\r\n\t\t}\r\n\t\treturn '+'\r\n\t}\r\n\r\n\tgetTemplate(state) {\r\n\t\tif (!this.template) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// `this.template` holds the template for a \"complete\" phone number.\r\n\t\t// The currently entered phone number is most likely not \"complete\",\r\n\t\t// so trim all non-populated digits.\r\n\t\tlet index = -1\r\n\t\tlet i = 0\r\n\t\tconst internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state, { spacing: false }) : ''\r\n\t\twhile (i < internationalPrefix.length + state.getDigitsWithoutInternationalPrefix().length) {\r\n\t\t\tindex = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1)\r\n\t\t\ti++\r\n\t\t}\r\n\t\treturn cutAndStripNonPairedParens(this.template, index + 1)\r\n\t}\r\n\r\n\tsetNationalNumberTemplate(template, state) {\r\n\t\tthis.nationalNumberTemplate = template\r\n\t\tthis.populatedNationalNumberTemplate = template\r\n\t\t// With a new formatting template, the matched position\r\n\t\t// using the old template needs to be reset.\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t\t// For convenience, the public `.template` property\r\n\t\t// contains the whole international number\r\n\t\t// if the phone number being input is international:\r\n\t\t// 'x' for the '+' sign, 'x'es for the country phone code,\r\n\t\t// a spacebar and then the template for the formatted national number.\r\n\t\tif (state.international) {\r\n\t\t\tthis.template =\r\n\t\t\t\tthis.getInternationalPrefixBeforeCountryCallingCode(state).replace(/[\\d\\+]/g, DIGIT_PLACEHOLDER) +\r\n\t\t\t\trepeat(DIGIT_PLACEHOLDER, state.callingCode.length) +\r\n\t\t\t\t' ' +\r\n\t\t\t\ttemplate\r\n\t\t} else {\r\n\t\t\tthis.template = template\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Generates formatting template for a national phone number,\r\n\t * optionally containing a national prefix, for a format.\r\n\t * @param {Format} format\r\n\t * @param {string} nationalPrefix\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplateForFormat(format, {\r\n\t\tnationalSignificantNumber,\r\n\t\tinternational,\r\n\t\tnationalPrefix,\r\n\t\tcomplexPrefixBeforeNationalSignificantNumber\r\n\t}) {\r\n\t\tlet pattern = format.pattern()\r\n\r\n\t\t/* istanbul ignore else */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS) {\r\n\t\t\tpattern = pattern\r\n\t\t\t\t// Replace anything in the form of [..] with \\d\r\n\t\t\t\t.replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\\\d')\r\n\t\t\t\t// Replace any standalone digit (not the one in `{}`) with \\d\r\n\t\t\t\t.replace(CREATE_STANDALONE_DIGIT_PATTERN(), '\\\\d')\r\n\t\t}\r\n\r\n\t\t// Generate a dummy national number (consisting of `9`s)\r\n\t\t// that fits this format's `pattern`.\r\n\t\t//\r\n\t\t// This match will always succeed,\r\n\t\t// because the \"longest dummy phone number\"\r\n\t\t// has enough length to accomodate any possible\r\n\t\t// national phone number format pattern.\r\n\t\t//\r\n\t\tlet digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0]\r\n\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (nationalSignificantNumber.length > digits.length) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// Get a formatting template which can be used to efficiently format\r\n\t\t// a partial number where digits are added one by one.\r\n\r\n\t\t// Below `strictPattern` is used for the\r\n\t\t// regular expression (with `^` and `$`).\r\n\t\t// This wasn't originally in Google's `libphonenumber`\r\n\t\t// and I guess they don't really need it\r\n\t\t// because they're not using \"templates\" to format phone numbers\r\n\t\t// but I added `strictPattern` after encountering\r\n\t\t// South Korean phone number formatting bug.\r\n\t\t//\r\n\t\t// Non-strict regular expression bug demonstration:\r\n\t\t//\r\n\t\t// this.nationalSignificantNumber : `111111111` (9 digits)\r\n\t\t//\r\n\t\t// pattern : (\\d{2})(\\d{3,4})(\\d{4})\r\n\t\t// format : `$1 $2 $3`\r\n\t\t// digits : `9999999999` (10 digits)\r\n\t\t//\r\n\t\t// '9999999999'.replace(new RegExp(/(\\d{2})(\\d{3,4})(\\d{4})/g), '$1 $2 $3') = \"99 9999 9999\"\r\n\t\t//\r\n\t\t// template : xx xxxx xxxx\r\n\t\t//\r\n\t\t// But the correct template in this case is `xx xxx xxxx`.\r\n\t\t// The template was generated incorrectly because of the\r\n\t\t// `{3,4}` variability in the `pattern`.\r\n\t\t//\r\n\t\t// The fix is, if `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then `this.nationalSignificantNumber`\r\n\t\t// is used instead of `digits`.\r\n\r\n\t\tconst strictPattern = new RegExp('^' + pattern + '$')\r\n\t\tconst nationalNumberDummyDigits = nationalSignificantNumber.replace(/\\d/g, DUMMY_DIGIT)\r\n\r\n\t\t// If `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then use it\r\n\t\t// instead of `digits`.\r\n\t\tif (strictPattern.test(nationalNumberDummyDigits)) {\r\n\t\t\tdigits = nationalNumberDummyDigits\r\n\t\t}\r\n\r\n\t\tlet numberFormat = this.getFormatFormat(format, international)\r\n\t\tlet nationalPrefixIncludedInTemplate\r\n\r\n\t\t// If a user did input a national prefix (and that's guaranteed),\r\n\t\t// and if a `format` does have a national prefix formatting rule,\r\n\t\t// then see if that national prefix formatting rule\r\n\t\t// prepends exactly the same national prefix the user has input.\r\n\t\t// If that's the case, then use the `format` with the national prefix formatting rule.\r\n\t\t// Otherwise, use the `format` without the national prefix formatting rule,\r\n\t\t// and prepend a national prefix manually to it.\r\n\t\tif (this.shouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix })) {\r\n\t\t\tconst numberFormatWithNationalPrefix = numberFormat.replace(\r\n\t\t\t\tFIRST_GROUP_PATTERN,\r\n\t\t\t\tformat.nationalPrefixFormattingRule()\r\n\t\t\t)\r\n\t\t\t// If `national_prefix_formatting_rule` of a `format` simply prepends\r\n\t\t\t// national prefix at the start of a national (significant) number,\r\n\t\t\t// then such formatting can be used with `AsYouType` formatter.\r\n\t\t\t// There seems to be no `else` case: everywhere in metadata,\r\n\t\t\t// national prefix formatting rule is national prefix + $1,\r\n\t\t\t// or `($1)`, in which case such format isn't even considered\r\n\t\t\t// when the user has input a national prefix.\r\n\t\t\t/* istanbul ignore else */\r\n\t\t\tif (parseDigits(format.nationalPrefixFormattingRule()) === (nationalPrefix || '') + parseDigits('$1')) {\r\n\t\t\t\tnumberFormat = numberFormatWithNationalPrefix\r\n\t\t\t\tnationalPrefixIncludedInTemplate = true\r\n\t\t\t\t// Replace all digits of the national prefix in the formatting template\r\n\t\t\t\t// with `DIGIT_PLACEHOLDER`s.\r\n\t\t\t\tif (nationalPrefix) {\r\n\t\t\t\t\tlet i = nationalPrefix.length\r\n\t\t\t\t\twhile (i > 0) {\r\n\t\t\t\t\t\tnumberFormat = numberFormat.replace(/\\d/, DIGIT_PLACEHOLDER)\r\n\t\t\t\t\t\ti--\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Generate formatting template for this phone number format.\r\n\t\tlet template = digits\r\n\t\t\t// Format the dummy phone number according to the format.\r\n\t\t\t.replace(new RegExp(pattern), numberFormat)\r\n\t\t\t// Replace each dummy digit with a DIGIT_PLACEHOLDER.\r\n\t\t\t.replace(new RegExp(DUMMY_DIGIT, 'g'), DIGIT_PLACEHOLDER)\r\n\r\n\t\t// If a prefix of a national (significant) number is not as simple\r\n\t\t// as just a basic national prefix, then just prepend such prefix\r\n\t\t// before the national (significant) number, optionally spacing\r\n\t\t// the two with a whitespace.\r\n\t\tif (!nationalPrefixIncludedInTemplate) {\r\n\t\t\tif (complexPrefixBeforeNationalSignificantNumber) {\r\n\t\t\t\t// Prepend the prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, complexPrefixBeforeNationalSignificantNumber.length) +\r\n\t\t\t\t\t' ' +\r\n\t\t\t\t\ttemplate\r\n\t\t\t} else if (nationalPrefix) {\r\n\t\t\t\t// Prepend national prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, nationalPrefix.length) +\r\n\t\t\t\t\tthis.getSeparatorAfterNationalPrefix(format) +\r\n\t\t\t\t\ttemplate\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (international) {\r\n\t\t\ttemplate = applyInternationalSeparatorStyle(template)\r\n\t\t}\r\n\r\n\t\treturn template\r\n\t}\r\n\r\n\tformatNextNationalNumberDigits(digits) {\r\n\t\tconst result = populateTemplateWithDigits(\r\n\t\t\tthis.populatedNationalNumberTemplate,\r\n\t\t\tthis.populatedNationalNumberTemplatePosition,\r\n\t\t\tdigits\r\n\t\t)\r\n\r\n\t\tif (!result) {\r\n\t\t\t// Reset the format.\r\n\t\t\tthis.resetFormat()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tthis.populatedNationalNumberTemplate = result[0]\r\n\t\tthis.populatedNationalNumberTemplatePosition = result[1]\r\n\r\n\t\t// Return the formatted phone number so far.\r\n\t\treturn cutAndStripNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\r\n\t\t// The old way which was good for `input-format` but is not so good\r\n\t\t// for `react-phone-number-input`'s default input (`InputBasic`).\r\n\t\t// return closeNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\t\t// \t.replace(new RegExp(DIGIT_PLACEHOLDER, 'g'), ' ')\r\n\t}\r\n\r\n\tshouldTryNationalPrefixFormattingRule = (format, { international, nationalPrefix }) => {\r\n\t\tif (format.nationalPrefixFormattingRule()) {\r\n\t\t\t// In some countries, `national_prefix_formatting_rule` is `($1)`,\r\n\t\t\t// so it applies even if the user hasn't input a national prefix.\r\n\t\t\t// `format.usesNationalPrefix()` detects such cases.\r\n\t\t\tconst usesNationalPrefix = format.usesNationalPrefix()\r\n\t\t\tif ((usesNationalPrefix && nationalPrefix) ||\r\n\t\t\t\t(!usesNationalPrefix && !international)) {\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}"],"file":"AsYouTypeFormatter.js"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _metadataMin = _interopRequireDefault(require("../metadata.min.json"));
|
|
4
4
|
|
|
5
5
|
var _PhoneNumber = _interopRequireDefault(require("./PhoneNumber"));
|
|
6
6
|
|
|
@@ -19,13 +19,13 @@ describe('PhoneNumber', function () {
|
|
|
19
19
|
}).to["throw"]('`metadata` not passed');
|
|
20
20
|
});
|
|
21
21
|
it('should accept country code argument', function () {
|
|
22
|
-
var phoneNumber = new _PhoneNumber["default"]('RU', '8005553535',
|
|
22
|
+
var phoneNumber = new _PhoneNumber["default"]('RU', '8005553535', _metadataMin["default"]);
|
|
23
23
|
phoneNumber.countryCallingCode.should.equal('7');
|
|
24
24
|
phoneNumber.country.should.equal('RU');
|
|
25
25
|
phoneNumber.number.should.equal('+78005553535');
|
|
26
26
|
});
|
|
27
27
|
it('should format number with options', function () {
|
|
28
|
-
var phoneNumber = new _PhoneNumber["default"]('7', '8005553535',
|
|
28
|
+
var phoneNumber = new _PhoneNumber["default"]('7', '8005553535', _metadataMin["default"]);
|
|
29
29
|
phoneNumber.ext = '123';
|
|
30
30
|
phoneNumber.format('NATIONAL', {
|
|
31
31
|
formatExtension: function formatExtension(number, extension) {
|
|
@@ -34,16 +34,16 @@ describe('PhoneNumber', function () {
|
|
|
34
34
|
}).should.equal('8 (800) 555-35-35 доб. 123');
|
|
35
35
|
});
|
|
36
36
|
it('should compare phone numbers', function () {
|
|
37
|
-
new _PhoneNumber["default"]('RU', '8005553535',
|
|
38
|
-
new _PhoneNumber["default"]('RU', '8005553535',
|
|
39
|
-
new _PhoneNumber["default"]('RU', '8005553535',
|
|
37
|
+
new _PhoneNumber["default"]('RU', '8005553535', _metadataMin["default"]).isEqual(new _PhoneNumber["default"]('RU', '8005553535', _metadataMin["default"])).should.equal(true);
|
|
38
|
+
new _PhoneNumber["default"]('RU', '8005553535', _metadataMin["default"]).isEqual(new _PhoneNumber["default"]('7', '8005553535', _metadataMin["default"])).should.equal(true);
|
|
39
|
+
new _PhoneNumber["default"]('RU', '8005553535', _metadataMin["default"]).isEqual(new _PhoneNumber["default"]('RU', '8005553536', _metadataMin["default"])).should.equal(false);
|
|
40
40
|
});
|
|
41
41
|
it('should tell if a number is non-geographic', function () {
|
|
42
|
-
new _PhoneNumber["default"]('7', '8005553535',
|
|
43
|
-
new _PhoneNumber["default"]('870', '773111632',
|
|
42
|
+
new _PhoneNumber["default"]('7', '8005553535', _metadataMin["default"]).isNonGeographic().should.equal(false);
|
|
43
|
+
new _PhoneNumber["default"]('870', '773111632', _metadataMin["default"]).isNonGeographic().should.equal(true);
|
|
44
44
|
});
|
|
45
45
|
it('should allow setting extension', function () {
|
|
46
|
-
var phoneNumber = new _PhoneNumber["default"]('1', '2133734253',
|
|
46
|
+
var phoneNumber = new _PhoneNumber["default"]('1', '2133734253', _metadataMin["default"]);
|
|
47
47
|
phoneNumber.setExt('1234');
|
|
48
48
|
phoneNumber.ext.should.equal('1234');
|
|
49
49
|
phoneNumber.formatNational().should.equal('(213) 373-4253 ext. 1234');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/PhoneNumber.test.js"],"names":["describe","it","expect","PhoneNumber","to","phoneNumber","metadata","countryCallingCode","should","equal","country","number","ext","format","formatExtension","extension","isEqual","isNonGeographic","setExt","formatNational"],"mappings":";;AAAA;;AACA;;;;AAEAA,QAAQ,CAAC,aAAD,EAAgB,YAAM;AAC7BC,EAAAA,EAAE,CAAC,uCAAD,EAA0C,YAAM;AACjDC,IAAAA,MAAM,CAAC;AAAA,aAAM,IAAIC,uBAAJ,EAAN;AAAA,KAAD,CAAN,CAAgCC,EAAhC,UAAyC,iCAAzC;AACAF,IAAAA,MAAM,CAAC;AAAA,aAAM,IAAIC,uBAAJ,CAAgB,GAAhB,CAAN;AAAA,KAAD,CAAN,CAAmCC,EAAnC,UAA4C,6BAA5C;AACAF,IAAAA,MAAM,CAAC;AAAA,aAAM,IAAIC,uBAAJ,CAAgB,GAAhB,EAAqB,YAArB,CAAN;AAAA,KAAD,CAAN,CAAiDC,EAAjD,UAA0D,uBAA1D;AACA,GAJC,CAAF;AAMAH,EAAAA,EAAE,CAAC,qCAAD,EAAwC,YAAM;AAC/C,QAAMI,WAAW,GAAG,IAAIF,uBAAJ,CAAgB,IAAhB,EAAsB,YAAtB,EAAoCG,
|
|
1
|
+
{"version":3,"sources":["../source/PhoneNumber.test.js"],"names":["describe","it","expect","PhoneNumber","to","phoneNumber","metadata","countryCallingCode","should","equal","country","number","ext","format","formatExtension","extension","isEqual","isNonGeographic","setExt","formatNational"],"mappings":";;AAAA;;AACA;;;;AAEAA,QAAQ,CAAC,aAAD,EAAgB,YAAM;AAC7BC,EAAAA,EAAE,CAAC,uCAAD,EAA0C,YAAM;AACjDC,IAAAA,MAAM,CAAC;AAAA,aAAM,IAAIC,uBAAJ,EAAN;AAAA,KAAD,CAAN,CAAgCC,EAAhC,UAAyC,iC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adata.min.json'\r\nimport PhoneNumber from './PhoneNumber'\r\n\r\ndescribe('PhoneNumber', () => {\r\n\tit('should validate constructor arguments', () => {\r\n\t\texpect(() => new PhoneNumber()).to.throw('`countryCallingCode` not passed')\r\n\t\texpect(() => new PhoneNumber('7')).to.throw('`nationalNumber` not passed')\r\n\t\texpect(() => new PhoneNumber('7', '8005553535')).to.throw('`metadata` not passed')\r\n\t})\r\n\r\n\tit('should accept country code argument', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('RU', '8005553535', metadata)\r\n\t\tphoneNumber.countryCallingCode.should.equal('7')\r\n\t\tphoneNumber.country.should.equal('RU')\r\n\t\tphoneNumber.number.should.equal('+78005553535')\r\n\t})\r\n\r\n\tit('should format number with options', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('7', '8005553535', metadata)\r\n\t\tphoneNumber.ext = '123'\r\n\t\tphoneNumber.format('NATIONAL', {\r\n\t\t\tformatExtension: (number, extension) => `${number} доб. ${extension}`\r\n\t\t})\r\n\t\t.should.equal('8 (800) 555-35-35 доб. 123')\r\n\t})\r\n\r\n\tit('should compare phone numbers', () => {\r\n\t\tnew PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('RU', '8005553535', metadata)).should.equal(true)\r\n\t\tnew PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('7', '8005553535', metadata)).should.equal(true)\r\n\t\tnew PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('RU', '8005553536', metadata)).should.equal(false)\r\n\t})\r\n\r\n\tit('should tell if a number is non-geographic', () => {\r\n\t\tnew PhoneNumber('7', '8005553535', metadata).isNonGeographic().should.equal(false)\r\n\t\tnew PhoneNumber('870', '773111632', metadata).isNonGeographic().should.equal(true)\r\n\t})\r\n\r\n\tit('should allow setting extension', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('1', '2133734253', metadata)\r\n\t\tphoneNumber.setExt('1234')\r\n\t\tphoneNumber.ext.should.equal('1234')\r\n\t\tphoneNumber.formatNational().should.equal('(213) 373-4253 ext. 1234')\r\n\t})\r\n})"],"file":"PhoneNumber.test.js"}
|
|
@@ -2,25 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
var _findNumbers = _interopRequireDefault(require("./findNumbers"));
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _metadataMax = _interopRequireDefault(require("../metadata.max.json"));
|
|
6
6
|
|
|
7
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
8
8
|
|
|
9
9
|
describe('findNumbers', function () {
|
|
10
10
|
it('should find numbers', function () {
|
|
11
|
-
(0, _findNumbers["default"])('2133734253', 'US',
|
|
11
|
+
(0, _findNumbers["default"])('2133734253', 'US', _metadataMax["default"]).should.deep.equal([{
|
|
12
12
|
phone: '2133734253',
|
|
13
13
|
country: 'US',
|
|
14
14
|
startsAt: 0,
|
|
15
15
|
endsAt: 10
|
|
16
16
|
}]);
|
|
17
|
-
(0, _findNumbers["default"])('(213) 373-4253', 'US',
|
|
17
|
+
(0, _findNumbers["default"])('(213) 373-4253', 'US', _metadataMax["default"]).should.deep.equal([{
|
|
18
18
|
phone: '2133734253',
|
|
19
19
|
country: 'US',
|
|
20
20
|
startsAt: 0,
|
|
21
21
|
endsAt: 14
|
|
22
22
|
}]);
|
|
23
|
-
(0, _findNumbers["default"])('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US',
|
|
23
|
+
(0, _findNumbers["default"])('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', _metadataMax["default"]).should.deep.equal([{
|
|
24
24
|
phone: '8005553535',
|
|
25
25
|
country: 'RU',
|
|
26
26
|
startsAt: 14,
|
|
@@ -33,7 +33,7 @@ describe('findNumbers', function () {
|
|
|
33
33
|
}]); // Opening parenthesis issue.
|
|
34
34
|
// https://github.com/catamphetamine/libphonenumber-js/issues/252
|
|
35
35
|
|
|
36
|
-
(0, _findNumbers["default"])('The number is +7 (800) 555-35-35 and not (213) 373-4253 (that\'s not even in the same country!) as written in the document.', 'US',
|
|
36
|
+
(0, _findNumbers["default"])('The number is +7 (800) 555-35-35 and not (213) 373-4253 (that\'s not even in the same country!) as written in the document.', 'US', _metadataMax["default"]).should.deep.equal([{
|
|
37
37
|
phone: '8005553535',
|
|
38
38
|
country: 'RU',
|
|
39
39
|
startsAt: 14,
|
|
@@ -45,7 +45,7 @@ describe('findNumbers', function () {
|
|
|
45
45
|
endsAt: 55
|
|
46
46
|
}]); // No default country.
|
|
47
47
|
|
|
48
|
-
(0, _findNumbers["default"])('The number is +7 (800) 555-35-35 as written in the document.',
|
|
48
|
+
(0, _findNumbers["default"])('The number is +7 (800) 555-35-35 as written in the document.', _metadataMax["default"]).should.deep.equal([{
|
|
49
49
|
phone: '8005553535',
|
|
50
50
|
country: 'RU',
|
|
51
51
|
startsAt: 14,
|
|
@@ -54,7 +54,7 @@ describe('findNumbers', function () {
|
|
|
54
54
|
|
|
55
55
|
(0, _findNumbers["default"])('The number is +7 (800) 555-35-35 as written in the document.', 'US', {
|
|
56
56
|
leniency: 'VALID'
|
|
57
|
-
},
|
|
57
|
+
}, _metadataMax["default"]).should.deep.equal([{
|
|
58
58
|
phone: '8005553535',
|
|
59
59
|
country: 'RU',
|
|
60
60
|
startsAt: 14,
|
|
@@ -63,7 +63,7 @@ describe('findNumbers', function () {
|
|
|
63
63
|
|
|
64
64
|
(0, _findNumbers["default"])('The number is +7 (800) 555-35-35 as written in the document.', {
|
|
65
65
|
leniency: 'VALID'
|
|
66
|
-
},
|
|
66
|
+
}, _metadataMax["default"]).should.deep.equal([{
|
|
67
67
|
phone: '8005553535',
|
|
68
68
|
country: 'RU',
|
|
69
69
|
startsAt: 14,
|
|
@@ -72,7 +72,7 @@ describe('findNumbers', function () {
|
|
|
72
72
|
|
|
73
73
|
(0, _findNumbers["default"])('Digits 12 are not a number, but +7 (800) 555-35-35 is.', {
|
|
74
74
|
leniency: 'VALID'
|
|
75
|
-
},
|
|
75
|
+
}, _metadataMax["default"]).should.deep.equal([{
|
|
76
76
|
phone: '8005553535',
|
|
77
77
|
country: 'RU',
|
|
78
78
|
startsAt: 32,
|
|
@@ -81,7 +81,7 @@ describe('findNumbers', function () {
|
|
|
81
81
|
|
|
82
82
|
(0, _findNumbers["default"])('Date 02/17/2018 is not a number, but +7 (800) 555-35-35 ext. 123 is.', {
|
|
83
83
|
leniency: 'VALID'
|
|
84
|
-
},
|
|
84
|
+
}, _metadataMax["default"]).should.deep.equal([{
|
|
85
85
|
phone: '8005553535',
|
|
86
86
|
country: 'RU',
|
|
87
87
|
ext: '123',
|
|
@@ -92,7 +92,7 @@ describe('findNumbers', function () {
|
|
|
92
92
|
it('should find numbers (v2)', function () {
|
|
93
93
|
var phoneNumbers = (0, _findNumbers["default"])('The number is +7 (800) 555-35-35 ext. 1234 and not (213) 373-4253 as written in the document.', 'US', {
|
|
94
94
|
v2: true
|
|
95
|
-
},
|
|
95
|
+
}, _metadataMax["default"]);
|
|
96
96
|
phoneNumbers.length.should.equal(2);
|
|
97
97
|
phoneNumbers[0].startsAt.should.equal(14);
|
|
98
98
|
phoneNumbers[0].endsAt.should.equal(42);
|
|
@@ -110,11 +110,11 @@ describe('findNumbers', function () {
|
|
|
110
110
|
});
|
|
111
111
|
it('shouldn\'t find non-valid numbers', function () {
|
|
112
112
|
// Not a valid phone number for US.
|
|
113
|
-
(0, _findNumbers["default"])('1111111111', 'US',
|
|
113
|
+
(0, _findNumbers["default"])('1111111111', 'US', _metadataMax["default"]).should.deep.equal([]);
|
|
114
114
|
});
|
|
115
115
|
it('should find non-European digits', function () {
|
|
116
116
|
// E.g. in Iraq they don't write `+442323234` but rather `+٤٤٢٣٢٣٢٣٤`.
|
|
117
|
-
(0, _findNumbers["default"])('العَرَبِيَّة +٤٤٣٣٣٣٣٣٣٣٣٣عَرَبِيّ',
|
|
117
|
+
(0, _findNumbers["default"])('العَرَبِيَّة +٤٤٣٣٣٣٣٣٣٣٣٣عَرَبِيّ', _metadataMax["default"]).should.deep.equal([{
|
|
118
118
|
country: 'GB',
|
|
119
119
|
phone: '3333333333',
|
|
120
120
|
startsAt: 14,
|
|
@@ -124,7 +124,7 @@ describe('findNumbers', function () {
|
|
|
124
124
|
it('should work in edge cases', function () {
|
|
125
125
|
var thrower; // No input
|
|
126
126
|
|
|
127
|
-
(0, _findNumbers["default"])('',
|
|
127
|
+
(0, _findNumbers["default"])('', _metadataMax["default"]).should.deep.equal([]); // // No country metadata for this `require` country code
|
|
128
128
|
// thrower = () => findNumbers('123', 'ZZ', metadata)
|
|
129
129
|
// thrower.should.throw('Unknown country')
|
|
130
130
|
// Numerical `value`
|
|
@@ -144,26 +144,26 @@ describe('findNumbers', function () {
|
|
|
144
144
|
var numbers = (0, _findNumbers["default"])('Phone: +7 (800) 555 35 35. National: 8 (800) 555-55-55', {
|
|
145
145
|
defaultCountry: 'XX',
|
|
146
146
|
v2: true
|
|
147
|
-
},
|
|
147
|
+
}, _metadataMax["default"]);
|
|
148
148
|
numbers.length.should.equal(1);
|
|
149
149
|
numbers[0].number.nationalNumber.should.equal('8005553535');
|
|
150
150
|
});
|
|
151
151
|
it('shouldn\'t find phone numbers which are not phone numbers', function () {
|
|
152
152
|
// A timestamp.
|
|
153
|
-
(0, _findNumbers["default"])('2012-01-02 08:00', 'US',
|
|
153
|
+
(0, _findNumbers["default"])('2012-01-02 08:00', 'US', _metadataMax["default"]).should.deep.equal([]); // A valid number (not a complete timestamp).
|
|
154
154
|
|
|
155
|
-
(0, _findNumbers["default"])('2012-01-02 08', 'US',
|
|
155
|
+
(0, _findNumbers["default"])('2012-01-02 08', 'US', _metadataMax["default"]).should.deep.equal([{
|
|
156
156
|
country: 'US',
|
|
157
157
|
phone: '2012010208',
|
|
158
158
|
startsAt: 0,
|
|
159
159
|
endsAt: 13
|
|
160
160
|
}]); // Invalid parens.
|
|
161
161
|
|
|
162
|
-
(0, _findNumbers["default"])('213(3734253', 'US',
|
|
162
|
+
(0, _findNumbers["default"])('213(3734253', 'US', _metadataMax["default"]).should.deep.equal([]); // Letters after phone number.
|
|
163
163
|
|
|
164
|
-
(0, _findNumbers["default"])('2133734253a', 'US',
|
|
164
|
+
(0, _findNumbers["default"])('2133734253a', 'US', _metadataMax["default"]).should.deep.equal([]); // Valid phone (same as the one found in the UUID below).
|
|
165
165
|
|
|
166
|
-
(0, _findNumbers["default"])('The phone number is 231354125.', 'FR',
|
|
166
|
+
(0, _findNumbers["default"])('The phone number is 231354125.', 'FR', _metadataMax["default"]).should.deep.equal([{
|
|
167
167
|
country: 'FR',
|
|
168
168
|
phone: '231354125',
|
|
169
169
|
startsAt: 20,
|
|
@@ -173,17 +173,17 @@ describe('findNumbers', function () {
|
|
|
173
173
|
|
|
174
174
|
var possibleNumbers = (0, _findNumbers["default"])('The UUID is CA801c26f98cd16e231354125ad046e40b.', 'FR', {
|
|
175
175
|
extended: true
|
|
176
|
-
},
|
|
176
|
+
}, _metadataMax["default"]);
|
|
177
177
|
possibleNumbers.length.should.equal(1);
|
|
178
178
|
possibleNumbers[0].country.should.equal('FR');
|
|
179
179
|
possibleNumbers[0].phone.should.equal('231354125'); // Not a phone number (part of a UUID).
|
|
180
180
|
// Shouldn't parse by default.
|
|
181
181
|
|
|
182
|
-
(0, _findNumbers["default"])('The UUID is CA801c26f98cd16e231354125ad046e40b.', 'FR',
|
|
182
|
+
(0, _findNumbers["default"])('The UUID is CA801c26f98cd16e231354125ad046e40b.', 'FR', _metadataMax["default"]).should.deep.equal([]);
|
|
183
183
|
}); // https://gitlab.com/catamphetamine/libphonenumber-js/-/merge_requests/4
|
|
184
184
|
|
|
185
185
|
it('should return correct `startsAt` and `endsAt` when matching "inner" candidates in a could-be-a-candidate substring', function () {
|
|
186
|
-
(0, _findNumbers["default"])('39945926 77200596 16533084', 'ID',
|
|
186
|
+
(0, _findNumbers["default"])('39945926 77200596 16533084', 'ID', _metadataMax["default"]).should.deep.equal([{
|
|
187
187
|
country: 'ID',
|
|
188
188
|
phone: '77200596',
|
|
189
189
|
startsAt: 9,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/findNumbers.test.js"],"names":["describe","it","metadata","should","deep","equal","phone","country","startsAt","endsAt","leniency","ext","phoneNumbers","v2","length","number","nationalNumber","countryCallingCode","thrower","numbers","defaultCountry","possibleNumbers","extended"],"mappings":";;AAAA;;AACA;;;;AAEAA,QAAQ,CAAC,aAAD,EAAgB,YAAM;AAC7BC,EAAAA,EAAE,CAAC,qBAAD,EAAwB,YAAM;AAC/B,iCAAY,YAAZ,EAA0B,IAA1B,EAAgCC,wBAAhC,EAA0CC,MAA1C,CAAiDC,IAAjD,CAAsDC,KAAtD,CAA4D,CAAC;AAC5DC,MAAAA,KAAK,EAAM,YADiD;AAE5DC,MAAAA,OAAO,EAAI,IAFiD;AAG5DC,MAAAA,QAAQ,EAAG,CAHiD;AAI5DC,MAAAA,MAAM,EAAK;AAJiD,KAAD,CAA5D;AAOA,iCAAY,gBAAZ,EAA8B,IAA9B,EAAoCP,wBAApC,EAA8CC,MAA9C,CAAqDC,IAArD,CAA0DC,KAA1D,CAAgE,CAAC;AAChEC,MAAAA,KAAK,EAAM,YADqD;AAEhEC,MAAAA,OAAO,EAAI,IAFqD;AAGhEC,MAAAA,QAAQ,EAAG,CAHqD;AAIhEC,MAAAA,MAAM,EAAK;AAJqD,KAAD,CAAhE;AAOA,iCAAY,qFAAZ,EAAmG,IAAnG,EAAyGP,wBAAzG,EAAmHC,MAAnH,CAA0HC,IAA1H,CAA+HC,KAA/H,CAAqI,CAAC;AACrIC,MAAAA,KAAK,EAAM,YAD0H;AAErIC,MAAAA,OAAO,EAAI,IAF0H;AAGrIC,MAAAA,QAAQ,EAAG,EAH0H;AAIrIC,MAAAA,MAAM,EAAK;AAJ0H,KAAD,EAKlI;AACFH,MAAAA,KAAK,EAAM,YADT;AAEFC,MAAAA,OAAO,EAAI,IAFT;AAGFC,MAAAA,QAAQ,EAAG,EAHT;AAIFC,MAAAA,MAAM,EAAK;AAJT,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eAAe,GAAG,6BAAY,iDAAZ,EAA+D,IAA/D,EAAqE;AAAEC,MAAAA,QAAQ,EAAE;AAAZ,KAArE,EAAyFpB,wBAAzF,CAAxB;AACAmB,IAAAA,eAAe,CAACP,MAAhB,CAAuBX,MAAvB,CAA8BE,KAA9B,CAAoC,CAApC;AACAgB,IAAAA,eAAe,CAAC,CAAD,CAAf,CAAmBd,OAAnB,CAA2BJ,MAA3B,CAAkCE,KAAlC,CAAwC,IAAxC;AACAgB,IAAAA,eAAe,CAAC,CAAD,CAAf,CAAmBf,KAAnB,CAAyBH,MAAzB,CAAgCE,KAAhC,CAAsC,WAAtC,EA/BqE,CAiCrE;AACA;;AACA,iCAAY,iDAAZ,EAA+D,IAA/D,EAAqEH,wBAArE,EAA+EC,MAA/E,CAAsFC,IAAtF,CAA2FC,KAA3F,CAAiG,EAAjG;AACA,GApCC,CAAF,CAtJ6B,CA4L7B;;AACAJ,EAAAA,EAAE,CAAC,oHAAD,EAAuH,YAAM;AAC9H,iCAAY,4BAAZ,EAA0C,IAA1C,EAAgDC,wBAAhD,EACEC,MADF,CAEEC,IAFF,CAGEC,KAHF,CAGQ,CAAC;AACPE,MAAAA,OAAO,EAAE,IADF;AAEPD,MAAAA,KAAK,EAAE,UAFA;AAGPE,MAAAA,QAAQ,EAAE,CAHH;AAIPC,MAAAA,MAAM,EAAE;AAJD,KAAD,CAHR;AASA,GAVC,CAAF;AAWA,CAxMO,CAAR","sourcesContent":["import findNumbers from './findNumbers'\r\nimport metadata from '../metadata.full.json'\r\n\r\ndescribe('findNumbers', () => {\r\n\tit('should find numbers', () => {\r\n\t\tfindNumbers('2133734253', 'US', metadata).should.deep.equal([{\r\n\t\t\tphone : '2133734253',\r\n\t\t\tcountry : 'US',\r\n\t\t\tstartsAt : 0,\r\n\t\t\tendsAt : 10\r\n\t\t}])\r\n\r\n\t\tfindNumbers('(213) 373-4253', 'US', metadata).should.deep.equal([{\r\n\t\t\tphone : '2133734253',\r\n\t\t\tcountry : 'US',\r\n\t\t\tstartsAt : 0,\r\n\t\t\tendsAt : 14\r\n\t\t}])\r\n\r\n\t\tfindNumbers('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', metadata).should.deep.equal([{\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\tstartsAt : 14,\r\n\t\t\tendsAt : 32\r\n\t\t}, {\r\n\t\t\tphone : '2133734253',\r\n\t\t\tcountry : 'US',\r\n\t\t\tstartsAt : 41,\r\n\t\t\tendsAt : 55\r\n\t\t}])\r\n\r\n\t\t// Opening parenthesis issue.\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/252\r\n\t\tfindNumbers('The number is +7 (800) 555-35-35 and not (213) 373-4253 (that\\'s not even in the same country!) as written in the document.', 'US', metadata).should.deep.equal([{\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\tstartsAt : 14,\r\n\t\t\tendsAt : 32\r\n\t\t}, {\r\n\t\t\tphone : '2133734253',\r\n\t\t\tcountry : 'US',\r\n\t\t\tstartsAt : 41,\r\n\t\t\tendsAt : 55\r\n\t\t}])\r\n\r\n\t\t// No default country.\r\n\t\tfindNumbers('The number is +7 (800) 555-35-35 as written in the document.', metadata).should.deep.equal([{\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\tstartsAt : 14,\r\n\t\t\tendsAt : 32\r\n\t\t}])\r\n\r\n\t\t// Passing `options` and default country.\r\n\t\tfindNumbers('The number is +7 (800) 555-35-35 as written in the document.', 'US', { leniency: 'VALID' }, metadata).should.deep.equal([{\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\tstartsAt : 14,\r\n\t\t\tendsAt : 32\r\n\t\t}])\r\n\r\n\t\t// Passing `options`.\r\n\t\tfindNumbers('The number is +7 (800) 555-35-35 as written in the document.', { leniency: 'VALID' }, metadata).should.deep.equal([{\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\tstartsAt : 14,\r\n\t\t\tendsAt : 32\r\n\t\t}])\r\n\r\n\t\t// Not a phone number and a phone number.\r\n\t\tfindNumbers('Digits 12 are not a number, but +7 (800) 555-35-35 is.', { leniency: 'VALID' }, metadata).should.deep.equal([{\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\tstartsAt : 32,\r\n\t\t\tendsAt : 50\r\n\t\t}])\r\n\r\n\t\t// Phone number extension.\r\n\t\tfindNumbers('Date 02/17/2018 is not a number, but +7 (800) 555-35-35 ext. 123 is.', { leniency: 'VALID' }, metadata).should.deep.equal([{\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\text : '123',\r\n\t\t\tstartsAt : 37,\r\n\t\t\tendsAt : 64\r\n\t\t}])\r\n\t})\r\n\r\n\tit('should find numbers (v2)', () => {\r\n\t\tconst phoneNumbers = findNumbers('The number is +7 (800) 555-35-35 ext. 1234 and not (213) 373-4253 as written in the document.', 'US', { v2: true }, metadata)\r\n\r\n\t\tphoneNumbers.length.should.equal(2)\r\n\r\n\t\tphoneNumbers[0].startsAt.should.equal(14)\r\n\t\tphoneNumbers[0].endsAt.should.equal(42)\r\n\r\n\t\tphoneNumbers[0].number.number.should.equal('+78005553535')\r\n\t\tphoneNumbers[0].number.nationalNumber.should.equal('8005553535')\r\n\t\tphoneNumbers[0].number.country.should.equal('RU')\r\n\t\tphoneNumbers[0].number.countryCallingCode.should.equal('7')\r\n\t\tphoneNumbers[0].number.ext.should.equal('1234')\r\n\r\n\t\tphoneNumbers[1].startsAt.should.equal(51)\r\n\t\tphoneNumbers[1].endsAt.should.equal(65)\r\n\r\n\t\tphoneNumbers[1].number.number.should.equal('+12133734253')\r\n\t\tphoneNumbers[1].number.nationalNumber.should.equal('2133734253')\r\n\t\tphoneNumbers[1].number.country.should.equal('US')\r\n\t\tphoneNumbers[1].number.countryCallingCode.should.equal('1')\r\n\t})\r\n\r\n\tit('shouldn\\'t find non-valid numbers', () => {\r\n\t\t// Not a valid phone number for US.\r\n\t\tfindNumbers('1111111111', 'US', metadata).should.deep.equal([])\r\n\t})\r\n\r\n\tit('should find non-European digits', () => {\r\n\t\t// E.g. in Iraq they don't write `+442323234` but rather `+٤٤٢٣٢٣٢٣٤`.\r\n\t\tfindNumbers('العَرَبِيَّة +٤٤٣٣٣٣٣٣٣٣٣٣عَرَبِيّ', metadata).should.deep.equal([{\r\n\t\t\tcountry : 'GB',\r\n\t\t\tphone : '3333333333',\r\n\t\t\tstartsAt : 14,\r\n\t\t\tendsAt : 27\r\n\t\t}])\r\n\t})\r\n\r\n\tit('should work in edge cases', () => {\r\n\t\tlet thrower\r\n\r\n\t\t// No input\r\n\t\tfindNumbers('', metadata).should.deep.equal([])\r\n\r\n\t\t// // No country metadata for this `require` country code\r\n\t\t// thrower = () => findNumbers('123', 'ZZ', metadata)\r\n\t\t// thrower.should.throw('Unknown country')\r\n\r\n\t\t// Numerical `value`\r\n\t\tthrower = () => findNumbers(2141111111, 'US')\r\n\t\tthrower.should.throw('A text for parsing must be a string.')\r\n\r\n\t\t// // No metadata\r\n\t\t// thrower = () => findNumbers('')\r\n\t\t// thrower.should.throw('`metadata` argument not passed')\r\n\r\n\t\t// No metadata, no default country, no phone numbers.\r\n\t\tfindNumbers('').should.deep.equal([])\r\n\t})\r\n\r\n\tit('should find international numbers when passed a non-existent default country', () => {\r\n\t\tconst numbers = findNumbers('Phone: +7 (800) 555 35 35. National: 8 (800) 555-55-55', { defaultCountry: 'XX', v2: true }, metadata)\r\n\t\tnumbers.length.should.equal(1)\r\n\t\tnumbers[0].number.nationalNumber.should.equal('8005553535')\r\n\t})\r\n\r\n\tit('shouldn\\'t find phone numbers which are not phone numbers', () => {\r\n\t\t// A timestamp.\r\n\t\tfindNumbers('2012-01-02 08:00', 'US', metadata).should.deep.equal([])\r\n\r\n\t\t// A valid number (not a complete timestamp).\r\n\t\tfindNumbers('2012-01-02 08', 'US', metadata).should.deep.equal([{\r\n\t\t\tcountry : 'US',\r\n\t\t\tphone : '2012010208',\r\n\t\t\tstartsAt : 0,\r\n\t\t\tendsAt : 13\r\n\t\t}])\r\n\r\n\t\t// Invalid parens.\r\n\t\tfindNumbers('213(3734253', 'US', metadata).should.deep.equal([])\r\n\r\n\t\t// Letters after phone number.\r\n\t\tfindNumbers('2133734253a', 'US', metadata).should.deep.equal([])\r\n\r\n\t\t// Valid phone (same as the one found in the UUID below).\r\n\t\tfindNumbers('The phone number is 231354125.', 'FR', metadata).should.deep.equal([{\r\n\t\t\tcountry : 'FR',\r\n\t\t\tphone : '231354125',\r\n\t\t\tstartsAt : 20,\r\n\t\t\tendsAt : 29\r\n\t\t}])\r\n\r\n\t\t// Not a phone number (part of a UUID).\r\n\t\t// Should parse in `{ extended: true }` mode.\r\n\t\tconst possibleNumbers = findNumbers('The UUID is CA801c26f98cd16e231354125ad046e40b.', 'FR', { extended: true }, metadata)\r\n\t\tpossibleNumbers.length.should.equal(1)\r\n\t\tpossibleNumbers[0].country.should.equal('FR')\r\n\t\tpossibleNumbers[0].phone.should.equal('231354125')\r\n\r\n\t\t// Not a phone number (part of a UUID).\r\n\t\t// Shouldn't parse by default.\r\n\t\tfindNumbers('The UUID is CA801c26f98cd16e231354125ad046e40b.', 'FR', metadata).should.deep.equal([])\r\n\t})\r\n\r\n\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/merge_requests/4\r\n\tit('should return correct `startsAt` and `endsAt` when matching \"inner\" candidates in a could-be-a-candidate substring', () => {\r\n\t\tfindNumbers('39945926 77200596 16533084', 'ID', metadata)\r\n\t\t\t.should\r\n\t\t\t.deep\r\n\t\t\t.equal([{\r\n\t\t\t\tcountry: 'ID',\r\n\t\t\t\tphone: '77200596',\r\n\t\t\t\tstartsAt: 9,\r\n\t\t\t\tendsAt: 17\r\n\t\t\t}])\r\n\t})\r\n})"],"file":"findNumbers.test.js"}
|
|
1
|
+
{"version":3,"sources":["../source/findNumbers.test.js"],"names":["describe","it","metadata","should","deep","equal","phone","country","startsAt","endsAt","leniency","ext","phoneNumbers","v2","length","number","nationalNumber","countryCallingCode","thrower","numbers","defaultCountry","possibleNumbers","extended"],"mappings":";;AAAA;;AACA;;;;AAEAA,QAAQ,CAAC,aAAD,EAAgB,YAAM;AAC7BC,EAAAA,EAAE,CAAC,qBAAD,EAAwB,YAAM;AAC/B,iCAAY,YAAZ,EAA0B,IAA1B,EAAgCC,uBAAhC,EAA0CC,MAA1C,CAAiDC,IAAjD,CAAsDC,KAAtD,CAA4D,CAAC;AAC5DC,MAAAA,KAAK,EAAM,YADiD;AAE5DC,MAAAA,OAAO,EAAI,IAFiD;AAG5DC,MAAAA,QAAQ,EAAG,CAHiD;AAI5DC,MAAAA,MAAM,EAAK;AAJiD,KAAD,CAA5D;AAOA,iCAAY,gBAAZ,EAA8B,IAA9B,EAAoCP,uBAApC,EAA8CC,MAA9C,CAAqDC,IAArD,CAA0DC,KAA1D,CAAgE,CAAC;AAChEC,MAAAA,KAAK,EAAM,YADqD;AAEhEC,MAAAA,OAAO,EAAI,IAFqD;AAGhEC,MAAAA,QAAQ,EAAG,CAHqD;AAIhEC,MAAAA,MAAM,EAAK;AAJqD,KAAD,CAAhE;AAOA,iCAAY,qFAAZ,EAAmG,IAAnG,EAAyGP,uBAAzG,EAAmHC,MAAnH,CAA0HC,IAA1H,CAA+HC,KAA/H,CAAqI,CAAC;AACrIC,MAAAA,KAAK,EAAM,YAD0H;AAErIC,MAAAA,OAAO,EAAI,IAF0H;AAGrIC,MAAAA,QAAQ,EAAG,EAH0H;AAIrIC,MAAAA,MAAM,EAAK;AAJ0H,KAAD,EAKlI;AACFH,MAAAA,KAAK,EAAM,YADT;AAEFC,MAAAA,OAAO,EAAI,IAFT;AAGFC,MAAAA,QAAQ,EAAG,EAHT;AAIFC,MAAAA,MAAM,EAAK;AAJT,KALkI,CAArI,EAf+B,CA2B/B;AACA;;AACA,iCAAY,6HAAZ,EAA2I,IAA3I,EAA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AAE;AAAZ,KAArE,EAAyFpB,uBAAzF,CAAxB;AACAmB,IAAAA,eAAe,CAACP,MAAhB,CAAuBX,MAAvB,CAA8BE,KAA9B,CAAoC,CAApC;AACAgB,IAAAA,eAAe,CAAC,CAAD,CAAf,CAAmBd,OAAnB,CAA2BJ,MAA3B,CAAkCE,KAAlC,CAAwC,IAAxC;AACAgB,IAAAA,eAAe,CAAC,CAAD,CAAf,CAAmBf,KAAnB,CAAyBH,MAAzB,CAAgCE,KAAhC,CAAsC,WAAtC,EA/BqE,CAiCrE;AACA;;AACA,iCAAY,iDAAZ,EAA+D,IAA/D,EAAqEH,uBAArE,EAA+EC,MAA/E,CAAsFC,IAAtF,CAA2FC,KAA3F,CAAiG,EAAjG;AACA,GApCC,CAAF,CAtJ6B,CA4L7B;;AACAJ,EAAAA,EAAE,CAAC,oHAAD,EAAuH,YAAM;AAC9H,iCAAY,4BAAZ,EAA0C,IAA1C,EAAgDC,uBAAhD,EACEC,MADF,CAEEC,IAFF,CAGEC,KAHF,CAGQ,CAAC;AACPE,MAAAA,OAAO,EAAE,IADF;AAEPD,MAAAA,KAAK,EAAE,UAFA;AAGPE,MAAAA,QAAQ,EAAE,CAHH;AAIPC,MAAAA,MAAM,EAAE;AAJD,KAAD,CAHR;AASA,GAVC,CAAF;AAWA,CAxMO,CAAR","sourcesContent":["import findNumbers from './findNumbers'\r\nimport metadata from '../metadata.max.json'\r\n\r\ndescribe('findNumbers', () => {\r\n\tit('should find numbers', () => {\r\n\t\tfindNumbers('2133734253', 'US', metadata).should.deep.equal([{\r\n\t\t\tphone : '2133734253',\r\n\t\t\tcountry : 'US',\r\n\t\t\tstartsAt : 0,\r\n\t\t\tendsAt : 10\r\n\t\t}])\r\n\r\n\t\tfindNumbers('(213) 373-4253', 'US', metadata).should.deep.equal([{\r\n\t\t\tphone : '2133734253',\r\n\t\t\tcountry : 'US',\r\n\t\t\tstartsAt : 0,\r\n\t\t\tendsAt : 14\r\n\t\t}])\r\n\r\n\t\tfindNumbers('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', metadata).should.deep.equal([{\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\tstartsAt : 14,\r\n\t\t\tendsAt : 32\r\n\t\t}, {\r\n\t\t\tphone : '2133734253',\r\n\t\t\tcountry : 'US',\r\n\t\t\tstartsAt : 41,\r\n\t\t\tendsAt : 55\r\n\t\t}])\r\n\r\n\t\t// Opening parenthesis issue.\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/252\r\n\t\tfindNumbers('The number is +7 (800) 555-35-35 and not (213) 373-4253 (that\\'s not even in the same country!) as written in the document.', 'US', metadata).should.deep.equal([{\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\tstartsAt : 14,\r\n\t\t\tendsAt : 32\r\n\t\t}, {\r\n\t\t\tphone : '2133734253',\r\n\t\t\tcountry : 'US',\r\n\t\t\tstartsAt : 41,\r\n\t\t\tendsAt : 55\r\n\t\t}])\r\n\r\n\t\t// No default country.\r\n\t\tfindNumbers('The number is +7 (800) 555-35-35 as written in the document.', metadata).should.deep.equal([{\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\tstartsAt : 14,\r\n\t\t\tendsAt : 32\r\n\t\t}])\r\n\r\n\t\t// Passing `options` and default country.\r\n\t\tfindNumbers('The number is +7 (800) 555-35-35 as written in the document.', 'US', { leniency: 'VALID' }, metadata).should.deep.equal([{\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\tstartsAt : 14,\r\n\t\t\tendsAt : 32\r\n\t\t}])\r\n\r\n\t\t// Passing `options`.\r\n\t\tfindNumbers('The number is +7 (800) 555-35-35 as written in the document.', { leniency: 'VALID' }, metadata).should.deep.equal([{\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\tstartsAt : 14,\r\n\t\t\tendsAt : 32\r\n\t\t}])\r\n\r\n\t\t// Not a phone number and a phone number.\r\n\t\tfindNumbers('Digits 12 are not a number, but +7 (800) 555-35-35 is.', { leniency: 'VALID' }, metadata).should.deep.equal([{\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\tstartsAt : 32,\r\n\t\t\tendsAt : 50\r\n\t\t}])\r\n\r\n\t\t// Phone number extension.\r\n\t\tfindNumbers('Date 02/17/2018 is not a number, but +7 (800) 555-35-35 ext. 123 is.', { leniency: 'VALID' }, metadata).should.deep.equal([{\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\text : '123',\r\n\t\t\tstartsAt : 37,\r\n\t\t\tendsAt : 64\r\n\t\t}])\r\n\t})\r\n\r\n\tit('should find numbers (v2)', () => {\r\n\t\tconst phoneNumbers = findNumbers('The number is +7 (800) 555-35-35 ext. 1234 and not (213) 373-4253 as written in the document.', 'US', { v2: true }, metadata)\r\n\r\n\t\tphoneNumbers.length.should.equal(2)\r\n\r\n\t\tphoneNumbers[0].startsAt.should.equal(14)\r\n\t\tphoneNumbers[0].endsAt.should.equal(42)\r\n\r\n\t\tphoneNumbers[0].number.number.should.equal('+78005553535')\r\n\t\tphoneNumbers[0].number.nationalNumber.should.equal('8005553535')\r\n\t\tphoneNumbers[0].number.country.should.equal('RU')\r\n\t\tphoneNumbers[0].number.countryCallingCode.should.equal('7')\r\n\t\tphoneNumbers[0].number.ext.should.equal('1234')\r\n\r\n\t\tphoneNumbers[1].startsAt.should.equal(51)\r\n\t\tphoneNumbers[1].endsAt.should.equal(65)\r\n\r\n\t\tphoneNumbers[1].number.number.should.equal('+12133734253')\r\n\t\tphoneNumbers[1].number.nationalNumber.should.equal('2133734253')\r\n\t\tphoneNumbers[1].number.country.should.equal('US')\r\n\t\tphoneNumbers[1].number.countryCallingCode.should.equal('1')\r\n\t})\r\n\r\n\tit('shouldn\\'t find non-valid numbers', () => {\r\n\t\t// Not a valid phone number for US.\r\n\t\tfindNumbers('1111111111', 'US', metadata).should.deep.equal([])\r\n\t})\r\n\r\n\tit('should find non-European digits', () => {\r\n\t\t// E.g. in Iraq they don't write `+442323234` but rather `+٤٤٢٣٢٣٢٣٤`.\r\n\t\tfindNumbers('العَرَبِيَّة +٤٤٣٣٣٣٣٣٣٣٣٣عَرَبِيّ', metadata).should.deep.equal([{\r\n\t\t\tcountry : 'GB',\r\n\t\t\tphone : '3333333333',\r\n\t\t\tstartsAt : 14,\r\n\t\t\tendsAt : 27\r\n\t\t}])\r\n\t})\r\n\r\n\tit('should work in edge cases', () => {\r\n\t\tlet thrower\r\n\r\n\t\t// No input\r\n\t\tfindNumbers('', metadata).should.deep.equal([])\r\n\r\n\t\t// // No country metadata for this `require` country code\r\n\t\t// thrower = () => findNumbers('123', 'ZZ', metadata)\r\n\t\t// thrower.should.throw('Unknown country')\r\n\r\n\t\t// Numerical `value`\r\n\t\tthrower = () => findNumbers(2141111111, 'US')\r\n\t\tthrower.should.throw('A text for parsing must be a string.')\r\n\r\n\t\t// // No metadata\r\n\t\t// thrower = () => findNumbers('')\r\n\t\t// thrower.should.throw('`metadata` argument not passed')\r\n\r\n\t\t// No metadata, no default country, no phone numbers.\r\n\t\tfindNumbers('').should.deep.equal([])\r\n\t})\r\n\r\n\tit('should find international numbers when passed a non-existent default country', () => {\r\n\t\tconst numbers = findNumbers('Phone: +7 (800) 555 35 35. National: 8 (800) 555-55-55', { defaultCountry: 'XX', v2: true }, metadata)\r\n\t\tnumbers.length.should.equal(1)\r\n\t\tnumbers[0].number.nationalNumber.should.equal('8005553535')\r\n\t})\r\n\r\n\tit('shouldn\\'t find phone numbers which are not phone numbers', () => {\r\n\t\t// A timestamp.\r\n\t\tfindNumbers('2012-01-02 08:00', 'US', metadata).should.deep.equal([])\r\n\r\n\t\t// A valid number (not a complete timestamp).\r\n\t\tfindNumbers('2012-01-02 08', 'US', metadata).should.deep.equal([{\r\n\t\t\tcountry : 'US',\r\n\t\t\tphone : '2012010208',\r\n\t\t\tstartsAt : 0,\r\n\t\t\tendsAt : 13\r\n\t\t}])\r\n\r\n\t\t// Invalid parens.\r\n\t\tfindNumbers('213(3734253', 'US', metadata).should.deep.equal([])\r\n\r\n\t\t// Letters after phone number.\r\n\t\tfindNumbers('2133734253a', 'US', metadata).should.deep.equal([])\r\n\r\n\t\t// Valid phone (same as the one found in the UUID below).\r\n\t\tfindNumbers('The phone number is 231354125.', 'FR', metadata).should.deep.equal([{\r\n\t\t\tcountry : 'FR',\r\n\t\t\tphone : '231354125',\r\n\t\t\tstartsAt : 20,\r\n\t\t\tendsAt : 29\r\n\t\t}])\r\n\r\n\t\t// Not a phone number (part of a UUID).\r\n\t\t// Should parse in `{ extended: true }` mode.\r\n\t\tconst possibleNumbers = findNumbers('The UUID is CA801c26f98cd16e231354125ad046e40b.', 'FR', { extended: true }, metadata)\r\n\t\tpossibleNumbers.length.should.equal(1)\r\n\t\tpossibleNumbers[0].country.should.equal('FR')\r\n\t\tpossibleNumbers[0].phone.should.equal('231354125')\r\n\r\n\t\t// Not a phone number (part of a UUID).\r\n\t\t// Shouldn't parse by default.\r\n\t\tfindNumbers('The UUID is CA801c26f98cd16e231354125ad046e40b.', 'FR', metadata).should.deep.equal([])\r\n\t})\r\n\r\n\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/merge_requests/4\r\n\tit('should return correct `startsAt` and `endsAt` when matching \"inner\" candidates in a could-be-a-candidate substring', () => {\r\n\t\tfindNumbers('39945926 77200596 16533084', 'ID', metadata)\r\n\t\t\t.should\r\n\t\t\t.deep\r\n\t\t\t.equal([{\r\n\t\t\t\tcountry: 'ID',\r\n\t\t\t\tphone: '77200596',\r\n\t\t\t\tstartsAt: 9,\r\n\t\t\t\tendsAt: 17\r\n\t\t\t}])\r\n\t})\r\n})"],"file":"findNumbers.test.js"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _examplesMobile = _interopRequireDefault(require("../examples.mobile.json"));
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _metadataMin = _interopRequireDefault(require("../metadata.min.json"));
|
|
6
6
|
|
|
7
7
|
var _getExampleNumber = _interopRequireDefault(require("./getExampleNumber"));
|
|
8
8
|
|
|
@@ -10,14 +10,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
10
10
|
|
|
11
11
|
describe('getExampleNumber', function () {
|
|
12
12
|
it('should get an example number', function () {
|
|
13
|
-
var phoneNumber = (0, _getExampleNumber["default"])('RU',
|
|
13
|
+
var phoneNumber = (0, _getExampleNumber["default"])('RU', _examplesMobile["default"], _metadataMin["default"]);
|
|
14
14
|
phoneNumber.nationalNumber.should.equal('9123456789');
|
|
15
15
|
phoneNumber.number.should.equal('+79123456789');
|
|
16
16
|
phoneNumber.countryCallingCode.should.equal('7');
|
|
17
17
|
phoneNumber.country.should.equal('RU');
|
|
18
18
|
});
|
|
19
19
|
it('should handle a non-existing country', function () {
|
|
20
|
-
expect((0, _getExampleNumber["default"])('XX',
|
|
20
|
+
expect((0, _getExampleNumber["default"])('XX', _examplesMobile["default"], _metadataMin["default"])).to.be.undefined;
|
|
21
21
|
});
|
|
22
22
|
});
|
|
23
23
|
//# sourceMappingURL=getExampleNumber.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/getExampleNumber.test.js"],"names":["describe","it","phoneNumber","examples","metadata","nationalNumber","should","equal","number","countryCallingCode","country","expect","to","be","undefined"],"mappings":";;AAAA;;AACA;;AACA;;;;AAEAA,QAAQ,CAAC,kBAAD,EAAqB,YAAM;AAClCC,EAAAA,EAAE,CAAC,8BAAD,EAAiC,YAAM;AACxC,QAAMC,WAAW,GAAG,kCAAiB,IAAjB,EAAuBC,
|
|
1
|
+
{"version":3,"sources":["../source/getExampleNumber.test.js"],"names":["describe","it","phoneNumber","examples","metadata","nationalNumber","should","equal","number","countryCallingCode","country","expect","to","be","undefined"],"mappings":";;AAAA;;AACA;;AACA;;;;AAEAA,QAAQ,CAAC,kBAAD,EAAqB,YAAM;AAClCC,EAAAA,EAAE,CAAC,8BAAD,EAAiC,YAAM;AACxC,QAAMC,WAAW,GAAG,kCAAiB,IAAjB,EAAuBC,0BAAvB,EAAiCC,uBAAjC,CAApB;AACAF,IAAAA,WAAW,CAACG,cAAZ,CAA2BC,MAA3B,CAAkCC,KAAlC,CAAwC,YAAxC;AACAL,IAAAA,WAAW,CAACM,MAAZ,CAAmBF,MAAnB,CAA0BC,KAA1B,CAAgC,cAAhC;AACAL,IAAAA,WAAW,CAACO,kBAAZ,CAA+BH,MAA/B,CAAsCC,KAAtC,CAA4C,GAA5C;AACAL,IAAAA,WAAW,CAACQ,OAAZ,CAAoBJ,MAApB,CAA2BC,KAA3B,CAAiC,IAAjC;AACA,GANC,CAAF;AAQAN,EAAAA,EAAE,CAAC,sCAAD,EAAyC,YAAM;AAChDU,IAAAA,MAAM,CAAC,kCAAiB,IAAjB,EAAuBR,0BAAvB,EAAiCC,uBAAjC,CAAD,CAAN,CAAmDQ,EAAnD,CAAsDC,EAAtD,CAAyDC,SAAzD;AACA,GAFC,CAAF;AAGA,CAZO,CAAR","sourcesContent":["import examples from '../examples.mobile.json'\r\nimport metadata from '../metadata.min.json'\r\nimport getExampleNumber from './getExampleNumber'\r\n\r\ndescribe('getExampleNumber', () => {\r\n\tit('should get an example number', () => {\r\n\t\tconst phoneNumber = getExampleNumber('RU', examples, metadata)\r\n\t\tphoneNumber.nationalNumber.should.equal('9123456789')\r\n\t\tphoneNumber.number.should.equal('+79123456789')\r\n\t\tphoneNumber.countryCallingCode.should.equal('7')\r\n\t\tphoneNumber.country.should.equal('RU')\r\n\t})\r\n\r\n\tit('should handle a non-existing country', () => {\r\n\t\texpect(getExampleNumber('XX', examples, metadata)).to.be.undefined\r\n\t})\r\n})"],"file":"getExampleNumber.test.js"}
|