UNPKG

5.01 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../source/AsYouTypeState.js"],"names":["AsYouTypeState","onCountryChange","onCallingCodeChange","properties","Object","keys","key","defaultCountry","defaultCallingCode","international","IDDPrefix","undefined","missingPlus","callingCode","digits","resetNationalSignificantNumber","initCountryAndCallingCode","nationalSignificantNumber","getNationalDigits","nationalSignificantNumberMatchesInput","nationalPrefix","carrierCode","complexPrefixBeforeNationalSignificantNumber","country","setCountry","setCallingCode","nextDigits","slice","length"],"mappings":";;;;;;;;;;;;;;;IAAqBA,c;;;AACpB,gCAAsD;AAAA;;AAAA,QAAxCC,eAAwC,QAAxCA,eAAwC;AAAA,QAAvBC,mBAAuB,QAAvBA,mBAAuB;;AAAA;;AAAA,oCAuB7C,UAACC,UAAD,EAAgB;AACxB,sCAAkBC,MAAM,CAACC,IAAP,CAAYF,UAAZ,CAAlB,kCAA2C;AAAtC,YAAMG,GAAG,mBAAT;AACJ,QAAA,KAAI,CAACA,GAAD,CAAJ,GAAYH,UAAU,CAACG,GAAD,CAAtB;AACA;AACD,KA3BqD;;AACrD,SAAKL,eAAL,GAAuBA,eAAvB;AACA,SAAKC,mBAAL,GAA2BA,mBAA3B;AACA;;;;0BAEKK,c,EAAgBC,kB,EAAoB;AACzC,WAAKC,aAAL,GAAqB,KAArB;AACA,WAAKC,SAAL,GAAiBC,SAAjB;AACA,WAAKC,WAAL,GAAmBD,SAAnB;AACA,WAAKE,WAAL,GAAmBF,SAAnB;AACA,WAAKG,MAAL,GAAc,EAAd;AACA,WAAKC,8BAAL;AACA,WAAKC,yBAAL,CAA+BT,cAA/B,EAA+CC,kBAA/C;AACA;;;qDAEgC;AAChC,WAAKS,yBAAL,GAAiC,KAAKC,iBAAL,EAAjC;AACA,WAAKC,qCAAL,GAA6C,IAA7C;AACA,WAAKC,cAAL,GAAsBT,SAAtB;AACA,WAAKU,WAAL,GAAmBV,SAAnB;AACA,WAAKW,4CAAL,GAAoDX,SAApD;AACA;;;8CAQyBY,O,EAASV,W,EAAa;AAC/C,WAAKW,UAAL,CAAgBD,OAAhB;AACA,WAAKE,cAAL,CAAoBZ,WAApB;AACA;;;+BAEUU,O,EAAS;AACnB,WAAKA,OAAL,GAAeA,OAAf;AACA,WAAKtB,eAAL,CAAqBsB,OAArB;AACA;;;mCAEcV,W,EAAa;AAC3B,WAAKA,WAAL,GAAmBA,WAAnB;AACA,aAAO,KAAKX,mBAAL,CAAyB,KAAKqB,OAA9B,EAAuCV,WAAvC,CAAP;AACA;;;+CAE0B;AAC1B;AACA,WAAKJ,aAAL,GAAqB,IAArB,CAF0B,CAG1B;AACA;AACA;;AACA,WAAKO,yBAAL;AACA;;;iCAEYU,U,EAAY;AACxB,WAAKZ,MAAL,IAAeY,UAAf;AACA;;;0DAEqCA,U,EAAY;AACjD,WAAKT,yBAAL,IAAkCS,UAAlC;AACA;AAED;;;;;;;;;;wCAOoB;AACnB,UAAI,KAAKjB,aAAT,EAAwB;AACvB,eAAO,KAAKK,MAAL,CAAYa,KAAZ,CACN,CAAC,KAAKjB,SAAL,GAAiB,KAAKA,SAAL,CAAekB,MAAhC,GAAyC,CAA1C,KACC,KAAKf,WAAL,GAAmB,KAAKA,WAAL,CAAiBe,MAApC,GAA6C,CAD9C,CADM,CAAP;AAIA;;AACD,aAAO,KAAKd,MAAZ;AACA;;;0DAEqC;AACrC,UAAI,KAAKL,aAAT,EAAwB;AACvB,YAAI,KAAKC,SAAT,EAAoB;AACnB,iBAAO,KAAKI,MAAL,CAAYa,KAAZ,CAAkB,KAAKjB,SAAL,CAAekB,MAAjC,CAAP;AACA;AACD;;AACD,aAAO,KAAKd,MAAZ;AACA","sourcesContent":["export default class AsYouTypeState {\r\n\tconstructor({ onCountryChange, onCallingCodeChange }) {\r\n\t\tthis.onCountryChange = onCountryChange\r\n\t\tthis.onCallingCodeChange = onCallingCodeChange\r\n\t}\r\n\r\n\treset(defaultCountry, defaultCallingCode) {\r\n\t\tthis.international = false\r\n\t\tthis.IDDPrefix = undefined\r\n\t\tthis.missingPlus = undefined\r\n\t\tthis.callingCode = undefined\r\n\t\tthis.digits = ''\r\n\t\tthis.resetNationalSignificantNumber()\r\n\t\tthis.initCountryAndCallingCode(defaultCountry, defaultCallingCode)\r\n\t}\r\n\r\n\tresetNationalSignificantNumber() {\r\n\t\tthis.nationalSignificantNumber = this.getNationalDigits()\r\n\t\tthis.nationalSignificantNumberMatchesInput = true\r\n\t\tthis.nationalPrefix = undefined\r\n\t\tthis.carrierCode = undefined\r\n\t\tthis.complexPrefixBeforeNationalSignificantNumber = undefined\r\n\t}\r\n\r\n\tupdate = (properties) => {\r\n\t\tfor (const key of Object.keys(properties)) {\r\n\t\t\tthis[key] = properties[key]\r\n\t\t}\r\n\t}\r\n\r\n\tinitCountryAndCallingCode(country, callingCode) {\r\n\t\tthis.setCountry(country)\r\n\t\tthis.setCallingCode(callingCode)\r\n\t}\r\n\r\n\tsetCountry(country) {\r\n\t\tthis.country = country\r\n\t\tthis.onCountryChange(country)\r\n\t}\r\n\r\n\tsetCallingCode(callingCode) {\r\n\t\tthis.callingCode = callingCode\r\n\t\treturn this.onCallingCodeChange(this.country, callingCode)\r\n\t}\r\n\r\n\tstartInternationalNumber() {\r\n\t\t// Prepend the `+` to parsed input.\r\n\t\tthis.international = true\r\n\t\t// If a default country was set then reset it\r\n\t\t// because an explicitly international phone\r\n\t\t// number is being entered.\r\n\t\tthis.initCountryAndCallingCode()\r\n\t}\r\n\r\n\tappendDigits(nextDigits) {\r\n\t\tthis.digits += nextDigits\r\n\t}\r\n\r\n\tappendNationalSignificantNumberDigits(nextDigits) {\r\n\t\tthis.nationalSignificantNumber += nextDigits\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the part of `this.digits` that corresponds to the national number.\r\n\t * Basically, all digits that have been input by the user, except for the\r\n\t * international prefix and the country calling code part\r\n\t * (if the number is an international one).\r\n\t * @return {string}\r\n\t */\r\n\tgetNationalDigits() {\r\n\t\tif (this.international) {\r\n\t\t\treturn this.digits.slice(\r\n\t\t\t\t(this.IDDPrefix ? this.IDDPrefix.length : 0) +\r\n\t\t\t\t(this.callingCode ? this.callingCode.length : 0)\r\n\t\t\t)\r\n\t\t}\r\n\t\treturn this.digits\r\n\t}\r\n\r\n\tgetDigitsWithoutInternationalPrefix() {\r\n\t\tif (this.international) {\r\n\t\t\tif (this.IDDPrefix) {\r\n\t\t\t\treturn this.digits.slice(this.IDDPrefix.length)\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn this.digits\r\n\t}\r\n}"],"file":"AsYouTypeState.js"}
\No newline at end of file