@desource/phone-mask 0.2.2 → 0.3.0
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 +13 -0
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/services/geoip/consts.js +1 -0
- package/dist/esm/services/geoip/utils.js +1 -0
- package/dist/esm/utils.js +1 -1
- package/dist/phone-mask.cjs.js +1 -1
- package/dist/phone-mask.umd.min.js +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/services/geoip/consts.d.ts +5 -0
- package/dist/types/services/geoip/consts.d.ts.map +1 -0
- package/dist/types/services/geoip/index.d.ts +4 -0
- package/dist/types/services/geoip/index.d.ts.map +1 -0
- package/dist/types/services/geoip/types.d.ts +5 -0
- package/dist/types/services/geoip/types.d.ts.map +1 -0
- package/dist/types/services/geoip/utils.d.ts +7 -0
- package/dist/types/services/geoip/utils.d.ts.map +1 -0
- package/dist/types/services/index.d.ts +2 -0
- package/dist/types/services/index.d.ts.map +1 -0
- package/dist/types/utils.d.ts +7 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @desource/phone-mask
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- React: Design React version of phone-mask library
|
|
8
|
+
- Core: Add geoip reusable service for country detection based on IP address
|
|
9
|
+
|
|
10
|
+
## 0.2.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Vue: Improve country dropdown scroll
|
|
15
|
+
|
|
3
16
|
## 0.2.2
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/LICENSE
CHANGED
package/README.md
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Masks as
|
|
1
|
+
import{Masks as s,MasksBase as o,MasksBaseMap as r,MasksFull as i,MasksFullEn as e,MasksFullMap as t,MasksFullMapEn as m,MasksMap as p,MasksWithFlag as f,MasksWithFlagMap as j,getFlagEmoji as c}from"./entries.js";import{countPlaceholders as g,formatDigitsWithMap as l,getCountry as n,getMasksFullMapByLocale as u,getNavigatorLang as v,pickMaskVariant as x,removeCountryCodePrefix as a,toArray as b}from"./utils.js";import{CACHE_EXPIRY_MS as d,CACHE_KEY as h,GEO_IP_API_URL as k,GEO_IP_TIMEOUT_MS as q}from"./services/geoip/consts.js";import{detectByGeoIp as w,detectCountryFromGeoIP as y}from"./services/geoip/utils.js";export{d as CACHE_EXPIRY_MS,h as CACHE_KEY,k as GEO_IP_API_URL,q as GEO_IP_TIMEOUT_MS,s as Masks,o as MasksBase,r as MasksBaseMap,i as MasksFull,e as MasksFullEn,t as MasksFullMap,m as MasksFullMapEn,p as MasksMap,f as MasksWithFlag,j as MasksWithFlagMap,g as countPlaceholders,w as detectByGeoIp,y as detectCountryFromGeoIP,l as formatDigitsWithMap,n as getCountry,c as getFlagEmoji,u as getMasksFullMapByLocale,v as getNavigatorLang,x as pickMaskVariant,a as removeCountryCodePrefix,b as toArray};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o="https://ipapi.co/json/",e=1500,p="@desource/phone-mask:geo",s=864e5;export{s as CACHE_EXPIRY_MS,p as CACHE_KEY,o as GEO_IP_API_URL,e as GEO_IP_TIMEOUT_MS};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{GEO_IP_API_URL as t,GEO_IP_TIMEOUT_MS as o,CACHE_KEY as e,CACHE_EXPIRY_MS as r}from"./consts.js";async function detectCountryFromGeoIP(e=t,r=o){const c=new AbortController,n=setTimeout(()=>c.abort(),r);try{const t=await fetch(e,{signal:c.signal,headers:{Accept:"application/json"}});if(clearTimeout(n),!t.ok)return null;const o=await t.json();return(o.country||o.country_code||o.countryCode||o.country_code2||"").toString().toUpperCase()||null}catch{return clearTimeout(n),null}}async function detectByGeoIp(t){try{const o=localStorage.getItem(e);if(o){const c=JSON.parse(o),n=Date.now()-c.ts>r;if(!n&&c.country_code&&t(c.country_code))return c.country_code.toUpperCase();n&&localStorage.removeItem(e)}}catch{}const o=await detectCountryFromGeoIP();if(o&&t(o)){try{localStorage.setItem(e,JSON.stringify({country_code:o,ts:Date.now()}))}catch{}return o}return null}export{detectByGeoIp,detectCountryFromGeoIP};
|
package/dist/esm/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function toArray(t){return Array.isArray(t)?t:[t]}function countPlaceholders(t){return(t.match(/#/g)||[]).length}function removeCountryCodePrefix(t){return t.replace(/^\+\d+\s?/,"")}function pickMaskVariant(t,n){if(1===t.length)return t[0];const
|
|
1
|
+
import{MasksFullMapEn as t,MasksFullMap as n}from"./entries.js";function getNavigatorLang(){return"undefined"!=typeof navigator&&navigator.language||"en"}function getMasksFullMapByLocale(e){return e.toLowerCase().startsWith("en")?t:n(e)}function getCountry(t,n){const e=getMasksFullMapByLocale(n),r=t.toUpperCase();return r in e?{id:r,...e[r]}:{id:"US",...e.US}}function toArray(t){return Array.isArray(t)?t:[t]}function countPlaceholders(t){return(t.match(/#/g)||[]).length}function removeCountryCodePrefix(t){return t.replace(/^\+\d+\s?/,"")}function pickMaskVariant(t,n){if(1===t.length)return t[0];const e=t.map(t=>({mask:t,count:countPlaceholders(t)})),r=e.filter(t=>t.count>=n).sort((t,n)=>t.count-n.count);if(r.length>0)return r[0].mask;const o=e.sort((t,n)=>n.count-t.count)[0];return o?o.mask:t[0]}function formatDigitsWithMap(t,n){let e="";const r=[];let o=0;const a=n.length,i=t.length;for(let u=0;u<i;u++){const i=t[u];if("#"===i){if(!(o<a))break;e+=n[o],r.push(o),o++}else{const n=-1!==t.indexOf("#",u+1)&&o<a;(e.length>0||n)&&(e+=i,r.push(-1))}}return{display:e,map:r}}export{countPlaceholders,formatDigitsWithMap,getCountry,getMasksFullMapByLocale,getNavigatorLang,pickMaskVariant,removeCountryCodePrefix,toArray};
|
package/dist/phone-mask.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const data={AC:"+247 #####",AD:["+376 ### ###","+376 #### ####"],AE:["+971 # ### ####","+971 ## ### ####","+971 ### ######","+971 ### # #####"],AF:"+93 ## ### ####",AG:"+1 ###-###-####",AI:"+1 ###-###-####",AL:["+355 ## ### ###","+355 ## ### ####","+355 ### ####","+355 ### ###","+355 ### #####"],AM:["+374 ## ######","+374 ### ## ###"],AO:"+244 ### ### ###",AR:["+54 ## ####-####","+54 # ## ####-####","+54 ###-###-####"],AS:"+1 ###-###-####",AT:["+43 # #########","+43 ### ######"],AU:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###","+61 ## ### ##"],AW:"+297 ### ####",AX:["+358 ## #######","+358 ### ######"],AZ:["+994 ## ### ## ##","+994 ### ## ## ##"],BA:["+387 ## ###-###","+387 ## ### ###"],BB:"+1 ###-###-####",BD:["+880 #-#######","+880 ####-######","+880 ###-#######"],BE:["+32 ## ## ## ##","+32 ### ## ## ##","+32 ### ## ###"],BF:"+226 ## ## ## ##",BG:["+359 # ### ###","+359 ## ### ###","+359 ### ## ###"],BH:"+973 #### ####",BI:"+257 ## ## ## ##",BJ:["+229 ## ## ## ## ##","+229 ## ## ## ##"],BL:"+590 ### ## ## ##",BM:"+1 ###-###-####",BN:"+673 ### ####",BO:["+591 # #######","+591 ########","+591 ### ## ####"],BQ:"+599 ### ####",BR:["+55 ## ####-####","+55 ## #####-####","+55 ### ## ####","+55 ####-####"],BS:"+1 ###-###-####",BT:["+975 # ### ###","+975 ## ## ## ##"],BW:["+267 ### ####","+267 ## ### ###","+267 #### ### ###","+267 ## #####"],BY:["+375 ### ##-##-##","+375 ## ###-##-##","+375 ### ### ####"],BZ:["+501 ###-####","+501 #-###-####-###"],CA:"+1 ###-###-####",CC:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###"],CD:["+243 ## #####","+243 ### ### ###"],CF:"+236 ## ## ## ##",CG:["+242 ## ### ####","+242 # #### ####"],CH:["+41 ## ### ## ##","+41 ### ### ###"],CI:["+225 ## ## # #####","+225 ## ## ## ####"],CK:"+682 ## ###",CL:["+56 ### ### ###","+56 # #### ####","+56 ### ### ####","+56 ## ### ####"],CM:["+237 # ## ## ## ##","+237 ## ## ## ##"],CN:["+86 ## #### ####","+86 ### #### ####","+86 ### ### ####","+86 ########"],CO:["+57 ### #######","+57 # ### #######"],CR:["+506 #### ####","+506 ###-###-####"],CU:["+53 # #######","+53 ### #######"],CV:"+238 ### ## ##",CW:["+599 # ### ####","+599 ### ####"],CX:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###"],CY:"+357 ## ######",CZ:"+420 ### ### ###",DE:["+49 ## ######","+49 #### #######","+49 ### ##########","+49 ### # ######","+49 ### # ####","+49 ### #### ####","+49 ########"],DJ:"+253 ## ## ## ##",DK:"+45 ## ## ## ##",DM:"+1 ###-###-####",DO:"+1 ###-###-####",DZ:["+213 ## ## ## ##","+213 ### ## ## ##","+213 ## ### ## ##"],EC:["+593 #-###-####","+593 ## ### ####","+593 #### ### ####"],EE:["+372 ### ####","+372 #### ####","+372 ## ## ####"],EG:["+20 # ########","+20 ## ########","+20 ### ### ####"],EH:["+212 # ## ## ## ##","+212 ##-#######"],ER:"+291 # ### ###",ES:["+34 ### ## ## ##","+34 ### ### ###"],ET:"+251 ## ### ####",FI:["+358 ## #######","+358 ### ######"],FJ:["+679 ### ####","+679 #### ### ####"],FK:"+500 #####",FM:"+691 ### ####",FO:"+298 ######",FR:["+33 # ## ## ## ##","+33 ### ## ## ##"],GA:"+241 ## ## ## ##",GB:["+44 ### ### ####","+44 #### ######","+44 ## #### ####"],GD:"+1 ###-###-####",GE:["+995 ## ### ## ##","+995 ### ## ## ##","+995 ### ### ###"],GF:"+594 ### ## ## ##",GG:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],GH:["+233 ## ### ####","+233 ### #####"],GI:["+350 ### #####","+350 ########"],GL:"+299 ## ## ##",GM:"+220 ### ####",GN:["+224 ## ## ## ##","+224 ### ## ## ##"],GP:"+590 ### ## ## ##",GQ:["+240 ### ### ###","+240 ### ######"],GR:["+30 ## #### ####","+30 ### ### ####"],GT:["+502 #### ####","+502 #### ### ####"],GU:"+1 ###-###-####",GW:["+245 ### ### ###","+245 ### ####"],GY:"+592 ### ####",HK:["+852 #### ####","+852 ### ### ###","+852 ### ## ### ###"],HN:["+504 ####-####","+504 ###########"],HR:["+385 # #### ###","+385 ## ### ####","+385 ### ### ###","+385 ## ## ###","+385 ## ### ###"],HT:"+509 ## ## ####",HU:["+36 # ### ####","+36 ## ### ####","+36 ## ### ###"],ID:["+62 ## #######","+62 ###-###-###","+62 ### #######","+62 ### # ### ###","+62 ### ### ####"],IE:["+353 ## #####","+353 ## ### ####","+353 #### ### ###","+353 ### ### ###"],IL:["+972 #-###-####","+972 ##-###-####","+972 #-###-###-###"],IM:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],IN:["+91 ##### #####","+91 #### ## ####","+91 #### ### ### ###","+91 #### ### ####"],IO:"+246 ### ####",IQ:["+964 # ### ####","+964 ### ### ####"],IR:["+98 ## #### ####","+98 ### ### ####"],IS:"+354 ### ####",IT:["+39 ## #### ####","+39 ### ### ####","+39 ### ### ###"],JE:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],JM:"+1 ###-###-####",JO:["+962 # ### ####","+962 # #### ####","+962 ### #####","+962 ## #######"],JP:["+81 #-####-####","+81 ##-####-####","+81 ###-###-###","+81 ##-###-####"],KE:["+254 ## #######","+254 ### ######","+254 ### ### ###"],KG:["+996 ### ### ###","+996 ### ### # ##"],KH:["+855 ## ### ###","+855 #### ### ###"],KI:["+686 #####","+686 ########"],KM:"+269 ### ## ##",KN:"+1 ###-###-####",KP:["+850 # ### ####","+850 ### ### ####"],KR:["+82 #-###-####","+82 ##-####-####","+82 ##-###-####"],KW:["+965 #### ####","+965 ### #####","+965 #### ###"],KY:"+1 ###-###-####",KZ:["+7 ##### # ## ##","+7 ### ### ####","+7 ### ###-##-##"],LA:["+856 ## ### ###","+856 ## ## ### ###"],LB:["+961 # ### ###","+961 ## ### ###"],LC:"+1 ###-###-####",LI:["+423 ### ## ##","+423 ### ### ###"],LK:["+94 ### ### ###","+94 ## ### ####"],LR:["+231 ## ### ###","+231 ## ### ####"],LS:"+266 #### ####",LT:["+370 ### #####","+370 ### ## ###"],LU:["+352 ## ## ## ##","+352 ### ### ###","+352 ### ## ###"],LV:"+371 ## ### ###",LY:"+218 ##-#######",MA:["+212 # ## ## ## ##","+212 ##-#######"],MC:["+377 ## ## ## ##","+377 # ## ## ## ##"],MD:["+373 ## ### ###","+373 ### ## ###","+373 ### #####"],ME:"+382 ## ### ###",MF:"+590 ### ## ## ##",MG:"+261 ## ## ### ##",MH:"+692 ###-####",MK:["+389 # ### ####","+389 ## ### ###","+389 ### # ## ##"],ML:"+223 ## ## ## ##",MM:["+95 # ### ###","+95 # ### ####","+95 ### ### ####"],MN:"+976 #### ####",MO:["+853 #### ####","+853 #### ###"],MP:"+1 ###-###-####",MQ:"+596 ### ## ## ##",MR:"+222 ## ## ## ##",MS:"+1 ###-###-####",MT:"+356 #### ####",MU:["+230 #### ####","+230 ### ####"],MV:["+960 ###-####","+960 ### ### ####"],MW:["+265 # ### ###","+265 ### ## ## ##"],MX:"+52 ### ### ####",MY:["+60 #-#### ####","+60 ##-### ####","+60 #-###-##-####","+60 ###-### ####"],MZ:["+258 ## ### ###","+258 ## ### ####","+258 ### ### ###"],NA:["+264 ## ### ###","+264 ## ### ####","+264 ### ### ###"],NC:"+687 ##.##.##",NE:["+227 ## ## ## ##","+227 ## ### ###"],NF:["+672 ## ####","+672 # #####"],NG:["+234 #### ## ####","+234 ### ### ####","+234 ### #### ####"],NI:"+505 #### ####",NL:["+31 ## ### ####","+31 # ########","+31 ### ####","+31 ## #######"],NO:["+47 ## ## ## ##","+47 ### ## ###"],NP:["+977 #-#######","+977 ###-#######","+977 ###########"],NR:"+674 ### ####",NU:["+683 ####","+683 ### ####"],NZ:["+64 # ### ####","+64 ## ### ####","+64 ### ### ###"],OM:["+968 ## ######","+968 #### ####","+968 ### #####"],PA:["+507 ###-####","+507 ####-####"],PE:["+51 # #######","+51 ### ### ###","+51 ### #####"],PF:["+689 ## ## ## ##","+689 ### ## ## ##"],PG:["+675 ### ####","+675 #### ####"],PH:["+63 # #### ####","+63 ### ### ####","+63 #### # ### ####"],PK:["+92 ## ########","+92 ### #######","+92 ### ### ##","+92 #### #####"],PL:["+48 ## ### ## ##","+48 ### ### ###"],PM:["+508 ## ## ##","+508 ### ## ## ##"],PR:"+1 ###-###-####",PS:["+970 # ### ####","+970 ### ### ###","+970 #### ### ###"],PT:["+351 ## ### ####","+351 ### ### ###"],PW:"+680 ### ####",PY:["+595 ## ### ####","+595 ### ######","+595 #### ### ####"],QA:["+974 #### ####","+974 ### ####"],RE:"+262 ### ## ## ##",RO:["+40 ## ### ####","+40 ### ### ###"],RS:["+381 ## ######","+381 ## #######","+381 ### #####"],RU:"+7 ### ###-##-##",RW:"+250 ### ### ###",SA:["+966 ## ### ####","+966 ### ### ####","+966 #### #####"],SB:["+677 #####","+677 ## #####"],SC:["+248 # ### ###","+248 #######"],SD:"+249 ## ### ####",SE:["+46 # ## ## ##","+46 ## ### ## ##","+46 ## ## ## ##","+46 ### ## ## ###"],SG:["+65 #### ####","+65 #### ### ####"],SH:"+290 #####",SI:["+386 # ### ## ##","+386 ## ### ###","+386 ## ######","+386 ### #####"],SJ:["+47 ## ## ## ##","+47 ### ## ###"],SK:["+421 #/### ### ##","+421 ### ### ###","+421 #######"],SL:"+232 ## ######",SM:["+378 #### ######","+378 ## ## ## ##"],SN:["+221 ## ### ## ##","+221 ### ## ## ##"],SO:["+252 # ######","+252 # #######"],SR:["+597 ###-###","+597 ###-####","+597 ##-##-##"],SS:"+211 ### ### ###",ST:"+239 ### ####",SV:["+503 #### ####","+503 ### ####"],SX:"+1 ###-###-####",SY:["+963 ## ### ####","+963 ### ### ###"],SZ:["+268 #### ####","+268 ##### ####"],TA:"+290 ####",TC:"+1 ###-###-####",TD:"+235 ## ## ## ##",TG:"+228 ## ## ## ##",TH:["+66 # ### ####","+66 ## ### ####","+66 #### ### ###"],TJ:["+992 ### ## ####","+992 ## ### ####"],TK:"+690 ####",TL:["+670 ### ####","+670 #### ####"],TM:["+993 ## ##-##-##","+993 ## ######"],TN:"+216 ## ### ###",TO:["+676 ##-###","+676 ### ####","+676 #### ###"],TR:["+90 ### ### ## ##","+90 ### ### ####"],TT:"+1 ###-###-####",TV:["+688 ## ###","+688 ## ####"],TW:["+886 # #### ####","+886 ### ### ###","+886 ## ### ####","+886 ## #### ####"],TZ:["+255 ## ### ####","+255 ### ### ###","+255 ### ## ####"],UA:["+380 #### #####","+380 ## ### ####","+380 ### ### ###"],UG:["+256 ## #######","+256 ### ######"],US:"+1 ###-###-####",UY:["+598 #### ####","+598 ## ### ###","+598 ### ####"],UZ:"+998 ## ### ## ##",VA:["+39 ## #### ####","+39 ### ### ####","+39 ### ### ###"],VC:"+1 ###-###-####",VE:"+58 ###-#######",VG:"+1 ###-###-####",VI:"+1 ###-###-####",VN:["+84 ### #### ###","+84 ### ### ###","+84 #### ######","+84 ## ### ## ##"],VU:["+678 #####","+678 ### ####"],WF:["+681 ## ## ##","+681 ### ## ## ##"],WS:["+685 #####","+685 ## #####","+685 ### ###"],XK:["+383 ## ### ###","+383 ### #####"],YE:["+967 # ### ###","+967 ### ### ###"],YT:"+262 ### ## ## ##",ZA:["+27 ## ### ####","+27 ### ### ###"],ZM:["+260 ### ### ###","+260 ## #######","+260 #########"],ZW:["+263 ## #####","+263 ## ### ####","+263 ### ####","+263 #### ######"]},CC_REGEX=/^[a-z]{2}$/i,countryCodeEmoji=t=>{if(!CC_REGEX.test(t)){const e=typeof t;throw new TypeError(`cc argument must be an ISO 3166-1 alpha-2 string, but got '${"string"===e?t:e}' instead.`)}const e=[...t.toUpperCase()].map(t=>(t.codePointAt(0)??0)+127397);return String.fromCodePoint(...e)},dataEntries=Object.entries(data),divideMask=t=>t.split(/ (.*)/s);function getCodeAndMask(t){let e="",s="";if(Array.isArray(t)){const a=[];for(const s of t){const[t,o]=divideMask(s);e||(e=t),a.push(o)}s=a}else{const[a,o]=divideMask(t);e=a,s=o}return[e,s]}const MasksBaseMap=data,MasksBase=dataEntries.map(([t,e])=>({id:t,mask:e})),MasksMap=dataEntries.reduce((t,[e,s])=>{const[a,o]=getCodeAndMask(s);return t[e]={code:a,mask:o},t},{}),Masks=dataEntries.map(([t,e])=>{const[s,a]=getCodeAndMask(e);return{id:t,code:s,mask:a}}),MasksWithFlagMap=dataEntries.reduce((t,[e,s])=>{const[a,o]=getCodeAndMask(s);return t[e]={code:a,mask:o,flag:countryCodeEmoji(e)},t},{}),MasksWithFlag=dataEntries.map(([t,e])=>{const[s,a]=getCodeAndMask(e);return{id:t,code:s,mask:a,flag:countryCodeEmoji(t)}}),MasksFullMapEn=dataEntries.reduce((t,[e,s])=>{const[a,o]=getCodeAndMask(s),n=new Intl.DisplayNames(["en"],{type:"region"});return t[e]={code:a,mask:o,name:n.of(e)??"",flag:countryCodeEmoji(e)},t},{}),MasksFullEn=dataEntries.map(([t,e])=>{const[s,a]=getCodeAndMask(e);return{id:t,code:s,mask:a,name:new Intl.DisplayNames(["en"],{type:"region"}).of(t)??"",flag:countryCodeEmoji(t)}}),getFlagEmoji=countryCodeEmoji;function countPlaceholders(t){return(t.match(/#/g)||[]).length}exports.Masks=Masks,exports.MasksBase=MasksBase,exports.MasksBaseMap=MasksBaseMap,exports.MasksFull=t=>{const e=new Intl.DisplayNames([t],{type:"region"});return dataEntries.map(([t,s])=>{const[a,o]=getCodeAndMask(s);return{id:t,code:a,mask:o,name:e.of(t)??"",flag:countryCodeEmoji(t)}})},exports.MasksFullEn=MasksFullEn,exports.MasksFullMap=t=>{const e=new Intl.DisplayNames([t],{type:"region"});return dataEntries.reduce((t,[s,a])=>{const[o,n]=getCodeAndMask(a),r=e.of(s)??"";return t[s]={code:o,mask:n,name:r,flag:countryCodeEmoji(s)},t},{})},exports.MasksFullMapEn=MasksFullMapEn,exports.MasksMap=MasksMap,exports.MasksWithFlag=MasksWithFlag,exports.MasksWithFlagMap=MasksWithFlagMap,exports.countPlaceholders=countPlaceholders,exports.formatDigitsWithMap=function formatDigitsWithMap(t,e){let s="";const a=[];let o=0;const n=e.length,r=t.length;for(let M=0;M<r;M++){const r=t[M];if("#"===r){if(!(o<n))break;s+=e[o],a.push(o),o++}else{const e=-1!==t.indexOf("#",M+1)&&o<n;(s.length>0||e)&&(s+=r,a.push(-1))}}return{display:s,map:a}},exports.getFlagEmoji=getFlagEmoji,exports.pickMaskVariant=function pickMaskVariant(t,e){if(1===t.length)return t[0];const s=t.map(t=>({mask:t,count:countPlaceholders(t)})),a=s.filter(t=>t.count>=e).sort((t,e)=>t.count-e.count);if(a.length>0)return a[0].mask;const o=s.sort((t,e)=>e.count-t.count)[0];return o?o.mask:t[0]},exports.removeCountryCodePrefix=function removeCountryCodePrefix(t){return t.replace(/^\+\d+\s?/,"")},exports.toArray=function toArray(t){return Array.isArray(t)?t:[t]};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const data={AC:"+247 #####",AD:["+376 ### ###","+376 #### ####"],AE:["+971 # ### ####","+971 ## ### ####","+971 ### ######","+971 ### # #####"],AF:"+93 ## ### ####",AG:"+1 ###-###-####",AI:"+1 ###-###-####",AL:["+355 ## ### ###","+355 ## ### ####","+355 ### ####","+355 ### ###","+355 ### #####"],AM:["+374 ## ######","+374 ### ## ###"],AO:"+244 ### ### ###",AR:["+54 ## ####-####","+54 # ## ####-####","+54 ###-###-####"],AS:"+1 ###-###-####",AT:["+43 # #########","+43 ### ######"],AU:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###","+61 ## ### ##"],AW:"+297 ### ####",AX:["+358 ## #######","+358 ### ######"],AZ:["+994 ## ### ## ##","+994 ### ## ## ##"],BA:["+387 ## ###-###","+387 ## ### ###"],BB:"+1 ###-###-####",BD:["+880 #-#######","+880 ####-######","+880 ###-#######"],BE:["+32 ## ## ## ##","+32 ### ## ## ##","+32 ### ## ###"],BF:"+226 ## ## ## ##",BG:["+359 # ### ###","+359 ## ### ###","+359 ### ## ###"],BH:"+973 #### ####",BI:"+257 ## ## ## ##",BJ:["+229 ## ## ## ## ##","+229 ## ## ## ##"],BL:"+590 ### ## ## ##",BM:"+1 ###-###-####",BN:"+673 ### ####",BO:["+591 # #######","+591 ########","+591 ### ## ####"],BQ:"+599 ### ####",BR:["+55 ## ####-####","+55 ## #####-####","+55 ### ## ####","+55 ####-####"],BS:"+1 ###-###-####",BT:["+975 # ### ###","+975 ## ## ## ##"],BW:["+267 ### ####","+267 ## ### ###","+267 #### ### ###","+267 ## #####"],BY:["+375 ### ##-##-##","+375 ## ###-##-##","+375 ### ### ####"],BZ:["+501 ###-####","+501 #-###-####-###"],CA:"+1 ###-###-####",CC:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###"],CD:["+243 ## #####","+243 ### ### ###"],CF:"+236 ## ## ## ##",CG:["+242 ## ### ####","+242 # #### ####"],CH:["+41 ## ### ## ##","+41 ### ### ###"],CI:["+225 ## ## # #####","+225 ## ## ## ####"],CK:"+682 ## ###",CL:["+56 ### ### ###","+56 # #### ####","+56 ### ### ####","+56 ## ### ####"],CM:["+237 # ## ## ## ##","+237 ## ## ## ##"],CN:["+86 ## #### ####","+86 ### #### ####","+86 ### ### ####","+86 ########"],CO:["+57 ### #######","+57 # ### #######"],CR:["+506 #### ####","+506 ###-###-####"],CU:["+53 # #######","+53 ### #######"],CV:"+238 ### ## ##",CW:["+599 # ### ####","+599 ### ####"],CX:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###"],CY:"+357 ## ######",CZ:"+420 ### ### ###",DE:["+49 ## ######","+49 #### #######","+49 ### ##########","+49 ### # ######","+49 ### # ####","+49 ### #### ####","+49 ########"],DJ:"+253 ## ## ## ##",DK:"+45 ## ## ## ##",DM:"+1 ###-###-####",DO:"+1 ###-###-####",DZ:["+213 ## ## ## ##","+213 ### ## ## ##","+213 ## ### ## ##"],EC:["+593 #-###-####","+593 ## ### ####","+593 #### ### ####"],EE:["+372 ### ####","+372 #### ####","+372 ## ## ####"],EG:["+20 # ########","+20 ## ########","+20 ### ### ####"],EH:["+212 # ## ## ## ##","+212 ##-#######"],ER:"+291 # ### ###",ES:["+34 ### ## ## ##","+34 ### ### ###"],ET:"+251 ## ### ####",FI:["+358 ## #######","+358 ### ######"],FJ:["+679 ### ####","+679 #### ### ####"],FK:"+500 #####",FM:"+691 ### ####",FO:"+298 ######",FR:["+33 # ## ## ## ##","+33 ### ## ## ##"],GA:"+241 ## ## ## ##",GB:["+44 ### ### ####","+44 #### ######","+44 ## #### ####"],GD:"+1 ###-###-####",GE:["+995 ## ### ## ##","+995 ### ## ## ##","+995 ### ### ###"],GF:"+594 ### ## ## ##",GG:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],GH:["+233 ## ### ####","+233 ### #####"],GI:["+350 ### #####","+350 ########"],GL:"+299 ## ## ##",GM:"+220 ### ####",GN:["+224 ## ## ## ##","+224 ### ## ## ##"],GP:"+590 ### ## ## ##",GQ:["+240 ### ### ###","+240 ### ######"],GR:["+30 ## #### ####","+30 ### ### ####"],GT:["+502 #### ####","+502 #### ### ####"],GU:"+1 ###-###-####",GW:["+245 ### ### ###","+245 ### ####"],GY:"+592 ### ####",HK:["+852 #### ####","+852 ### ### ###","+852 ### ## ### ###"],HN:["+504 ####-####","+504 ###########"],HR:["+385 # #### ###","+385 ## ### ####","+385 ### ### ###","+385 ## ## ###","+385 ## ### ###"],HT:"+509 ## ## ####",HU:["+36 # ### ####","+36 ## ### ####","+36 ## ### ###"],ID:["+62 ## #######","+62 ###-###-###","+62 ### #######","+62 ### # ### ###","+62 ### ### ####"],IE:["+353 ## #####","+353 ## ### ####","+353 #### ### ###","+353 ### ### ###"],IL:["+972 #-###-####","+972 ##-###-####","+972 #-###-###-###"],IM:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],IN:["+91 ##### #####","+91 #### ## ####","+91 #### ### ### ###","+91 #### ### ####"],IO:"+246 ### ####",IQ:["+964 # ### ####","+964 ### ### ####"],IR:["+98 ## #### ####","+98 ### ### ####"],IS:"+354 ### ####",IT:["+39 ## #### ####","+39 ### ### ####","+39 ### ### ###"],JE:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],JM:"+1 ###-###-####",JO:["+962 # ### ####","+962 # #### ####","+962 ### #####","+962 ## #######"],JP:["+81 #-####-####","+81 ##-####-####","+81 ###-###-###","+81 ##-###-####"],KE:["+254 ## #######","+254 ### ######","+254 ### ### ###"],KG:["+996 ### ### ###","+996 ### ### # ##"],KH:["+855 ## ### ###","+855 #### ### ###"],KI:["+686 #####","+686 ########"],KM:"+269 ### ## ##",KN:"+1 ###-###-####",KP:["+850 # ### ####","+850 ### ### ####"],KR:["+82 #-###-####","+82 ##-####-####","+82 ##-###-####"],KW:["+965 #### ####","+965 ### #####","+965 #### ###"],KY:"+1 ###-###-####",KZ:["+7 ##### # ## ##","+7 ### ### ####","+7 ### ###-##-##"],LA:["+856 ## ### ###","+856 ## ## ### ###"],LB:["+961 # ### ###","+961 ## ### ###"],LC:"+1 ###-###-####",LI:["+423 ### ## ##","+423 ### ### ###"],LK:["+94 ### ### ###","+94 ## ### ####"],LR:["+231 ## ### ###","+231 ## ### ####"],LS:"+266 #### ####",LT:["+370 ### #####","+370 ### ## ###"],LU:["+352 ## ## ## ##","+352 ### ### ###","+352 ### ## ###"],LV:"+371 ## ### ###",LY:"+218 ##-#######",MA:["+212 # ## ## ## ##","+212 ##-#######"],MC:["+377 ## ## ## ##","+377 # ## ## ## ##"],MD:["+373 ## ### ###","+373 ### ## ###","+373 ### #####"],ME:"+382 ## ### ###",MF:"+590 ### ## ## ##",MG:"+261 ## ## ### ##",MH:"+692 ###-####",MK:["+389 # ### ####","+389 ## ### ###","+389 ### # ## ##"],ML:"+223 ## ## ## ##",MM:["+95 # ### ###","+95 # ### ####","+95 ### ### ####"],MN:"+976 #### ####",MO:["+853 #### ####","+853 #### ###"],MP:"+1 ###-###-####",MQ:"+596 ### ## ## ##",MR:"+222 ## ## ## ##",MS:"+1 ###-###-####",MT:"+356 #### ####",MU:["+230 #### ####","+230 ### ####"],MV:["+960 ###-####","+960 ### ### ####"],MW:["+265 # ### ###","+265 ### ## ## ##"],MX:"+52 ### ### ####",MY:["+60 #-#### ####","+60 ##-### ####","+60 #-###-##-####","+60 ###-### ####"],MZ:["+258 ## ### ###","+258 ## ### ####","+258 ### ### ###"],NA:["+264 ## ### ###","+264 ## ### ####","+264 ### ### ###"],NC:"+687 ##.##.##",NE:["+227 ## ## ## ##","+227 ## ### ###"],NF:["+672 ## ####","+672 # #####"],NG:["+234 #### ## ####","+234 ### ### ####","+234 ### #### ####"],NI:"+505 #### ####",NL:["+31 ## ### ####","+31 # ########","+31 ### ####","+31 ## #######"],NO:["+47 ## ## ## ##","+47 ### ## ###"],NP:["+977 #-#######","+977 ###-#######","+977 ###########"],NR:"+674 ### ####",NU:["+683 ####","+683 ### ####"],NZ:["+64 # ### ####","+64 ## ### ####","+64 ### ### ###"],OM:["+968 ## ######","+968 #### ####","+968 ### #####"],PA:["+507 ###-####","+507 ####-####"],PE:["+51 # #######","+51 ### ### ###","+51 ### #####"],PF:["+689 ## ## ## ##","+689 ### ## ## ##"],PG:["+675 ### ####","+675 #### ####"],PH:["+63 # #### ####","+63 ### ### ####","+63 #### # ### ####"],PK:["+92 ## ########","+92 ### #######","+92 ### ### ##","+92 #### #####"],PL:["+48 ## ### ## ##","+48 ### ### ###"],PM:["+508 ## ## ##","+508 ### ## ## ##"],PR:"+1 ###-###-####",PS:["+970 # ### ####","+970 ### ### ###","+970 #### ### ###"],PT:["+351 ## ### ####","+351 ### ### ###"],PW:"+680 ### ####",PY:["+595 ## ### ####","+595 ### ######","+595 #### ### ####"],QA:["+974 #### ####","+974 ### ####"],RE:"+262 ### ## ## ##",RO:["+40 ## ### ####","+40 ### ### ###"],RS:["+381 ## ######","+381 ## #######","+381 ### #####"],RU:"+7 ### ###-##-##",RW:"+250 ### ### ###",SA:["+966 ## ### ####","+966 ### ### ####","+966 #### #####"],SB:["+677 #####","+677 ## #####"],SC:["+248 # ### ###","+248 #######"],SD:"+249 ## ### ####",SE:["+46 # ## ## ##","+46 ## ### ## ##","+46 ## ## ## ##","+46 ### ## ## ###"],SG:["+65 #### ####","+65 #### ### ####"],SH:"+290 #####",SI:["+386 # ### ## ##","+386 ## ### ###","+386 ## ######","+386 ### #####"],SJ:["+47 ## ## ## ##","+47 ### ## ###"],SK:["+421 #/### ### ##","+421 ### ### ###","+421 #######"],SL:"+232 ## ######",SM:["+378 #### ######","+378 ## ## ## ##"],SN:["+221 ## ### ## ##","+221 ### ## ## ##"],SO:["+252 # ######","+252 # #######"],SR:["+597 ###-###","+597 ###-####","+597 ##-##-##"],SS:"+211 ### ### ###",ST:"+239 ### ####",SV:["+503 #### ####","+503 ### ####"],SX:"+1 ###-###-####",SY:["+963 ## ### ####","+963 ### ### ###"],SZ:["+268 #### ####","+268 ##### ####"],TA:"+290 ####",TC:"+1 ###-###-####",TD:"+235 ## ## ## ##",TG:"+228 ## ## ## ##",TH:["+66 # ### ####","+66 ## ### ####","+66 #### ### ###"],TJ:["+992 ### ## ####","+992 ## ### ####"],TK:"+690 ####",TL:["+670 ### ####","+670 #### ####"],TM:["+993 ## ##-##-##","+993 ## ######"],TN:"+216 ## ### ###",TO:["+676 ##-###","+676 ### ####","+676 #### ###"],TR:["+90 ### ### ## ##","+90 ### ### ####"],TT:"+1 ###-###-####",TV:["+688 ## ###","+688 ## ####"],TW:["+886 # #### ####","+886 ### ### ###","+886 ## ### ####","+886 ## #### ####"],TZ:["+255 ## ### ####","+255 ### ### ###","+255 ### ## ####"],UA:["+380 #### #####","+380 ## ### ####","+380 ### ### ###"],UG:["+256 ## #######","+256 ### ######"],US:"+1 ###-###-####",UY:["+598 #### ####","+598 ## ### ###","+598 ### ####"],UZ:"+998 ## ### ## ##",VA:["+39 ## #### ####","+39 ### ### ####","+39 ### ### ###"],VC:"+1 ###-###-####",VE:"+58 ###-#######",VG:"+1 ###-###-####",VI:"+1 ###-###-####",VN:["+84 ### #### ###","+84 ### ### ###","+84 #### ######","+84 ## ### ## ##"],VU:["+678 #####","+678 ### ####"],WF:["+681 ## ## ##","+681 ### ## ## ##"],WS:["+685 #####","+685 ## #####","+685 ### ###"],XK:["+383 ## ### ###","+383 ### #####"],YE:["+967 # ### ###","+967 ### ### ###"],YT:"+262 ### ## ## ##",ZA:["+27 ## ### ####","+27 ### ### ###"],ZM:["+260 ### ### ###","+260 ## #######","+260 #########"],ZW:["+263 ## #####","+263 ## ### ####","+263 ### ####","+263 #### ######"]},CC_REGEX=/^[a-z]{2}$/i,countryCodeEmoji=t=>{if(!CC_REGEX.test(t)){const e=typeof t;throw new TypeError(`cc argument must be an ISO 3166-1 alpha-2 string, but got '${"string"===e?t:e}' instead.`)}const e=[...t.toUpperCase()].map(t=>(t.codePointAt(0)??0)+127397);return String.fromCodePoint(...e)},dataEntries=Object.entries(data),divideMask=t=>t.split(/ (.*)/s);function getCodeAndMask(t){let e="",o="";if(Array.isArray(t)){const a=[];for(const o of t){const[t,s]=divideMask(o);e||(e=t),a.push(s)}o=a}else{const[a,s]=divideMask(t);e=a,o=s}return[e,o]}const MasksBaseMap=data,MasksBase=dataEntries.map(([t,e])=>({id:t,mask:e})),MasksMap=dataEntries.reduce((t,[e,o])=>{const[a,s]=getCodeAndMask(o);return t[e]={code:a,mask:s},t},{}),Masks=dataEntries.map(([t,e])=>{const[o,a]=getCodeAndMask(e);return{id:t,code:o,mask:a}}),MasksWithFlagMap=dataEntries.reduce((t,[e,o])=>{const[a,s]=getCodeAndMask(o);return t[e]={code:a,mask:s,flag:countryCodeEmoji(e)},t},{}),MasksWithFlag=dataEntries.map(([t,e])=>{const[o,a]=getCodeAndMask(e);return{id:t,code:o,mask:a,flag:countryCodeEmoji(t)}}),MasksFullMap=t=>{const e=new Intl.DisplayNames([t],{type:"region"});return dataEntries.reduce((t,[o,a])=>{const[s,n]=getCodeAndMask(a),r=e.of(o)??"";return t[o]={code:s,mask:n,name:r,flag:countryCodeEmoji(o)},t},{})},MasksFullMapEn=dataEntries.reduce((t,[e,o])=>{const[a,s]=getCodeAndMask(o),n=new Intl.DisplayNames(["en"],{type:"region"});return t[e]={code:a,mask:s,name:n.of(e)??"",flag:countryCodeEmoji(e)},t},{}),MasksFullEn=dataEntries.map(([t,e])=>{const[o,a]=getCodeAndMask(e);return{id:t,code:o,mask:a,name:new Intl.DisplayNames(["en"],{type:"region"}).of(t)??"",flag:countryCodeEmoji(t)}}),getFlagEmoji=countryCodeEmoji,CACHE_KEY="@desource/phone-mask:geo";async function detectCountryFromGeoIP(t="https://ipapi.co/json/",e=1500){const o=new AbortController,a=setTimeout(()=>o.abort(),e);try{const e=await fetch(t,{signal:o.signal,headers:{Accept:"application/json"}});if(clearTimeout(a),!e.ok)return null;const s=await e.json();return(s.country||s.country_code||s.countryCode||s.country_code2||"").toString().toUpperCase()||null}catch{return clearTimeout(a),null}}function getMasksFullMapByLocale(t){return t.toLowerCase().startsWith("en")?MasksFullMapEn:MasksFullMap(t)}function countPlaceholders(t){return(t.match(/#/g)||[]).length}exports.CACHE_EXPIRY_MS=864e5,exports.CACHE_KEY=CACHE_KEY,exports.GEO_IP_API_URL="https://ipapi.co/json/",exports.GEO_IP_TIMEOUT_MS=1500,exports.Masks=Masks,exports.MasksBase=MasksBase,exports.MasksBaseMap=MasksBaseMap,exports.MasksFull=t=>{const e=new Intl.DisplayNames([t],{type:"region"});return dataEntries.map(([t,o])=>{const[a,s]=getCodeAndMask(o);return{id:t,code:a,mask:s,name:e.of(t)??"",flag:countryCodeEmoji(t)}})},exports.MasksFullEn=MasksFullEn,exports.MasksFullMap=MasksFullMap,exports.MasksFullMapEn=MasksFullMapEn,exports.MasksMap=MasksMap,exports.MasksWithFlag=MasksWithFlag,exports.MasksWithFlagMap=MasksWithFlagMap,exports.countPlaceholders=countPlaceholders,exports.detectByGeoIp=async function detectByGeoIp(t){try{const e=localStorage.getItem(CACHE_KEY);if(e){const o=JSON.parse(e),a=Date.now()-o.ts>864e5;if(!a&&o.country_code&&t(o.country_code))return o.country_code.toUpperCase();a&&localStorage.removeItem(CACHE_KEY)}}catch{}const e=await detectCountryFromGeoIP();if(e&&t(e)){try{localStorage.setItem(CACHE_KEY,JSON.stringify({country_code:e,ts:Date.now()}))}catch{}return e}return null},exports.detectCountryFromGeoIP=detectCountryFromGeoIP,exports.formatDigitsWithMap=function formatDigitsWithMap(t,e){let o="";const a=[];let s=0;const n=e.length,r=t.length;for(let c=0;c<r;c++){const r=t[c];if("#"===r){if(!(s<n))break;o+=e[s],a.push(s),s++}else{const e=-1!==t.indexOf("#",c+1)&&s<n;(o.length>0||e)&&(o+=r,a.push(-1))}}return{display:o,map:a}},exports.getCountry=function getCountry(t,e){const o=getMasksFullMapByLocale(e),a=t.toUpperCase();return a in o?{id:a,...o[a]}:{id:"US",...o.US}},exports.getFlagEmoji=getFlagEmoji,exports.getMasksFullMapByLocale=getMasksFullMapByLocale,exports.getNavigatorLang=function getNavigatorLang(){return"undefined"!=typeof navigator&&navigator.language||"en"},exports.pickMaskVariant=function pickMaskVariant(t,e){if(1===t.length)return t[0];const o=t.map(t=>({mask:t,count:countPlaceholders(t)})),a=o.filter(t=>t.count>=e).sort((t,e)=>t.count-e.count);if(a.length>0)return a[0].mask;const s=o.sort((t,e)=>e.count-t.count)[0];return s?s.mask:t[0]},exports.removeCountryCodePrefix=function removeCountryCodePrefix(t){return t.replace(/^\+\d+\s?/,"")},exports.toArray=function toArray(t){return Array.isArray(t)?t:[t]};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).phoneMask={})}(this,function(e){"use strict";const t={AC:"+247 #####",AD:["+376 ### ###","+376 #### ####"],AE:["+971 # ### ####","+971 ## ### ####","+971 ### ######","+971 ### # #####"],AF:"+93 ## ### ####",AG:"+1 ###-###-####",AI:"+1 ###-###-####",AL:["+355 ## ### ###","+355 ## ### ####","+355 ### ####","+355 ### ###","+355 ### #####"],AM:["+374 ## ######","+374 ### ## ###"],AO:"+244 ### ### ###",AR:["+54 ## ####-####","+54 # ## ####-####","+54 ###-###-####"],AS:"+1 ###-###-####",AT:["+43 # #########","+43 ### ######"],AU:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###","+61 ## ### ##"],AW:"+297 ### ####",AX:["+358 ## #######","+358 ### ######"],AZ:["+994 ## ### ## ##","+994 ### ## ## ##"],BA:["+387 ## ###-###","+387 ## ### ###"],BB:"+1 ###-###-####",BD:["+880 #-#######","+880 ####-######","+880 ###-#######"],BE:["+32 ## ## ## ##","+32 ### ## ## ##","+32 ### ## ###"],BF:"+226 ## ## ## ##",BG:["+359 # ### ###","+359 ## ### ###","+359 ### ## ###"],BH:"+973 #### ####",BI:"+257 ## ## ## ##",BJ:["+229 ## ## ## ## ##","+229 ## ## ## ##"],BL:"+590 ### ## ## ##",BM:"+1 ###-###-####",BN:"+673 ### ####",BO:["+591 # #######","+591 ########","+591 ### ## ####"],BQ:"+599 ### ####",BR:["+55 ## ####-####","+55 ## #####-####","+55 ### ## ####","+55 ####-####"],BS:"+1 ###-###-####",BT:["+975 # ### ###","+975 ## ## ## ##"],BW:["+267 ### ####","+267 ## ### ###","+267 #### ### ###","+267 ## #####"],BY:["+375 ### ##-##-##","+375 ## ###-##-##","+375 ### ### ####"],BZ:["+501 ###-####","+501 #-###-####-###"],CA:"+1 ###-###-####",CC:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###"],CD:["+243 ## #####","+243 ### ### ###"],CF:"+236 ## ## ## ##",CG:["+242 ## ### ####","+242 # #### ####"],CH:["+41 ## ### ## ##","+41 ### ### ###"],CI:["+225 ## ## # #####","+225 ## ## ## ####"],CK:"+682 ## ###",CL:["+56 ### ### ###","+56 # #### ####","+56 ### ### ####","+56 ## ### ####"],CM:["+237 # ## ## ## ##","+237 ## ## ## ##"],CN:["+86 ## #### ####","+86 ### #### ####","+86 ### ### ####","+86 ########"],CO:["+57 ### #######","+57 # ### #######"],CR:["+506 #### ####","+506 ###-###-####"],CU:["+53 # #######","+53 ### #######"],CV:"+238 ### ## ##",CW:["+599 # ### ####","+599 ### ####"],CX:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###"],CY:"+357 ## ######",CZ:"+420 ### ### ###",DE:["+49 ## ######","+49 #### #######","+49 ### ##########","+49 ### # ######","+49 ### # ####","+49 ### #### ####","+49 ########"],DJ:"+253 ## ## ## ##",DK:"+45 ## ## ## ##",DM:"+1 ###-###-####",DO:"+1 ###-###-####",DZ:["+213 ## ## ## ##","+213 ### ## ## ##","+213 ## ### ## ##"],EC:["+593 #-###-####","+593 ## ### ####","+593 #### ### ####"],EE:["+372 ### ####","+372 #### ####","+372 ## ## ####"],EG:["+20 # ########","+20 ## ########","+20 ### ### ####"],EH:["+212 # ## ## ## ##","+212 ##-#######"],ER:"+291 # ### ###",ES:["+34 ### ## ## ##","+34 ### ### ###"],ET:"+251 ## ### ####",FI:["+358 ## #######","+358 ### ######"],FJ:["+679 ### ####","+679 #### ### ####"],FK:"+500 #####",FM:"+691 ### ####",FO:"+298 ######",FR:["+33 # ## ## ## ##","+33 ### ## ## ##"],GA:"+241 ## ## ## ##",GB:["+44 ### ### ####","+44 #### ######","+44 ## #### ####"],GD:"+1 ###-###-####",GE:["+995 ## ### ## ##","+995 ### ## ## ##","+995 ### ### ###"],GF:"+594 ### ## ## ##",GG:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],GH:["+233 ## ### ####","+233 ### #####"],GI:["+350 ### #####","+350 ########"],GL:"+299 ## ## ##",GM:"+220 ### ####",GN:["+224 ## ## ## ##","+224 ### ## ## ##"],GP:"+590 ### ## ## ##",GQ:["+240 ### ### ###","+240 ### ######"],GR:["+30 ## #### ####","+30 ### ### ####"],GT:["+502 #### ####","+502 #### ### ####"],GU:"+1 ###-###-####",GW:["+245 ### ### ###","+245 ### ####"],GY:"+592 ### ####",HK:["+852 #### ####","+852 ### ### ###","+852 ### ## ### ###"],HN:["+504 ####-####","+504 ###########"],HR:["+385 # #### ###","+385 ## ### ####","+385 ### ### ###","+385 ## ## ###","+385 ## ### ###"],HT:"+509 ## ## ####",HU:["+36 # ### ####","+36 ## ### ####","+36 ## ### ###"],ID:["+62 ## #######","+62 ###-###-###","+62 ### #######","+62 ### # ### ###","+62 ### ### ####"],IE:["+353 ## #####","+353 ## ### ####","+353 #### ### ###","+353 ### ### ###"],IL:["+972 #-###-####","+972 ##-###-####","+972 #-###-###-###"],IM:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],IN:["+91 ##### #####","+91 #### ## ####","+91 #### ### ### ###","+91 #### ### ####"],IO:"+246 ### ####",IQ:["+964 # ### ####","+964 ### ### ####"],IR:["+98 ## #### ####","+98 ### ### ####"],IS:"+354 ### ####",IT:["+39 ## #### ####","+39 ### ### ####","+39 ### ### ###"],JE:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],JM:"+1 ###-###-####",JO:["+962 # ### ####","+962 # #### ####","+962 ### #####","+962 ## #######"],JP:["+81 #-####-####","+81 ##-####-####","+81 ###-###-###","+81 ##-###-####"],KE:["+254 ## #######","+254 ### ######","+254 ### ### ###"],KG:["+996 ### ### ###","+996 ### ### # ##"],KH:["+855 ## ### ###","+855 #### ### ###"],KI:["+686 #####","+686 ########"],KM:"+269 ### ## ##",KN:"+1 ###-###-####",KP:["+850 # ### ####","+850 ### ### ####"],KR:["+82 #-###-####","+82 ##-####-####","+82 ##-###-####"],KW:["+965 #### ####","+965 ### #####","+965 #### ###"],KY:"+1 ###-###-####",KZ:["+7 ##### # ## ##","+7 ### ### ####","+7 ### ###-##-##"],LA:["+856 ## ### ###","+856 ## ## ### ###"],LB:["+961 # ### ###","+961 ## ### ###"],LC:"+1 ###-###-####",LI:["+423 ### ## ##","+423 ### ### ###"],LK:["+94 ### ### ###","+94 ## ### ####"],LR:["+231 ## ### ###","+231 ## ### ####"],LS:"+266 #### ####",LT:["+370 ### #####","+370 ### ## ###"],LU:["+352 ## ## ## ##","+352 ### ### ###","+352 ### ## ###"],LV:"+371 ## ### ###",LY:"+218 ##-#######",MA:["+212 # ## ## ## ##","+212 ##-#######"],MC:["+377 ## ## ## ##","+377 # ## ## ## ##"],MD:["+373 ## ### ###","+373 ### ## ###","+373 ### #####"],ME:"+382 ## ### ###",MF:"+590 ### ## ## ##",MG:"+261 ## ## ### ##",MH:"+692 ###-####",MK:["+389 # ### ####","+389 ## ### ###","+389 ### # ## ##"],ML:"+223 ## ## ## ##",MM:["+95 # ### ###","+95 # ### ####","+95 ### ### ####"],MN:"+976 #### ####",MO:["+853 #### ####","+853 #### ###"],MP:"+1 ###-###-####",MQ:"+596 ### ## ## ##",MR:"+222 ## ## ## ##",MS:"+1 ###-###-####",MT:"+356 #### ####",MU:["+230 #### ####","+230 ### ####"],MV:["+960 ###-####","+960 ### ### ####"],MW:["+265 # ### ###","+265 ### ## ## ##"],MX:"+52 ### ### ####",MY:["+60 #-#### ####","+60 ##-### ####","+60 #-###-##-####","+60 ###-### ####"],MZ:["+258 ## ### ###","+258 ## ### ####","+258 ### ### ###"],NA:["+264 ## ### ###","+264 ## ### ####","+264 ### ### ###"],NC:"+687 ##.##.##",NE:["+227 ## ## ## ##","+227 ## ### ###"],NF:["+672 ## ####","+672 # #####"],NG:["+234 #### ## ####","+234 ### ### ####","+234 ### #### ####"],NI:"+505 #### ####",NL:["+31 ## ### ####","+31 # ########","+31 ### ####","+31 ## #######"],NO:["+47 ## ## ## ##","+47 ### ## ###"],NP:["+977 #-#######","+977 ###-#######","+977 ###########"],NR:"+674 ### ####",NU:["+683 ####","+683 ### ####"],NZ:["+64 # ### ####","+64 ## ### ####","+64 ### ### ###"],OM:["+968 ## ######","+968 #### ####","+968 ### #####"],PA:["+507 ###-####","+507 ####-####"],PE:["+51 # #######","+51 ### ### ###","+51 ### #####"],PF:["+689 ## ## ## ##","+689 ### ## ## ##"],PG:["+675 ### ####","+675 #### ####"],PH:["+63 # #### ####","+63 ### ### ####","+63 #### # ### ####"],PK:["+92 ## ########","+92 ### #######","+92 ### ### ##","+92 #### #####"],PL:["+48 ## ### ## ##","+48 ### ### ###"],PM:["+508 ## ## ##","+508 ### ## ## ##"],PR:"+1 ###-###-####",PS:["+970 # ### ####","+970 ### ### ###","+970 #### ### ###"],PT:["+351 ## ### ####","+351 ### ### ###"],PW:"+680 ### ####",PY:["+595 ## ### ####","+595 ### ######","+595 #### ### ####"],QA:["+974 #### ####","+974 ### ####"],RE:"+262 ### ## ## ##",RO:["+40 ## ### ####","+40 ### ### ###"],RS:["+381 ## ######","+381 ## #######","+381 ### #####"],RU:"+7 ### ###-##-##",RW:"+250 ### ### ###",SA:["+966 ## ### ####","+966 ### ### ####","+966 #### #####"],SB:["+677 #####","+677 ## #####"],SC:["+248 # ### ###","+248 #######"],SD:"+249 ## ### ####",SE:["+46 # ## ## ##","+46 ## ### ## ##","+46 ## ## ## ##","+46 ### ## ## ###"],SG:["+65 #### ####","+65 #### ### ####"],SH:"+290 #####",SI:["+386 # ### ## ##","+386 ## ### ###","+386 ## ######","+386 ### #####"],SJ:["+47 ## ## ## ##","+47 ### ## ###"],SK:["+421 #/### ### ##","+421 ### ### ###","+421 #######"],SL:"+232 ## ######",SM:["+378 #### ######","+378 ## ## ## ##"],SN:["+221 ## ### ## ##","+221 ### ## ## ##"],SO:["+252 # ######","+252 # #######"],SR:["+597 ###-###","+597 ###-####","+597 ##-##-##"],SS:"+211 ### ### ###",ST:"+239 ### ####",SV:["+503 #### ####","+503 ### ####"],SX:"+1 ###-###-####",SY:["+963 ## ### ####","+963 ### ### ###"],SZ:["+268 #### ####","+268 ##### ####"],TA:"+290 ####",TC:"+1 ###-###-####",TD:"+235 ## ## ## ##",TG:"+228 ## ## ## ##",TH:["+66 # ### ####","+66 ## ### ####","+66 #### ### ###"],TJ:["+992 ### ## ####","+992 ## ### ####"],TK:"+690 ####",TL:["+670 ### ####","+670 #### ####"],TM:["+993 ## ##-##-##","+993 ## ######"],TN:"+216 ## ### ###",TO:["+676 ##-###","+676 ### ####","+676 #### ###"],TR:["+90 ### ### ## ##","+90 ### ### ####"],TT:"+1 ###-###-####",TV:["+688 ## ###","+688 ## ####"],TW:["+886 # #### ####","+886 ### ### ###","+886 ## ### ####","+886 ## #### ####"],TZ:["+255 ## ### ####","+255 ### ### ###","+255 ### ## ####"],UA:["+380 #### #####","+380 ## ### ####","+380 ### ### ###"],UG:["+256 ## #######","+256 ### ######"],US:"+1 ###-###-####",UY:["+598 #### ####","+598 ## ### ###","+598 ### ####"],UZ:"+998 ## ### ## ##",VA:["+39 ## #### ####","+39 ### ### ####","+39 ### ### ###"],VC:"+1 ###-###-####",VE:"+58 ###-#######",VG:"+1 ###-###-####",VI:"+1 ###-###-####",VN:["+84 ### #### ###","+84 ### ### ###","+84 #### ######","+84 ## ### ## ##"],VU:["+678 #####","+678 ### ####"],WF:["+681 ## ## ##","+681 ### ## ## ##"],WS:["+685 #####","+685 ## #####","+685 ### ###"],XK:["+383 ## ### ###","+383 ### #####"],YE:["+967 # ### ###","+967 ### ### ###"],YT:"+262 ### ## ## ##",ZA:["+27 ## ### ####","+27 ### ### ###"],ZM:["+260 ### ### ###","+260 ## #######","+260 #########"],ZW:["+263 ## #####","+263 ## ### ####","+263 ### ####","+263 #### ######"]},n=/^[a-z]{2}$/i,s=e=>{if(!n.test(e)){const t=typeof e;throw new TypeError(`cc argument must be an ISO 3166-1 alpha-2 string, but got '${"string"===t?e:t}' instead.`)}const t=[...e.toUpperCase()].map(e=>(e.codePointAt(0)??0)+127397);return String.fromCodePoint(...t)},o=Object.entries(t),r=e=>e.split(/ (.*)/s);function a(e){let t="",n="";if(Array.isArray(e)){const s=[];for(const n of e){const[e,o]=r(n);t||(t=e),s.push(o)}n=s}else{const[s,o]=r(e);t=s,n=o}return[t,n]}const c=t,i=o.map(([e,t])=>({id:e,mask:t})),M=o.reduce((e,[t,n])=>{const[s,o]=a(n);return e[t]={code:s,mask:o},e},{}),u=o.map(([e,t])=>{const[n,s]=a(t);return{id:e,code:n,mask:s}}),l=o.reduce((e,[t,n])=>{const[o,r]=a(n);return e[t]={code:o,mask:r,flag:s(t)},e},{}),f=o.map(([e,t])=>{const[n,o]=a(t);return{id:e,code:n,mask:o,flag:s(e)}}),p=o.reduce((e,[t,n])=>{const[o,r]=a(n),c=new Intl.DisplayNames(["en"],{type:"region"});return e[t]={code:o,mask:r,name:c.of(t)??"",flag:s(t)},e},{}),m=o.map(([e,t])=>{const[n,o]=a(t);return{id:e,code:n,mask:o,name:new Intl.DisplayNames(["en"],{type:"region"}).of(e)??"",flag:s(e)}}),d=s;function S(e){return(e.match(/#/g)||[]).length}e.Masks=u,e.MasksBase=i,e.MasksBaseMap=c,e.MasksFull=e=>{const t=new Intl.DisplayNames([e],{type:"region"});return o.map(([e,n])=>{const[o,r]=a(n);return{id:e,code:o,mask:r,name:t.of(e)??"",flag:s(e)}})},e.MasksFullEn=m,e.MasksFullMap=e=>{const t=new Intl.DisplayNames([e],{type:"region"});return o.reduce((e,[n,o])=>{const[r,c]=a(o),i=t.of(n)??"";return e[n]={code:r,mask:c,name:i,flag:s(n)},e},{})},e.MasksFullMapEn=p,e.MasksMap=M,e.MasksWithFlag=f,e.MasksWithFlagMap=l,e.countPlaceholders=S,e.formatDigitsWithMap=function(e,t){let n="";const s=[];let o=0;const r=t.length,a=e.length;for(let c=0;c<a;c++){const a=e[c];if("#"===a){if(!(o<r))break;n+=t[o],s.push(o),o++}else{const t=-1!==e.indexOf("#",c+1)&&o<r;(n.length>0||t)&&(n+=a,s.push(-1))}}return{display:n,map:s}},e.getFlagEmoji=d,e.pickMaskVariant=function(e,t){if(1===e.length)return e[0];const n=e.map(e=>({mask:e,count:S(e)})),s=n.filter(e=>e.count>=t).sort((e,t)=>e.count-t.count);if(s.length>0)return s[0].mask;const o=n.sort((e,t)=>t.count-e.count)[0];return o?o.mask:e[0]},e.removeCountryCodePrefix=function(e){return e.replace(/^\+\d+\s?/,"")},e.toArray=function(e){return Array.isArray(e)?e:[e]},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).phoneMask={})}(this,function(t){"use strict";const e={AC:"+247 #####",AD:["+376 ### ###","+376 #### ####"],AE:["+971 # ### ####","+971 ## ### ####","+971 ### ######","+971 ### # #####"],AF:"+93 ## ### ####",AG:"+1 ###-###-####",AI:"+1 ###-###-####",AL:["+355 ## ### ###","+355 ## ### ####","+355 ### ####","+355 ### ###","+355 ### #####"],AM:["+374 ## ######","+374 ### ## ###"],AO:"+244 ### ### ###",AR:["+54 ## ####-####","+54 # ## ####-####","+54 ###-###-####"],AS:"+1 ###-###-####",AT:["+43 # #########","+43 ### ######"],AU:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###","+61 ## ### ##"],AW:"+297 ### ####",AX:["+358 ## #######","+358 ### ######"],AZ:["+994 ## ### ## ##","+994 ### ## ## ##"],BA:["+387 ## ###-###","+387 ## ### ###"],BB:"+1 ###-###-####",BD:["+880 #-#######","+880 ####-######","+880 ###-#######"],BE:["+32 ## ## ## ##","+32 ### ## ## ##","+32 ### ## ###"],BF:"+226 ## ## ## ##",BG:["+359 # ### ###","+359 ## ### ###","+359 ### ## ###"],BH:"+973 #### ####",BI:"+257 ## ## ## ##",BJ:["+229 ## ## ## ## ##","+229 ## ## ## ##"],BL:"+590 ### ## ## ##",BM:"+1 ###-###-####",BN:"+673 ### ####",BO:["+591 # #######","+591 ########","+591 ### ## ####"],BQ:"+599 ### ####",BR:["+55 ## ####-####","+55 ## #####-####","+55 ### ## ####","+55 ####-####"],BS:"+1 ###-###-####",BT:["+975 # ### ###","+975 ## ## ## ##"],BW:["+267 ### ####","+267 ## ### ###","+267 #### ### ###","+267 ## #####"],BY:["+375 ### ##-##-##","+375 ## ###-##-##","+375 ### ### ####"],BZ:["+501 ###-####","+501 #-###-####-###"],CA:"+1 ###-###-####",CC:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###"],CD:["+243 ## #####","+243 ### ### ###"],CF:"+236 ## ## ## ##",CG:["+242 ## ### ####","+242 # #### ####"],CH:["+41 ## ### ## ##","+41 ### ### ###"],CI:["+225 ## ## # #####","+225 ## ## ## ####"],CK:"+682 ## ###",CL:["+56 ### ### ###","+56 # #### ####","+56 ### ### ####","+56 ## ### ####"],CM:["+237 # ## ## ## ##","+237 ## ## ## ##"],CN:["+86 ## #### ####","+86 ### #### ####","+86 ### ### ####","+86 ########"],CO:["+57 ### #######","+57 # ### #######"],CR:["+506 #### ####","+506 ###-###-####"],CU:["+53 # #######","+53 ### #######"],CV:"+238 ### ## ##",CW:["+599 # ### ####","+599 ### ####"],CX:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###"],CY:"+357 ## ######",CZ:"+420 ### ### ###",DE:["+49 ## ######","+49 #### #######","+49 ### ##########","+49 ### # ######","+49 ### # ####","+49 ### #### ####","+49 ########"],DJ:"+253 ## ## ## ##",DK:"+45 ## ## ## ##",DM:"+1 ###-###-####",DO:"+1 ###-###-####",DZ:["+213 ## ## ## ##","+213 ### ## ## ##","+213 ## ### ## ##"],EC:["+593 #-###-####","+593 ## ### ####","+593 #### ### ####"],EE:["+372 ### ####","+372 #### ####","+372 ## ## ####"],EG:["+20 # ########","+20 ## ########","+20 ### ### ####"],EH:["+212 # ## ## ## ##","+212 ##-#######"],ER:"+291 # ### ###",ES:["+34 ### ## ## ##","+34 ### ### ###"],ET:"+251 ## ### ####",FI:["+358 ## #######","+358 ### ######"],FJ:["+679 ### ####","+679 #### ### ####"],FK:"+500 #####",FM:"+691 ### ####",FO:"+298 ######",FR:["+33 # ## ## ## ##","+33 ### ## ## ##"],GA:"+241 ## ## ## ##",GB:["+44 ### ### ####","+44 #### ######","+44 ## #### ####"],GD:"+1 ###-###-####",GE:["+995 ## ### ## ##","+995 ### ## ## ##","+995 ### ### ###"],GF:"+594 ### ## ## ##",GG:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],GH:["+233 ## ### ####","+233 ### #####"],GI:["+350 ### #####","+350 ########"],GL:"+299 ## ## ##",GM:"+220 ### ####",GN:["+224 ## ## ## ##","+224 ### ## ## ##"],GP:"+590 ### ## ## ##",GQ:["+240 ### ### ###","+240 ### ######"],GR:["+30 ## #### ####","+30 ### ### ####"],GT:["+502 #### ####","+502 #### ### ####"],GU:"+1 ###-###-####",GW:["+245 ### ### ###","+245 ### ####"],GY:"+592 ### ####",HK:["+852 #### ####","+852 ### ### ###","+852 ### ## ### ###"],HN:["+504 ####-####","+504 ###########"],HR:["+385 # #### ###","+385 ## ### ####","+385 ### ### ###","+385 ## ## ###","+385 ## ### ###"],HT:"+509 ## ## ####",HU:["+36 # ### ####","+36 ## ### ####","+36 ## ### ###"],ID:["+62 ## #######","+62 ###-###-###","+62 ### #######","+62 ### # ### ###","+62 ### ### ####"],IE:["+353 ## #####","+353 ## ### ####","+353 #### ### ###","+353 ### ### ###"],IL:["+972 #-###-####","+972 ##-###-####","+972 #-###-###-###"],IM:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],IN:["+91 ##### #####","+91 #### ## ####","+91 #### ### ### ###","+91 #### ### ####"],IO:"+246 ### ####",IQ:["+964 # ### ####","+964 ### ### ####"],IR:["+98 ## #### ####","+98 ### ### ####"],IS:"+354 ### ####",IT:["+39 ## #### ####","+39 ### ### ####","+39 ### ### ###"],JE:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],JM:"+1 ###-###-####",JO:["+962 # ### ####","+962 # #### ####","+962 ### #####","+962 ## #######"],JP:["+81 #-####-####","+81 ##-####-####","+81 ###-###-###","+81 ##-###-####"],KE:["+254 ## #######","+254 ### ######","+254 ### ### ###"],KG:["+996 ### ### ###","+996 ### ### # ##"],KH:["+855 ## ### ###","+855 #### ### ###"],KI:["+686 #####","+686 ########"],KM:"+269 ### ## ##",KN:"+1 ###-###-####",KP:["+850 # ### ####","+850 ### ### ####"],KR:["+82 #-###-####","+82 ##-####-####","+82 ##-###-####"],KW:["+965 #### ####","+965 ### #####","+965 #### ###"],KY:"+1 ###-###-####",KZ:["+7 ##### # ## ##","+7 ### ### ####","+7 ### ###-##-##"],LA:["+856 ## ### ###","+856 ## ## ### ###"],LB:["+961 # ### ###","+961 ## ### ###"],LC:"+1 ###-###-####",LI:["+423 ### ## ##","+423 ### ### ###"],LK:["+94 ### ### ###","+94 ## ### ####"],LR:["+231 ## ### ###","+231 ## ### ####"],LS:"+266 #### ####",LT:["+370 ### #####","+370 ### ## ###"],LU:["+352 ## ## ## ##","+352 ### ### ###","+352 ### ## ###"],LV:"+371 ## ### ###",LY:"+218 ##-#######",MA:["+212 # ## ## ## ##","+212 ##-#######"],MC:["+377 ## ## ## ##","+377 # ## ## ## ##"],MD:["+373 ## ### ###","+373 ### ## ###","+373 ### #####"],ME:"+382 ## ### ###",MF:"+590 ### ## ## ##",MG:"+261 ## ## ### ##",MH:"+692 ###-####",MK:["+389 # ### ####","+389 ## ### ###","+389 ### # ## ##"],ML:"+223 ## ## ## ##",MM:["+95 # ### ###","+95 # ### ####","+95 ### ### ####"],MN:"+976 #### ####",MO:["+853 #### ####","+853 #### ###"],MP:"+1 ###-###-####",MQ:"+596 ### ## ## ##",MR:"+222 ## ## ## ##",MS:"+1 ###-###-####",MT:"+356 #### ####",MU:["+230 #### ####","+230 ### ####"],MV:["+960 ###-####","+960 ### ### ####"],MW:["+265 # ### ###","+265 ### ## ## ##"],MX:"+52 ### ### ####",MY:["+60 #-#### ####","+60 ##-### ####","+60 #-###-##-####","+60 ###-### ####"],MZ:["+258 ## ### ###","+258 ## ### ####","+258 ### ### ###"],NA:["+264 ## ### ###","+264 ## ### ####","+264 ### ### ###"],NC:"+687 ##.##.##",NE:["+227 ## ## ## ##","+227 ## ### ###"],NF:["+672 ## ####","+672 # #####"],NG:["+234 #### ## ####","+234 ### ### ####","+234 ### #### ####"],NI:"+505 #### ####",NL:["+31 ## ### ####","+31 # ########","+31 ### ####","+31 ## #######"],NO:["+47 ## ## ## ##","+47 ### ## ###"],NP:["+977 #-#######","+977 ###-#######","+977 ###########"],NR:"+674 ### ####",NU:["+683 ####","+683 ### ####"],NZ:["+64 # ### ####","+64 ## ### ####","+64 ### ### ###"],OM:["+968 ## ######","+968 #### ####","+968 ### #####"],PA:["+507 ###-####","+507 ####-####"],PE:["+51 # #######","+51 ### ### ###","+51 ### #####"],PF:["+689 ## ## ## ##","+689 ### ## ## ##"],PG:["+675 ### ####","+675 #### ####"],PH:["+63 # #### ####","+63 ### ### ####","+63 #### # ### ####"],PK:["+92 ## ########","+92 ### #######","+92 ### ### ##","+92 #### #####"],PL:["+48 ## ### ## ##","+48 ### ### ###"],PM:["+508 ## ## ##","+508 ### ## ## ##"],PR:"+1 ###-###-####",PS:["+970 # ### ####","+970 ### ### ###","+970 #### ### ###"],PT:["+351 ## ### ####","+351 ### ### ###"],PW:"+680 ### ####",PY:["+595 ## ### ####","+595 ### ######","+595 #### ### ####"],QA:["+974 #### ####","+974 ### ####"],RE:"+262 ### ## ## ##",RO:["+40 ## ### ####","+40 ### ### ###"],RS:["+381 ## ######","+381 ## #######","+381 ### #####"],RU:"+7 ### ###-##-##",RW:"+250 ### ### ###",SA:["+966 ## ### ####","+966 ### ### ####","+966 #### #####"],SB:["+677 #####","+677 ## #####"],SC:["+248 # ### ###","+248 #######"],SD:"+249 ## ### ####",SE:["+46 # ## ## ##","+46 ## ### ## ##","+46 ## ## ## ##","+46 ### ## ## ###"],SG:["+65 #### ####","+65 #### ### ####"],SH:"+290 #####",SI:["+386 # ### ## ##","+386 ## ### ###","+386 ## ######","+386 ### #####"],SJ:["+47 ## ## ## ##","+47 ### ## ###"],SK:["+421 #/### ### ##","+421 ### ### ###","+421 #######"],SL:"+232 ## ######",SM:["+378 #### ######","+378 ## ## ## ##"],SN:["+221 ## ### ## ##","+221 ### ## ## ##"],SO:["+252 # ######","+252 # #######"],SR:["+597 ###-###","+597 ###-####","+597 ##-##-##"],SS:"+211 ### ### ###",ST:"+239 ### ####",SV:["+503 #### ####","+503 ### ####"],SX:"+1 ###-###-####",SY:["+963 ## ### ####","+963 ### ### ###"],SZ:["+268 #### ####","+268 ##### ####"],TA:"+290 ####",TC:"+1 ###-###-####",TD:"+235 ## ## ## ##",TG:"+228 ## ## ## ##",TH:["+66 # ### ####","+66 ## ### ####","+66 #### ### ###"],TJ:["+992 ### ## ####","+992 ## ### ####"],TK:"+690 ####",TL:["+670 ### ####","+670 #### ####"],TM:["+993 ## ##-##-##","+993 ## ######"],TN:"+216 ## ### ###",TO:["+676 ##-###","+676 ### ####","+676 #### ###"],TR:["+90 ### ### ## ##","+90 ### ### ####"],TT:"+1 ###-###-####",TV:["+688 ## ###","+688 ## ####"],TW:["+886 # #### ####","+886 ### ### ###","+886 ## ### ####","+886 ## #### ####"],TZ:["+255 ## ### ####","+255 ### ### ###","+255 ### ## ####"],UA:["+380 #### #####","+380 ## ### ####","+380 ### ### ###"],UG:["+256 ## #######","+256 ### ######"],US:"+1 ###-###-####",UY:["+598 #### ####","+598 ## ### ###","+598 ### ####"],UZ:"+998 ## ### ## ##",VA:["+39 ## #### ####","+39 ### ### ####","+39 ### ### ###"],VC:"+1 ###-###-####",VE:"+58 ###-#######",VG:"+1 ###-###-####",VI:"+1 ###-###-####",VN:["+84 ### #### ###","+84 ### ### ###","+84 #### ######","+84 ## ### ## ##"],VU:["+678 #####","+678 ### ####"],WF:["+681 ## ## ##","+681 ### ## ## ##"],WS:["+685 #####","+685 ## #####","+685 ### ###"],XK:["+383 ## ### ###","+383 ### #####"],YE:["+967 # ### ###","+967 ### ### ###"],YT:"+262 ### ## ## ##",ZA:["+27 ## ### ####","+27 ### ### ###"],ZM:["+260 ### ### ###","+260 ## #######","+260 #########"],ZW:["+263 ## #####","+263 ## ### ####","+263 ### ####","+263 #### ######"]},n=/^[a-z]{2}$/i,o=t=>{if(!n.test(t)){const e=typeof t;throw new TypeError(`cc argument must be an ISO 3166-1 alpha-2 string, but got '${"string"===e?t:e}' instead.`)}const e=[...t.toUpperCase()].map(t=>(t.codePointAt(0)??0)+127397);return String.fromCodePoint(...e)},r=Object.entries(e),a=t=>t.split(/ (.*)/s);function s(t){let e="",n="";if(Array.isArray(t)){const o=[];for(const n of t){const[t,r]=a(n);e||(e=t),o.push(r)}n=o}else{const[o,r]=a(t);e=o,n=r}return[e,n]}const c=e,i=r.map(([t,e])=>({id:t,mask:e})),u=r.reduce((t,[e,n])=>{const[o,r]=s(n);return t[e]={code:o,mask:r},t},{}),l=r.map(([t,e])=>{const[n,o]=s(e);return{id:t,code:n,mask:o}}),M=r.reduce((t,[e,n])=>{const[r,a]=s(n);return t[e]={code:r,mask:a,flag:o(e)},t},{}),p=r.map(([t,e])=>{const[n,r]=s(e);return{id:t,code:n,mask:r,flag:o(t)}}),f=t=>{const e=new Intl.DisplayNames([t],{type:"region"});return r.reduce((t,[n,r])=>{const[a,c]=s(r),i=e.of(n)??"";return t[n]={code:a,mask:c,name:i,flag:o(n)},t},{})},d=r.reduce((t,[e,n])=>{const[r,a]=s(n),c=new Intl.DisplayNames(["en"],{type:"region"});return t[e]={code:r,mask:a,name:c.of(e)??"",flag:o(e)},t},{}),g=r.map(([t,e])=>{const[n,r]=s(e);return{id:t,code:n,mask:r,name:new Intl.DisplayNames(["en"],{type:"region"}).of(t)??"",flag:o(t)}}),m=o,S="https://ipapi.co/json/",C="@desource/phone-mask:geo",y=864e5;async function A(t=S,e=1500){const n=new AbortController,o=setTimeout(()=>n.abort(),e);try{const e=await fetch(t,{signal:n.signal,headers:{Accept:"application/json"}});if(clearTimeout(o),!e.ok)return null;const r=await e.json();return(r.country||r.country_code||r.countryCode||r.country_code2||"").toString().toUpperCase()||null}catch{return clearTimeout(o),null}}function T(t){return t.toLowerCase().startsWith("en")?d:f(t)}function G(t){return(t.match(/#/g)||[]).length}t.CACHE_EXPIRY_MS=y,t.CACHE_KEY=C,t.GEO_IP_API_URL=S,t.GEO_IP_TIMEOUT_MS=1500,t.Masks=l,t.MasksBase=i,t.MasksBaseMap=c,t.MasksFull=t=>{const e=new Intl.DisplayNames([t],{type:"region"});return r.map(([t,n])=>{const[r,a]=s(n);return{id:t,code:r,mask:a,name:e.of(t)??"",flag:o(t)}})},t.MasksFullEn=g,t.MasksFullMap=f,t.MasksFullMapEn=d,t.MasksMap=u,t.MasksWithFlag=p,t.MasksWithFlagMap=M,t.countPlaceholders=G,t.detectByGeoIp=async function(t){try{const e=localStorage.getItem(C);if(e){const n=JSON.parse(e),o=Date.now()-n.ts>y;if(!o&&n.country_code&&t(n.country_code))return n.country_code.toUpperCase();o&&localStorage.removeItem(C)}}catch{}const e=await A();if(e&&t(e)){try{localStorage.setItem(C,JSON.stringify({country_code:e,ts:Date.now()}))}catch{}return e}return null},t.detectCountryFromGeoIP=A,t.formatDigitsWithMap=function(t,e){let n="";const o=[];let r=0;const a=e.length,s=t.length;for(let c=0;c<s;c++){const s=t[c];if("#"===s){if(!(r<a))break;n+=e[r],o.push(r),r++}else{const e=-1!==t.indexOf("#",c+1)&&r<a;(n.length>0||e)&&(n+=s,o.push(-1))}}return{display:n,map:o}},t.getCountry=function(t,e){const n=T(e),o=t.toUpperCase();return o in n?{id:o,...n[o]}:{id:"US",...n.US}},t.getFlagEmoji=m,t.getMasksFullMapByLocale=T,t.getNavigatorLang=function(){return"undefined"!=typeof navigator&&navigator.language||"en"},t.pickMaskVariant=function(t,e){if(1===t.length)return t[0];const n=t.map(t=>({mask:t,count:G(t)})),o=n.filter(t=>t.count>=e).sort((t,e)=>t.count-e.count);if(o.length>0)return o[0].mask;const r=n.sort((t,e)=>e.count-t.count)[0];return r?r.mask:t[0]},t.removeCountryCodePrefix=function(t){return t.replace(/^\+\d+\s?/,"")},t.toArray=function(t){return Array.isArray(t)?t:[t]},Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../../src/services/geoip/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,2BAA2B,CAAC;AACvD,eAAO,MAAM,iBAAiB,OAAQ,CAAC;AAEvC,eAAO,MAAM,SAAS,6BAA6B,CAAC;AACpD,eAAO,MAAM,eAAe,QAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/services/geoip/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/services/geoip/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;CACZ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect country from GeoIP service.
|
|
3
|
+
* Attempts to fetch country code from external API with timeout
|
|
4
|
+
*/
|
|
5
|
+
export declare function detectCountryFromGeoIP(url?: string, timeout?: number): Promise<string | null>;
|
|
6
|
+
export declare function detectByGeoIp(hasCountry: (code: string) => boolean): Promise<string | null>;
|
|
7
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/services/geoip/utils.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,SAAiB,EACpB,OAAO,SAAoB,GAC1B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwBxB;AAED,wBAAsB,aAAa,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAgCjG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import { MaskFull, MaskFullMap } from './entries';
|
|
1
2
|
export type FormatResult = {
|
|
2
3
|
display: string;
|
|
3
4
|
map: number[];
|
|
4
5
|
};
|
|
6
|
+
/** Get navigator language with fallback to 'en' */
|
|
7
|
+
export declare function getNavigatorLang(): string;
|
|
8
|
+
/** Get full mask map for a given locale */
|
|
9
|
+
export declare function getMasksFullMapByLocale(locale: string): MaskFullMap;
|
|
10
|
+
/** Get country data by ISO code and locale with fallback to US */
|
|
11
|
+
export declare function getCountry(code: string, locale: string): MaskFull;
|
|
5
12
|
/** Ensure mask is an array of strings */
|
|
6
13
|
export declare function toArray<T>(mask: T | T[]): T[];
|
|
7
14
|
/** Count number of placeholders (#) in a mask string */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAEnE,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,EAAE,CAAC;CACf,CAAC;AAEF,mDAAmD;AACnD,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,2CAA2C;AAC3C,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAKnE;AAED,kEAAkE;AAClE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CASjE;AAED,yCAAyC;AACzC,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,CAE7C;AAED,wDAAwD;AACxD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,gEAAgE;AAChE,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED,sEAAsE;AACtE,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAgBpF;AAED,8DAA8D;AAC9D,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,CAgCxF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@desource/phone-mask",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "⚡ Ultra-lightweight international phone number formatter & validator with auto-sync to Google libphonenumber. Framework-agnostic core library.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"phone",
|