Comparing version 1.0.8 to 1.0.10
@@ -6,3 +6,4 @@ declare const _default: { | ||
REGEXP_CLEANED_MASK: RegExp; | ||
REGEXP_LAST_NONE_DIGIT: RegExp; | ||
}; | ||
export default _default; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const M={1:[{secondNumbers:[0,1,2,3,4,5,6,7,8,9],countries:[{code:"US",dialCode:"+1"}]}],2:[{secondNumbers:[0],countries:[{code:"EG",dialCode:"+20"}]},{secondNumbers:[1],countries:[{code:"SS",dialCode:"+211"},{code:"MA",dialCode:"+212"},{code:"DZ",dialCode:"+213"},{code:"TN",dialCode:"+216"},{code:"LY",dialCode:"+218"}]},{secondNumbers:[2],countries:[{code:"GM",dialCode:"+220"},{code:"SN",dialCode:"+221"},{code:"MR",dialCode:"+222"},{code:"ML",dialCode:"+223"},{code:"GN",dialCode:"+224"},{code:"CI",dialCode:"+225"},{code:"BF",dialCode:"+226"},{code:"NE",dialCode:"+227"},{code:"TG",dialCode:"+228"},{code:"BJ",dialCode:"+229"}]},{secondNumbers:[3],countries:[{code:"MU",dialCode:"+230"},{code:"LR",dialCode:"+231"},{code:"SL",dialCode:"+232"},{code:"GH",dialCode:"+233"},{code:"NG",dialCode:"+234"},{code:"TD",dialCode:"+235"},{code:"CF",dialCode:"+236"},{code:"CM",dialCode:"+237"},{code:"CV",dialCode:"+238"},{code:"ST",dialCode:"+239"}]},{secondNumbers:[4],countries:[{code:"GQ",dialCode:"+240"},{code:"GA",dialCode:"+241"},{code:"CG",dialCode:"+242"},{code:"CD",dialCode:"+243"},{code:"AO",dialCode:"+244"},{code:"GW",dialCode:"+245"},{code:"IO",dialCode:"+246"},{code:"AC",dialCode:"+247"},{code:"SC",dialCode:"+248"},{code:"SD",dialCode:"+249"}]},{secondNumbers:[5],countries:[{code:"RW",dialCode:"+250"},{code:"ET",dialCode:"+251"},{code:"SO",dialCode:"+252"},{code:"DJ",dialCode:"+253"},{code:"KE",dialCode:"+254"},{code:"TZ",dialCode:"+255"},{code:"UG",dialCode:"+256"},{code:"BI",dialCode:"+257"},{code:"MZ",dialCode:"+258"}]},{secondNumbers:[6],countries:[{code:"ZM",dialCode:"+260"},{code:"MG",dialCode:"+261"},{code:"RE",dialCode:"+262"},{code:"ZW",dialCode:"+263"},{code:"NA",dialCode:"+264"},{code:"MW",dialCode:"+265"},{code:"LS",dialCode:"+266"},{code:"BW",dialCode:"+267"},{code:"SZ",dialCode:"+268"},{code:"KM",dialCode:"+269"}]},{secondNumbers:[7],countries:[{code:"ZA",dialCode:"+27"}]},{secondNumbers:[9],countries:[{code:"SH",dialCode:"+290"},{code:"ER",dialCode:"+291"},{code:"AW",dialCode:"+297"},{code:"FO",dialCode:"+298"},{code:"GL",dialCode:"+299"}]}],3:[{secondNumbers:[0],countries:[{code:"GR",dialCode:"+30"}]},{secondNumbers:[1],countries:[{code:"NL",dialCode:"+31"}]},{secondNumbers:[2],countries:[{code:"BE",dialCode:"+32"}]},{secondNumbers:[3],countries:[{code:"FR",dialCode:"+33"}]},{secondNumbers:[4],countries:[{code:"ES",dialCode:"+34"}]},{secondNumbers:[5],countries:[{code:"GI",dialCode:"+350"},{code:"PT",dialCode:"+351"},{code:"LU",dialCode:"+352"},{code:"IE",dialCode:"+353"},{code:"IS",dialCode:"+354"},{code:"AL",dialCode:"+355"},{code:"MT",dialCode:"+356"},{code:"CY",dialCode:"+357"},{code:"FI",dialCode:"+358"},{code:"BG",dialCode:"+359"}]},{secondNumbers:[6],countries:[{code:"HU",dialCode:"+36"}]},{secondNumbers:[7],countries:[{code:"LT",dialCode:"+370"},{code:"LV",dialCode:"+371"},{code:"EE",dialCode:"+372"},{code:"MD",dialCode:"+373"},{code:"AM",dialCode:"+374"},{code:"BY",dialCode:"+375"},{code:"AD",dialCode:"+376"},{code:"MC",dialCode:"+377"},{code:"SM",dialCode:"+378"},{code:"VA",dialCode:"+379"}]},{secondNumbers:[8],countries:[{code:"UA",dialCode:"+380"},{code:"RS",dialCode:"+381"},{code:"ME",dialCode:"+382"},{code:"XK",dialCode:"+383"},{code:"HR",dialCode:"+385"},{code:"SI",dialCode:"+386"},{code:"BA",dialCode:"+387"},{code:"EU",dialCode:"+388"},{code:"MK",dialCode:"+389"}]},{secondNumbers:[9],countries:[{code:"IT",dialCode:"+39"}]}],4:[{secondNumbers:[0],countries:[{code:"RO",dialCode:"+40"}]},{secondNumbers:[1],countries:[{code:"CH",dialCode:"+41"}]},{secondNumbers:[2],countries:[{code:"CZ",dialCode:"+420"},{code:"SK",dialCode:"+421"},{code:"LI",dialCode:"+423"}]},{secondNumbers:[3],countries:[{code:"AT",dialCode:"+43"}]},{secondNumbers:[4],countries:[{code:"UK",dialCode:"+44"}]},{secondNumbers:[5],countries:[{code:"DK",dialCode:"+45"}]},{secondNumbers:[6],countries:[{code:"SE",dialCode:"+45"}]},{secondNumbers:[7],countries:[{code:"NO",dialCode:"+47"}]},{secondNumbers:[8],countries:[{code:"PL",dialCode:"+48"}]},{secondNumbers:[9],countries:[{code:"DE",dialCode:"+49"}]}],5:[{secondNumbers:[0],countries:[{code:"FK",dialCode:"+500"},{code:"BZ",dialCode:"+501"},{code:"GT",dialCode:"+502"},{code:"SV",dialCode:"+503"},{code:"HN",dialCode:"+504"},{code:"NI",dialCode:"+505"},{code:"CR",dialCode:"+506"},{code:"PA",dialCode:"+507"},{code:"PM",dialCode:"+508"},{code:"HT",dialCode:"+509"}]},{secondNumbers:[1],countries:[{code:"PE",dialCode:"+51"}]},{secondNumbers:[2],countries:[{code:"MX",dialCode:"+52"}]},{secondNumbers:[3],countries:[{code:"CU",dialCode:"+53"}]},{secondNumbers:[4],countries:[{code:"AR",dialCode:"+54"}]},{secondNumbers:[5],countries:[{code:"BR",dialCode:"+55"}]},{secondNumbers:[6],countries:[{code:"CL",dialCode:"+56"}]},{secondNumbers:[7],countries:[{code:"CO",dialCode:"+57"}]},{secondNumbers:[8],countries:[{code:"VE",dialCode:"+58"}]},{secondNumbers:[9],countries:[{code:"FK",dialCode:"+590"},{code:"BZ",dialCode:"+591"},{code:"GT",dialCode:"+592"},{code:"SV",dialCode:"+593"},{code:"HN",dialCode:"+594"},{code:"NI",dialCode:"+595"},{code:"CR",dialCode:"+596"},{code:"PA",dialCode:"+597"},{code:"PM",dialCode:"+598"},{code:"HT",dialCode:"+599"}]}],6:[{secondNumbers:[0],countries:[{code:"MY",dialCode:"+60"}]},{secondNumbers:[1],countries:[{code:"AU",dialCode:"+61"}]},{secondNumbers:[2],countries:[{code:"ID",dialCode:"+62"}]},{secondNumbers:[3],countries:[{code:"PH",dialCode:"+63"}]},{secondNumbers:[4],countries:[{code:"NZ",dialCode:"+64"}]},{secondNumbers:[5],countries:[{code:"SG",dialCode:"+65"}]},{secondNumbers:[6],countries:[{code:"TH",dialCode:"+66"}]},{secondNumbers:[7],countries:[{code:"TL",dialCode:"+670"},{code:"AQ",dialCode:"+672"},{code:"BN",dialCode:"+673"},{code:"NR",dialCode:"+674"},{code:"PG",dialCode:"+675"},{code:"TO",dialCode:"+676"},{code:"SB",dialCode:"+677"},{code:"VU",dialCode:"+678"},{code:"FJ",dialCode:"+679"}]},{secondNumbers:[8],countries:[{code:"PW",dialCode:"+680"},{code:"WF",dialCode:"+681"},{code:"CK",dialCode:"+682"},{code:"NU",dialCode:"+683"},{code:"WS",dialCode:"+685"},{code:"KI",dialCode:"+686"},{code:"NC",dialCode:"+687"},{code:"TV",dialCode:"+688"},{code:"PF",dialCode:"+689"}]},{secondNumbers:[9],countries:[{code:"TK",dialCode:"+690"},{code:"FM",dialCode:"+691"},{code:"MH",dialCode:"+692"}]}],7:[{secondNumbers:[6,7],countries:[{code:"KZ",dialCode:"+7"}]},{secondNumbers:[0,1,2,3,4,5,8,9],countries:[{code:"RU",dialCode:"+7"}]}],8:[{secondNumbers:[1],countries:[{code:"JP",dialCode:"+81"}]},{secondNumbers:[2],countries:[{code:"KR",dialCode:"+82"}]},{secondNumbers:[4],countries:[{code:"VN",dialCode:"+84"}]},{secondNumbers:[5],countries:[{code:"KP",dialCode:"+850"},{code:"HK",dialCode:"+852"},{code:"MO",dialCode:"+853"},{code:"KH",dialCode:"+855"},{code:"LA",dialCode:"+856"}]},{secondNumbers:[6],countries:[{code:"CN",dialCode:"+86"}]},{secondNumbers:[8],countries:[{code:"BD",dialCode:"+880"},{code:"TW",dialCode:"+886"}]}],9:[{secondNumbers:[0],countries:[{code:"TR",dialCode:"+90"}]},{secondNumbers:[1],countries:[{code:"IN",dialCode:"+91"}]},{secondNumbers:[2],countries:[{code:"PK",dialCode:"+92"}]},{secondNumbers:[3],countries:[{code:"AF",dialCode:"+93"}]},{secondNumbers:[4],countries:[{code:"LK",dialCode:"+94"}]},{secondNumbers:[5],countries:[{code:"MM",dialCode:"+95"}]},{secondNumbers:[6],countries:[{code:"MV",dialCode:"+960"},{code:"LB",dialCode:"+961"},{code:"JO",dialCode:"+962"},{code:"SY",dialCode:"+963"},{code:"IQ",dialCode:"+964"},{code:"KW",dialCode:"+965"},{code:"SA",dialCode:"+966"},{code:"YE",dialCode:"+967"},{code:"OM",dialCode:"+968"}]},{secondNumbers:[7],countries:[{code:"PS",dialCode:"+970"},{code:"AE",dialCode:"+971"},{code:"IL",dialCode:"+972"},{code:"BH",dialCode:"+973"},{code:"QA",dialCode:"+974"},{code:"BT",dialCode:"+975"},{code:"MN",dialCode:"+976"},{code:"NP",dialCode:"+977"}]},{secondNumbers:[8],countries:[{code:"IR",dialCode:"+98"}]},{secondNumbers:[9],countries:[{code:"TJ",dialCode:"+992"},{code:"TM",dialCode:"+993"},{code:"AZ",dialCode:"+994"},{code:"GE",dialCode:"+995"},{code:"KG",dialCode:"+996"},{code:"UZ",dialCode:"+998"}]}]},T=/\(|\)|\s|-|\+/g,R=/[^\\(\\)\s-#]/g,_=/#/g,I=/\D/g,b={REGEXP_ALL_HASHES:_,REGEXP_ONLY_DIGITS:I,REGEXP_MASK_SYMBOLS:T,REGEXP_CLEANED_MASK:R},{REGEXP_ONLY_DIGITS:K}=b,f=({value:r,resolvers:d})=>{const a=+r.charAt(0);let i=null,e=r;const C=d.find(o=>o.firstInputChars[a]);if(C){const{resolveAs:o}=C;i=M[o.firstChar].find(s=>s.countries.find(t=>t.code===o.code))||null;const c=i?i.countries.find(s=>s.code===o.code):null,u=c?c.dialCode.replace(K,""):null,l=C.firstInputChars[a];(l==null?void 0:l.mode)==="add"&&(e=`${u||o.firstChar}${e}`),(l==null?void 0:l.mode)==="replace"&&(e=`${u||o.firstChar}${e.substring(1)}`)}return{resolvedCell:i,resolvedPhone:e}},{REGEXP_ALL_HASHES:D,REGEXP_MASK_SYMBOLS:g,REGEXP_CLEANED_MASK:H}=b,B=({mask:r,value:d,options:a})=>{let i=0,e="";if(!d)return"";if(!r)return d;const C=r.replace(H,"");if(a!=null&&a.withTail){const c=C.replace(g,"").length;e=d.slice(c,d.length)}return`${C.replace(D,()=>{const c=d[i];return i+=1,c||"_"}).split("_")[0].trim()}${e}`},{REGEXP_ONLY_DIGITS:O}=b,X=(r,d)=>{const a=d==null?void 0:d.resolvers,i=d==null?void 0:d.formats,e=r.trim().replace(O,""),C=e.length>1?e.charAt(1):"";let o=e.length>0?e.charAt(0):"",N=null,c=e;if(a&&o){const{resolvedCell:l,resolvedPhone:s}=f({value:e,resolvers:a});N=l,c=s,o=c.charAt(0)}const u={code:null,dialCode:null,nationalNumber:null,formattedNumber:`+${c}`};if(o&&o!=="0"){const l=C===""?-1:Number(C),s=N||M[o].find(t=>t.secondNumbers.includes(l));if(s){const t=s?s.countries[0].dialCode.length-1:0,G=c.slice(0,t),m=s.countries.filter(L=>L.dialCode.includes(G));if(m.length>1||!m.length)return u;const P=m[0].dialCode.substring(1),{dialCode:E,code:S}=m[0],A=c.substring(P.length),n=i?i[S]:null,h=`${E} ${B({value:A,mask:n==null?void 0:n.mask,options:{withTail:!!(n!=null&&n.withTail)}})}`.trim();return{code:S,dialCode:E,nationalNumber:A,formattedNumber:h}}}return u};exports.parsePhoneNumber=X; | ||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const G={1:[{secondNumbers:[0,1,2,3,4,5,6,7,8,9],countries:[{code:"US",dialCode:"+1"}]}],2:[{secondNumbers:[0],countries:[{code:"EG",dialCode:"+20"}]},{secondNumbers:[1],countries:[{code:"SS",dialCode:"+211"},{code:"MA",dialCode:"+212"},{code:"DZ",dialCode:"+213"},{code:"TN",dialCode:"+216"},{code:"LY",dialCode:"+218"}]},{secondNumbers:[2],countries:[{code:"GM",dialCode:"+220"},{code:"SN",dialCode:"+221"},{code:"MR",dialCode:"+222"},{code:"ML",dialCode:"+223"},{code:"GN",dialCode:"+224"},{code:"CI",dialCode:"+225"},{code:"BF",dialCode:"+226"},{code:"NE",dialCode:"+227"},{code:"TG",dialCode:"+228"},{code:"BJ",dialCode:"+229"}]},{secondNumbers:[3],countries:[{code:"MU",dialCode:"+230"},{code:"LR",dialCode:"+231"},{code:"SL",dialCode:"+232"},{code:"GH",dialCode:"+233"},{code:"NG",dialCode:"+234"},{code:"TD",dialCode:"+235"},{code:"CF",dialCode:"+236"},{code:"CM",dialCode:"+237"},{code:"CV",dialCode:"+238"},{code:"ST",dialCode:"+239"}]},{secondNumbers:[4],countries:[{code:"GQ",dialCode:"+240"},{code:"GA",dialCode:"+241"},{code:"CG",dialCode:"+242"},{code:"CD",dialCode:"+243"},{code:"AO",dialCode:"+244"},{code:"GW",dialCode:"+245"},{code:"IO",dialCode:"+246"},{code:"AC",dialCode:"+247"},{code:"SC",dialCode:"+248"},{code:"SD",dialCode:"+249"}]},{secondNumbers:[5],countries:[{code:"RW",dialCode:"+250"},{code:"ET",dialCode:"+251"},{code:"SO",dialCode:"+252"},{code:"DJ",dialCode:"+253"},{code:"KE",dialCode:"+254"},{code:"TZ",dialCode:"+255"},{code:"UG",dialCode:"+256"},{code:"BI",dialCode:"+257"},{code:"MZ",dialCode:"+258"}]},{secondNumbers:[6],countries:[{code:"ZM",dialCode:"+260"},{code:"MG",dialCode:"+261"},{code:"RE",dialCode:"+262"},{code:"ZW",dialCode:"+263"},{code:"NA",dialCode:"+264"},{code:"MW",dialCode:"+265"},{code:"LS",dialCode:"+266"},{code:"BW",dialCode:"+267"},{code:"SZ",dialCode:"+268"},{code:"KM",dialCode:"+269"}]},{secondNumbers:[7],countries:[{code:"ZA",dialCode:"+27"}]},{secondNumbers:[9],countries:[{code:"SH",dialCode:"+290"},{code:"ER",dialCode:"+291"},{code:"AW",dialCode:"+297"},{code:"FO",dialCode:"+298"},{code:"GL",dialCode:"+299"}]}],3:[{secondNumbers:[0],countries:[{code:"GR",dialCode:"+30"}]},{secondNumbers:[1],countries:[{code:"NL",dialCode:"+31"}]},{secondNumbers:[2],countries:[{code:"BE",dialCode:"+32"}]},{secondNumbers:[3],countries:[{code:"FR",dialCode:"+33"}]},{secondNumbers:[4],countries:[{code:"ES",dialCode:"+34"}]},{secondNumbers:[5],countries:[{code:"GI",dialCode:"+350"},{code:"PT",dialCode:"+351"},{code:"LU",dialCode:"+352"},{code:"IE",dialCode:"+353"},{code:"IS",dialCode:"+354"},{code:"AL",dialCode:"+355"},{code:"MT",dialCode:"+356"},{code:"CY",dialCode:"+357"},{code:"FI",dialCode:"+358"},{code:"BG",dialCode:"+359"}]},{secondNumbers:[6],countries:[{code:"HU",dialCode:"+36"}]},{secondNumbers:[7],countries:[{code:"LT",dialCode:"+370"},{code:"LV",dialCode:"+371"},{code:"EE",dialCode:"+372"},{code:"MD",dialCode:"+373"},{code:"AM",dialCode:"+374"},{code:"BY",dialCode:"+375"},{code:"AD",dialCode:"+376"},{code:"MC",dialCode:"+377"},{code:"SM",dialCode:"+378"},{code:"VA",dialCode:"+379"}]},{secondNumbers:[8],countries:[{code:"UA",dialCode:"+380"},{code:"RS",dialCode:"+381"},{code:"ME",dialCode:"+382"},{code:"XK",dialCode:"+383"},{code:"HR",dialCode:"+385"},{code:"SI",dialCode:"+386"},{code:"BA",dialCode:"+387"},{code:"EU",dialCode:"+388"},{code:"MK",dialCode:"+389"}]},{secondNumbers:[9],countries:[{code:"IT",dialCode:"+39"}]}],4:[{secondNumbers:[0],countries:[{code:"RO",dialCode:"+40"}]},{secondNumbers:[1],countries:[{code:"CH",dialCode:"+41"}]},{secondNumbers:[2],countries:[{code:"CZ",dialCode:"+420"},{code:"SK",dialCode:"+421"},{code:"LI",dialCode:"+423"}]},{secondNumbers:[3],countries:[{code:"AT",dialCode:"+43"}]},{secondNumbers:[4],countries:[{code:"UK",dialCode:"+44"}]},{secondNumbers:[5],countries:[{code:"DK",dialCode:"+45"}]},{secondNumbers:[6],countries:[{code:"SE",dialCode:"+45"}]},{secondNumbers:[7],countries:[{code:"NO",dialCode:"+47"}]},{secondNumbers:[8],countries:[{code:"PL",dialCode:"+48"}]},{secondNumbers:[9],countries:[{code:"DE",dialCode:"+49"}]}],5:[{secondNumbers:[0],countries:[{code:"FK",dialCode:"+500"},{code:"BZ",dialCode:"+501"},{code:"GT",dialCode:"+502"},{code:"SV",dialCode:"+503"},{code:"HN",dialCode:"+504"},{code:"NI",dialCode:"+505"},{code:"CR",dialCode:"+506"},{code:"PA",dialCode:"+507"},{code:"PM",dialCode:"+508"},{code:"HT",dialCode:"+509"}]},{secondNumbers:[1],countries:[{code:"PE",dialCode:"+51"}]},{secondNumbers:[2],countries:[{code:"MX",dialCode:"+52"}]},{secondNumbers:[3],countries:[{code:"CU",dialCode:"+53"}]},{secondNumbers:[4],countries:[{code:"AR",dialCode:"+54"}]},{secondNumbers:[5],countries:[{code:"BR",dialCode:"+55"}]},{secondNumbers:[6],countries:[{code:"CL",dialCode:"+56"}]},{secondNumbers:[7],countries:[{code:"CO",dialCode:"+57"}]},{secondNumbers:[8],countries:[{code:"VE",dialCode:"+58"}]},{secondNumbers:[9],countries:[{code:"FK",dialCode:"+590"},{code:"BZ",dialCode:"+591"},{code:"GT",dialCode:"+592"},{code:"SV",dialCode:"+593"},{code:"HN",dialCode:"+594"},{code:"NI",dialCode:"+595"},{code:"CR",dialCode:"+596"},{code:"PA",dialCode:"+597"},{code:"PM",dialCode:"+598"},{code:"HT",dialCode:"+599"}]}],6:[{secondNumbers:[0],countries:[{code:"MY",dialCode:"+60"}]},{secondNumbers:[1],countries:[{code:"AU",dialCode:"+61"}]},{secondNumbers:[2],countries:[{code:"ID",dialCode:"+62"}]},{secondNumbers:[3],countries:[{code:"PH",dialCode:"+63"}]},{secondNumbers:[4],countries:[{code:"NZ",dialCode:"+64"}]},{secondNumbers:[5],countries:[{code:"SG",dialCode:"+65"}]},{secondNumbers:[6],countries:[{code:"TH",dialCode:"+66"}]},{secondNumbers:[7],countries:[{code:"TL",dialCode:"+670"},{code:"AQ",dialCode:"+672"},{code:"BN",dialCode:"+673"},{code:"NR",dialCode:"+674"},{code:"PG",dialCode:"+675"},{code:"TO",dialCode:"+676"},{code:"SB",dialCode:"+677"},{code:"VU",dialCode:"+678"},{code:"FJ",dialCode:"+679"}]},{secondNumbers:[8],countries:[{code:"PW",dialCode:"+680"},{code:"WF",dialCode:"+681"},{code:"CK",dialCode:"+682"},{code:"NU",dialCode:"+683"},{code:"WS",dialCode:"+685"},{code:"KI",dialCode:"+686"},{code:"NC",dialCode:"+687"},{code:"TV",dialCode:"+688"},{code:"PF",dialCode:"+689"}]},{secondNumbers:[9],countries:[{code:"TK",dialCode:"+690"},{code:"FM",dialCode:"+691"},{code:"MH",dialCode:"+692"}]}],7:[{secondNumbers:[6,7],countries:[{code:"KZ",dialCode:"+7"}]},{secondNumbers:[0,1,2,3,4,5,8,9],countries:[{code:"RU",dialCode:"+7"}]}],8:[{secondNumbers:[1],countries:[{code:"JP",dialCode:"+81"}]},{secondNumbers:[2],countries:[{code:"KR",dialCode:"+82"}]},{secondNumbers:[4],countries:[{code:"VN",dialCode:"+84"}]},{secondNumbers:[5],countries:[{code:"KP",dialCode:"+850"},{code:"HK",dialCode:"+852"},{code:"MO",dialCode:"+853"},{code:"KH",dialCode:"+855"},{code:"LA",dialCode:"+856"}]},{secondNumbers:[6],countries:[{code:"CN",dialCode:"+86"}]},{secondNumbers:[8],countries:[{code:"BD",dialCode:"+880"},{code:"TW",dialCode:"+886"}]}],9:[{secondNumbers:[0],countries:[{code:"TR",dialCode:"+90"}]},{secondNumbers:[1],countries:[{code:"IN",dialCode:"+91"}]},{secondNumbers:[2],countries:[{code:"PK",dialCode:"+92"}]},{secondNumbers:[3],countries:[{code:"AF",dialCode:"+93"}]},{secondNumbers:[4],countries:[{code:"LK",dialCode:"+94"}]},{secondNumbers:[5],countries:[{code:"MM",dialCode:"+95"}]},{secondNumbers:[6],countries:[{code:"MV",dialCode:"+960"},{code:"LB",dialCode:"+961"},{code:"JO",dialCode:"+962"},{code:"SY",dialCode:"+963"},{code:"IQ",dialCode:"+964"},{code:"KW",dialCode:"+965"},{code:"SA",dialCode:"+966"},{code:"YE",dialCode:"+967"},{code:"OM",dialCode:"+968"}]},{secondNumbers:[7],countries:[{code:"PS",dialCode:"+970"},{code:"AE",dialCode:"+971"},{code:"IL",dialCode:"+972"},{code:"BH",dialCode:"+973"},{code:"QA",dialCode:"+974"},{code:"BT",dialCode:"+975"},{code:"MN",dialCode:"+976"},{code:"NP",dialCode:"+977"}]},{secondNumbers:[8],countries:[{code:"IR",dialCode:"+98"}]},{secondNumbers:[9],countries:[{code:"TJ",dialCode:"+992"},{code:"TM",dialCode:"+993"},{code:"AZ",dialCode:"+994"},{code:"GE",dialCode:"+995"},{code:"KG",dialCode:"+996"},{code:"UZ",dialCode:"+998"}]}]},_=/\(|\)|\s|-|\+/g,h=/[^\\(\\)\s-#]/g,R=/#/g,I=/\D/g,D=/\D$/g,b={REGEXP_ALL_HASHES:R,REGEXP_ONLY_DIGITS:I,REGEXP_MASK_SYMBOLS:_,REGEXP_CLEANED_MASK:h,REGEXP_LAST_NONE_DIGIT:D},{REGEXP_ONLY_DIGITS:K}=b,f=({value:r,resolvers:d})=>{const a=+r.charAt(0);let i=null,e=r;const C=d.find(o=>o.firstInputChars[a]);if(C){const{resolveAs:o}=C;i=G[o.firstChar].find(s=>s.countries.find(t=>t.code===o.code))||null;const c=i?i.countries.find(s=>s.code===o.code):null,u=c?c.dialCode.replace(K,""):null,l=C.firstInputChars[a];(l==null?void 0:l.mode)==="add"&&(e=`${u||o.firstChar}${e}`),(l==null?void 0:l.mode)==="replace"&&(e=`${u||o.firstChar}${e.substring(1)}`)}return{resolvedCell:i,resolvedPhone:e}},{REGEXP_ALL_HASHES:g,REGEXP_MASK_SYMBOLS:H,REGEXP_CLEANED_MASK:B,REGEXP_LAST_NONE_DIGIT:O}=b,X=({mask:r,value:d,options:a})=>{let i=0,e="";if(!d)return"";if(!r)return d;const C=r.replace(B,"");if(a!=null&&a.withTail){const c=C.replace(H,"").length;e=d.slice(c,d.length)}return`${C.replace(g,()=>{const c=d[i];return i+=1,c||"_"}).split("_")[0].trim()}${e}`.replace(O,"")},{REGEXP_ONLY_DIGITS:$}=b,U=(r,d)=>{const a=d==null?void 0:d.resolvers,i=d==null?void 0:d.formats,e=r.trim().replace($,""),C=e.length>1?e.charAt(1):"";let o=e.length>0?e.charAt(0):"",N=null,c=e;if(a&&o){const{resolvedCell:l,resolvedPhone:s}=f({value:e,resolvers:a});N=l,c=s,o=c.charAt(0)}const u={code:null,dialCode:null,nationalNumber:null,formattedNumber:`+${c}`};if(o&&o!=="0"){const l=C===""?-1:Number(C),s=N||G[o].find(t=>t.secondNumbers.includes(l));if(s){const t=s?s.countries[0].dialCode.length-1:0,M=c.slice(0,t),m=s.countries.filter(T=>T.dialCode.includes(M));if(m.length>1||!m.length)return u;const P=m[0].dialCode.substring(1),{dialCode:E,code:S}=m[0],A=c.substring(P.length),n=i?i[S]:null,L=`${E} ${X({value:A,mask:n==null?void 0:n.mask,options:{withTail:!!(n!=null&&n.withTail)}})}`.trim();return{code:S,dialCode:E,nationalNumber:A,formattedNumber:L}}}return u};exports.parsePhoneNumber=U; |
{ | ||
"name": "phonumber", | ||
"version": "1.0.8", | ||
"version": "1.0.10", | ||
"description": "Phone number parser. Good for formatting phone numbers entered by users.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -5,2 +5,3 @@ const REGEXP_MASK_SYMBOLS = /\(|\)|\s|-|\+/g; | ||
const REGEXP_ONLY_DIGITS = /\D/g; | ||
const REGEXP_LAST_NONE_DIGIT = /\D$/g; | ||
@@ -12,2 +13,3 @@ export default { | ||
REGEXP_CLEANED_MASK, | ||
REGEXP_LAST_NONE_DIGIT, | ||
}; |
import { regexp } from './constants'; | ||
import { SetMaskParams } from './types'; | ||
const { REGEXP_ALL_HASHES, REGEXP_MASK_SYMBOLS, REGEXP_CLEANED_MASK } = regexp; | ||
const { | ||
REGEXP_ALL_HASHES, | ||
REGEXP_MASK_SYMBOLS, | ||
REGEXP_CLEANED_MASK, | ||
REGEXP_LAST_NONE_DIGIT, | ||
} = regexp; | ||
@@ -38,5 +43,5 @@ const setMask = ({ mask, value, options }: SetMaskParams) => { | ||
return `${result}${tail}`; | ||
return `${result}${tail}`.replace(REGEXP_LAST_NONE_DIGIT, ''); | ||
}; | ||
export default setMask; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79552
3322