@desource/phone-mask 0.3.0 → 1.0.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 CHANGED
@@ -1,5 +1,34 @@
1
1
  # @desource/phone-mask
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - Core Upgrades:
8
+ - Refactored core architecture for better separation of concerns and reusability
9
+ - Added zero-config browser script support path
10
+ - Improved Intl.DisplayNames caching for performance
11
+ - Fixed various edge cases in formatting and event handling
12
+ - Added comprehensive unit tests for core utilities and handlers
13
+
14
+ - React Upgrades:
15
+ - Major internal refactor to a controlled pattern with consistent hooks
16
+ - Improved React 18/19 compatibility for ref behavior
17
+ - Added and expanded unit/e2e tests for React components and behavior
18
+
19
+ - Vue Upgrades:
20
+ - Refactored to align composable structure and reuse core utilities
21
+ - Fixed directive behavior for external value updates and dropdown close logic
22
+ - Added substantial unit/e2e test coverage for Vue composables and directive
23
+
24
+ - 🚀 Svelte Upgrades:
25
+ - Introduced Svelte version of phone-mask library
26
+
27
+ - Nuxt Upgrades:
28
+ - Added full test foundation with @nuxt/test-utils
29
+ - Added unit tests for module and runtime behavior
30
+ - Added e2e fixtures/tests and shared e2e utilities
31
+
3
32
  ## 0.3.0
4
33
 
5
34
  ### Minor Changes
package/README.md CHANGED
@@ -335,6 +335,8 @@ All exports are tree-shakeable — only import what you use!
335
335
 
336
336
  - [@desource/phone-mask-vue](../phone-mask-vue) — Vue 3 component + directive
337
337
  - [@desource/phone-mask-nuxt](../phone-mask-nuxt) — Nuxt module
338
+ - [@desource/phone-mask-react](../phone-mask-react) — React component + hook
339
+ - [@desource/phone-mask-svelte](../phone-mask-svelte) — Svelte component + composable
338
340
 
339
341
  ## 📄 License
340
342
 
@@ -1 +1 @@
1
- import e from"./data.min.js";import{countryCodeEmoji as n}from"./country-code-emodji.js";const t=Object.entries(e),divideMask=e=>e.split(/ (.*)/s);function getCodeAndMask(e){let n="",t="";if(Array.isArray(e)){const o=[];for(const t of e){const[e,s]=divideMask(t);n||(n=e),o.push(s)}t=o}else{const[o,s]=divideMask(e);n=o,t=s}return[n,t]}const o=e,s=t.map(([e,n])=>({id:e,mask:n})),a=t.reduce((e,[n,t])=>{const[o,s]=getCodeAndMask(t);return e[n]={code:o,mask:s},e},{}),r=t.map(([e,n])=>{const[t,o]=getCodeAndMask(n);return{id:e,code:t,mask:o}}),d=t.reduce((e,[t,o])=>{const[s,a]=getCodeAndMask(o);return e[t]={code:s,mask:a,flag:n(t)},e},{}),c=t.map(([e,t])=>{const[o,s]=getCodeAndMask(t);return{id:e,code:o,mask:s,flag:n(e)}}),MasksFullMap=e=>{const o=new Intl.DisplayNames([e],{type:"region"});return t.reduce((e,[t,s])=>{const[a,r]=getCodeAndMask(s),d=o.of(t)??"";return e[t]={code:a,mask:r,name:d,flag:n(t)},e},{})},MasksFull=e=>{const o=new Intl.DisplayNames([e],{type:"region"});return t.map(([e,t])=>{const[s,a]=getCodeAndMask(t);return{id:e,code:s,mask:a,name:o.of(e)??"",flag:n(e)}})},m=t.reduce((e,[t,o])=>{const[s,a]=getCodeAndMask(o),r=new Intl.DisplayNames(["en"],{type:"region"});return e[t]={code:s,mask:a,name:r.of(t)??"",flag:n(t)},e},{}),i=t.map(([e,t])=>{const[o,s]=getCodeAndMask(t);return{id:e,code:o,mask:s,name:new Intl.DisplayNames(["en"],{type:"region"}).of(e)??"",flag:n(e)}}),g=n;export{r as Masks,s as MasksBase,o as MasksBaseMap,MasksFull,i as MasksFullEn,MasksFullMap,m as MasksFullMapEn,a as MasksMap,c as MasksWithFlag,d as MasksWithFlagMap,g as getFlagEmoji};
1
+ import e from"./data.min.js";import{countryCodeEmoji as t}from"./country-code-emodji.js";const o="en",n=new Map,getDisplayNames=e=>{const t=e.toLowerCase(),s=n.get(t);if(s)return s;const r=new Intl.DisplayNames([e],{type:"region"});if(n.size>=10)for(const e of n.keys())if(e!==o){n.delete(e);break}return n.set(t,r),r},s=Object.entries(e),divideMask=e=>e.split(/ (.*)/s);function getCodeAndMask(e){let t="",o="";if(Array.isArray(e)){const n=[];for(const o of e){const[e,s]=divideMask(o);t||(t=e),n.push(s)}o=n}else{const[n,s]=divideMask(e);t=n,o=s}return[t,o]}const r=e,a=s.map(([e,t])=>({id:e,mask:t})),d=s.reduce((e,[t,o])=>{const[n,s]=getCodeAndMask(o);return e[t]={code:n,mask:s},e},{}),c=s.map(([e,t])=>{const[o,n]=getCodeAndMask(t);return{id:e,code:o,mask:n}}),m=s.reduce((e,[o,n])=>{const[s,r]=getCodeAndMask(n);return e[o]={code:s,mask:r,flag:t(o)},e},{}),i=s.map(([e,o])=>{const[n,s]=getCodeAndMask(o);return{id:e,code:n,mask:s,flag:t(e)}}),MasksFullMap=e=>{const o=getDisplayNames(e);return s.reduce((e,[n,s])=>{const[r,a]=getCodeAndMask(s),d=o.of(n)??"";return e[n]={code:r,mask:a,name:d,flag:t(n)},e},{})},MasksFull=e=>{const o=getDisplayNames(e);return s.map(([e,n])=>{const[s,r]=getCodeAndMask(n);return{id:e,code:s,mask:r,name:o.of(e)??"",flag:t(e)}})},f=MasksFullMap(o),u=MasksFull(o),k=t;export{c as Masks,a as MasksBase,r as MasksBaseMap,MasksFull,u as MasksFullEn,MasksFullMap,f as MasksFullMapEn,d as MasksMap,i as MasksWithFlag,m as MasksWithFlagMap,k as getFlagEmoji};
@@ -0,0 +1 @@
1
+ import{countPlaceholders as t,removeCountryCodePrefix as e,formatDigitsWithMap as n,toArray as r,pickMaskVariant as l}from"./utils.js";function createPhoneFormatter(o){const a=r(o.mask),i=a.map(n=>t(e(n))),g=Math.max(...i),getMask=t=>{const n=l(a,t);return e(n)};return{formatDisplay:t=>{const e=getMask(t.length);return n(e,t).display},getMaxDigits:()=>g,getPlaceholder:()=>getMask(0),getCaretPosition:t=>{const e=getMask(t),{display:r,map:l}=n(e,"0".repeat(t));for(let e=0;e<l.length;e++)if(l[e]===t)return e;if(t>=l.length)return r.length;for(let e=0;e<l.length;e++)if(l[e]>t)return e;return r.length},getDigitRange:(t,e,r)=>{const l=getMask(t.length),{map:o}=n(l,t);let a=1/0,i=-1/0;for(let t=e;t<r&&t<o.length;t++){const e=o[t];void 0!==e&&e>=0&&(a=Math.min(a,e),i=Math.max(i,e))}return a===1/0?null:[a,i+1]},isComplete:t=>i.includes(t.length)}}export{createPhoneFormatter};
@@ -0,0 +1 @@
1
+ const t=[" ","-","(",")"],e=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","Tab"],i=/[^\d\s\-()]/;function extractDigits(t,e){const i=t.replace(/\D/g,"");return e?i.slice(0,e):i}function getSelection(t){return t?[t.selectionStart??0,t.selectionEnd??0]:[0,0]}function setCaret(t,e){if(t)try{t.setSelectionRange(e,e)}catch{}}function processBeforeInput(t){if(!t.target)return;const e=t.target,n=t.data;"insertText"===t.inputType&&n&&(i.test(n)||" "===n&&e.value.endsWith(" "))&&t.preventDefault()}function processInput(t,e){if(!t.target)return;const i=t.target,{formatter:n}=e,r=n.getMaxDigits(),s=extractDigits(i.value,r);return{newDigits:s,caretDigitIndex:s.length}}function processKeydown(i,n){if(!i.target)return;const r=i.target,{digits:s,formatter:c}=n;if(i.ctrlKey||i.metaKey||i.altKey||e.includes(i.key))return;const[g,a]=getSelection(r);if("Backspace"!==i.key)if("Delete"!==i.key)/^[0-9]$/.test(i.key)?s.length>=c.getMaxDigits()&&i.preventDefault():1===i.key.length&&i.preventDefault();else{if(i.preventDefault(),g!==a){const t=c.getDigitRange(s,g,a);if(t){const[e,i]=t;return{newDigits:s.slice(0,e)+s.slice(i),caretDigitIndex:e}}}if(g<r.value.length){const t=c.getDigitRange(s,g,r.value.length);if(t){const[e]=t;return{newDigits:s.slice(0,e)+s.slice(e+1),caretDigitIndex:e}}}}else{if(i.preventDefault(),g!==a){const t=c.getDigitRange(s,g,a);if(t){const[e,i]=t;return{newDigits:s.slice(0,e)+s.slice(i),caretDigitIndex:e}}}if(g>0){const e=r.value;let i=g-1;for(;i>=0&&t.includes(e[i]);)i--;if(i>=0){const t=c.getDigitRange(s,i,i+1);if(t){const[e]=t;return{newDigits:s.slice(0,e)+s.slice(e+1),caretDigitIndex:e}}}}}}function processPaste(t,e){if(!t.target)return;t.preventDefault();const i=t.target,{digits:n,formatter:r}=e,s=t.clipboardData?.getData("text")||"",c=r.getMaxDigits(),g=extractDigits(s,c);if(0===g.length)return;const[a,o]=getSelection(i);if(a!==o){const t=r.getDigitRange(n,a,o);if(t){const[e,i]=t;return{newDigits:extractDigits(n.slice(0,e)+g+n.slice(i),c),caretDigitIndex:e+g.length}}}const l=r.getDigitRange(n,0,a),f=l?l[1]:0;return{newDigits:extractDigits(n.slice(0,f)+g+n.slice(f),c),caretDigitIndex:f+g.length}}export{t as DELIMITERS,i as INVALID_PATTERN,e as NAVIGATION_KEYS,extractDigits,getSelection,processBeforeInput,processInput,processKeydown,processPaste,setCaret};
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
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};
1
+ import{Masks as r,MasksBase as o,MasksBaseMap as s,MasksFull as i,MasksFullEn as m,MasksFullMap as t,MasksFullMapEn as e,MasksMap as p,MasksWithFlag as f,MasksWithFlagMap as j,getFlagEmoji as c}from"./entries.js";import{countPlaceholders as l,detectCountryFromLocale as n,filterCountries as a,formatDigitsWithMap as g,getCountry as u,getNavigatorLang as v,hasCountry as d,parseCountryCode as h,pickMaskVariant as x,removeCountryCodePrefix as b,toArray as k}from"./utils.js";import{DELIMITERS as q,INVALID_PATTERN as w,NAVIGATION_KEYS as y,extractDigits as z,getSelection as A,processBeforeInput as B,processInput as C,processKeydown as D,processPaste as E,setCaret as F}from"./handlers.js";import{createPhoneFormatter as G}from"./formatter.js";import{CACHE_EXPIRY_MS as H,CACHE_KEY as I,GEO_IP_API_URL as J,GEO_IP_TIMEOUT_MS as K}from"./services/geoip/consts.js";import{detectByGeoIp as L,detectCountryFromGeoIP as M}from"./services/geoip/utils.js";export{H as CACHE_EXPIRY_MS,I as CACHE_KEY,q as DELIMITERS,J as GEO_IP_API_URL,K as GEO_IP_TIMEOUT_MS,w as INVALID_PATTERN,r as Masks,o as MasksBase,s as MasksBaseMap,i as MasksFull,m as MasksFullEn,t as MasksFullMap,e as MasksFullMapEn,p as MasksMap,f as MasksWithFlag,j as MasksWithFlagMap,y as NAVIGATION_KEYS,l as countPlaceholders,G as createPhoneFormatter,L as detectByGeoIp,M as detectCountryFromGeoIP,n as detectCountryFromLocale,z as extractDigits,a as filterCountries,g as formatDigitsWithMap,u as getCountry,c as getFlagEmoji,v as getNavigatorLang,A as getSelection,d as hasCountry,h as parseCountryCode,x as pickMaskVariant,B as processBeforeInput,C as processInput,D as processKeydown,E as processPaste,b as removeCountryCodePrefix,F as setCaret,k as toArray};
@@ -1 +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};
1
+ import{parseCountryCode as t}from"../../utils.js";import{GEO_IP_API_URL as o,GEO_IP_TIMEOUT_MS as e,CACHE_KEY as r,CACHE_EXPIRY_MS as n}from"./consts.js";async function detectCountryFromGeoIP(t=o,r=e){const n=new AbortController,c=setTimeout(()=>n.abort(),r);try{const o=await fetch(t,{signal:n.signal,headers:{Accept:"application/json"}});if(clearTimeout(c),!o.ok)return null;const e=await o.json();return(e.country||e.country_code||e.countryCode||e.country_code2||"").toString().toUpperCase()||null}catch{return clearTimeout(c),null}}async function detectByGeoIp(){try{const o=localStorage.getItem(r);if(o){const e=JSON.parse(o),c=Date.now()-e.ts>n,a=t(e.country_code);if(a&&!c)return a;localStorage.removeItem(r)}}catch{}const o=await detectCountryFromGeoIP(),e=t(o);if(e){try{const t=JSON.stringify({country_code:e,ts:Date.now()});localStorage.setItem(r,t)}catch{}return e}return null}export{detectByGeoIp,detectCountryFromGeoIP};
package/dist/esm/utils.js CHANGED
@@ -1 +1 @@
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};
1
+ import{MasksFullMap as t,MasksFullMapEn as e}from"./entries.js";function getNavigatorLang(){return"undefined"!=typeof navigator&&navigator.language||"en"}function detectCountryFromLocale(){try{const t=getNavigatorLang();try{const e=new Intl.Locale(t);if(e.region)return e.region.toUpperCase()}catch{}const e=t.split(/[-_]/);if(e.length>1)return e[1]?.toUpperCase()||null}catch{}return null}function hasCountry(t){const r=e;return t.toUpperCase()in r}function getCountry(e,r){const n=t(r),o=e.toUpperCase();return o in n?{id:o,...n[o]}:{id:"US",...n.US}}function parseCountryCode(t,e){return t&&hasCountry(t)?t.toUpperCase():e||""}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,e){if(1===t.length)return t[0];const r=t.map(t=>({mask:t,count:countPlaceholders(t)})),n=r.filter(t=>t.count>=e).sort((t,e)=>t.count-e.count);if(n.length>0)return n[0].mask;const o=r.sort((t,e)=>e.count-t.count)[0];return o?o.mask:t[0]}function formatDigitsWithMap(t,e){let r="";const n=[];let o=0;const a=e.length,s=t.length;for(let c=0;c<s;c++){const s=t[c];if("#"===s){if(!(o<a))break;r+=e[o],n.push(o),o++}else{const e=-1!==t.indexOf("#",c+1)&&o<a;(r.length>0||e)&&(r+=s,n.push(-1))}}return{display:r,map:n}}function filterCountries(t,e){const r=e.trim().toUpperCase();if(!r)return t;const n=r.replace(/\D/g,""),o=n.length>0;return t.map(t=>{const e=t.name.toUpperCase(),a=t.id.toUpperCase(),s=t.code.toUpperCase(),c=t.code.replace(/\D/g,"");let i=0;return e.startsWith(r)?i=1e3:e.includes(r)&&(i=500),s.startsWith(r)?i+=100:s.includes(r)&&(i+=50),a===r?i+=200:a.startsWith(r)&&(i+=150),o&&c.startsWith(n)?i+=80:o&&c.includes(n)&&(i+=40),{country:t,score:i}}).filter(t=>t.score>0).sort((t,e)=>e.score!==t.score?e.score-t.score:t.country.name.localeCompare(e.country.name)).map(t=>t.country)}export{countPlaceholders,detectCountryFromLocale,filterCountries,formatDigitsWithMap,getCountry,getNavigatorLang,hasCountry,parseCountryCode,pickMaskVariant,removeCountryCodePrefix,toArray};
@@ -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="",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
+ "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)},dnCache=new Map,getDisplayNames=t=>{const e=t.toLowerCase(),r=dnCache.get(e);if(r)return r;const n=new Intl.DisplayNames([t],{type:"region"});if(dnCache.size>=10)for(const t of dnCache.keys())if("en"!==t){dnCache.delete(t);break}return dnCache.set(e,n),n},dataEntries=Object.entries(data),divideMask=t=>t.split(/ (.*)/s);function getCodeAndMask(t){let e="",r="";if(Array.isArray(t)){const n=[];for(const r of t){const[t,s]=divideMask(r);e||(e=t),n.push(s)}r=n}else{const[n,s]=divideMask(t);e=n,r=s}return[e,r]}const MasksBaseMap=data,MasksBase=dataEntries.map(([t,e])=>({id:t,mask:e})),MasksMap=dataEntries.reduce((t,[e,r])=>{const[n,s]=getCodeAndMask(r);return t[e]={code:n,mask:s},t},{}),Masks=dataEntries.map(([t,e])=>{const[r,n]=getCodeAndMask(e);return{id:t,code:r,mask:n}}),MasksWithFlagMap=dataEntries.reduce((t,[e,r])=>{const[n,s]=getCodeAndMask(r);return t[e]={code:n,mask:s,flag:countryCodeEmoji(e)},t},{}),MasksWithFlag=dataEntries.map(([t,e])=>{const[r,n]=getCodeAndMask(e);return{id:t,code:r,mask:n,flag:countryCodeEmoji(t)}}),MasksFullMap=t=>{const e=getDisplayNames(t);return dataEntries.reduce((t,[r,n])=>{const[s,o]=getCodeAndMask(n),a=e.of(r)??"";return t[r]={code:s,mask:o,name:a,flag:countryCodeEmoji(r)},t},{})},MasksFull=t=>{const e=getDisplayNames(t);return dataEntries.map(([t,r])=>{const[n,s]=getCodeAndMask(r);return{id:t,code:n,mask:s,name:e.of(t)??"",flag:countryCodeEmoji(t)}})},MasksFullMapEn=MasksFullMap("en"),MasksFullEn=MasksFull("en"),getFlagEmoji=countryCodeEmoji,CACHE_KEY="@desource/phone-mask:geo";function getNavigatorLang(){return"undefined"!=typeof navigator&&navigator.language||"en"}function hasCountry(t){const e=MasksFullMapEn;return t.toUpperCase()in e}function parseCountryCode(t,e){return t&&hasCountry(t)?t.toUpperCase():e||""}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,e){if(1===t.length)return t[0];const r=t.map(t=>({mask:t,count:countPlaceholders(t)})),n=r.filter(t=>t.count>=e).sort((t,e)=>t.count-e.count);if(n.length>0)return n[0].mask;const s=r.sort((t,e)=>e.count-t.count)[0];return s?s.mask:t[0]}function formatDigitsWithMap(t,e){let r="";const n=[];let s=0;const o=e.length,a=t.length;for(let i=0;i<a;i++){const a=t[i];if("#"===a){if(!(s<o))break;r+=e[s],n.push(s),s++}else{const e=-1!==t.indexOf("#",i+1)&&s<o;(r.length>0||e)&&(r+=a,n.push(-1))}}return{display:r,map:n}}async function detectCountryFromGeoIP(t="https://ipapi.co/json/",e=1500){const r=new AbortController,n=setTimeout(()=>r.abort(),e);try{const e=await fetch(t,{signal:r.signal,headers:{Accept:"application/json"}});if(clearTimeout(n),!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(n),null}}const DELIMITERS=[" ","-","(",")"],NAVIGATION_KEYS=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","Tab"],INVALID_PATTERN=/[^\d\s\-()]/;function extractDigits(t,e){const r=t.replace(/\D/g,"");return e?r.slice(0,e):r}function getSelection(t){return t?[t.selectionStart??0,t.selectionEnd??0]:[0,0]}exports.CACHE_EXPIRY_MS=864e5,exports.CACHE_KEY=CACHE_KEY,exports.DELIMITERS=DELIMITERS,exports.GEO_IP_API_URL="https://ipapi.co/json/",exports.GEO_IP_TIMEOUT_MS=1500,exports.INVALID_PATTERN=INVALID_PATTERN,exports.Masks=Masks,exports.MasksBase=MasksBase,exports.MasksBaseMap=MasksBaseMap,exports.MasksFull=MasksFull,exports.MasksFullEn=MasksFullEn,exports.MasksFullMap=MasksFullMap,exports.MasksFullMapEn=MasksFullMapEn,exports.MasksMap=MasksMap,exports.MasksWithFlag=MasksWithFlag,exports.MasksWithFlagMap=MasksWithFlagMap,exports.NAVIGATION_KEYS=NAVIGATION_KEYS,exports.countPlaceholders=countPlaceholders,exports.createPhoneFormatter=function createPhoneFormatter(t){const e=toArray(t.mask),r=e.map(t=>countPlaceholders(removeCountryCodePrefix(t))),n=Math.max(...r),getMask=t=>removeCountryCodePrefix(pickMaskVariant(e,t));return{formatDisplay:t=>formatDigitsWithMap(getMask(t.length),t).display,getMaxDigits:()=>n,getPlaceholder:()=>getMask(0),getCaretPosition:t=>{const e=getMask(t),{display:r,map:n}=formatDigitsWithMap(e,"0".repeat(t));for(let e=0;e<n.length;e++)if(n[e]===t)return e;if(t>=n.length)return r.length;for(let e=0;e<n.length;e++)if(n[e]>t)return e;return r.length},getDigitRange:(t,e,r)=>{const n=getMask(t.length),{map:s}=formatDigitsWithMap(n,t);let o=1/0,a=-1/0;for(let t=e;t<r&&t<s.length;t++){const e=s[t];void 0!==e&&e>=0&&(o=Math.min(o,e),a=Math.max(a,e))}return o===1/0?null:[o,a+1]},isComplete:t=>r.includes(t.length)}},exports.detectByGeoIp=async function detectByGeoIp(){try{const t=localStorage.getItem(CACHE_KEY);if(t){const e=JSON.parse(t),r=Date.now()-e.ts>864e5,n=parseCountryCode(e.country_code);if(n&&!r)return n;localStorage.removeItem(CACHE_KEY)}}catch{}const t=parseCountryCode(await detectCountryFromGeoIP());if(t){try{const e=JSON.stringify({country_code:t,ts:Date.now()});localStorage.setItem(CACHE_KEY,e)}catch{}return t}return null},exports.detectCountryFromGeoIP=detectCountryFromGeoIP,exports.detectCountryFromLocale=function detectCountryFromLocale(){try{const t=getNavigatorLang();try{const e=new Intl.Locale(t);if(e.region)return e.region.toUpperCase()}catch{}const e=t.split(/[-_]/);if(e.length>1)return e[1]?.toUpperCase()||null}catch{}return null},exports.extractDigits=extractDigits,exports.filterCountries=function filterCountries(t,e){const r=e.trim().toUpperCase();if(!r)return t;const n=r.replace(/\D/g,""),s=n.length>0;return t.map(t=>{const e=t.name.toUpperCase(),o=t.id.toUpperCase(),a=t.code.toUpperCase(),i=t.code.replace(/\D/g,"");let c=0;return e.startsWith(r)?c=1e3:e.includes(r)&&(c=500),a.startsWith(r)?c+=100:a.includes(r)&&(c+=50),o===r?c+=200:o.startsWith(r)&&(c+=150),s&&i.startsWith(n)?c+=80:s&&i.includes(n)&&(c+=40),{country:t,score:c}}).filter(t=>t.score>0).sort((t,e)=>e.score!==t.score?e.score-t.score:t.country.name.localeCompare(e.country.name)).map(t=>t.country)},exports.formatDigitsWithMap=formatDigitsWithMap,exports.getCountry=function getCountry(t,e){const r=MasksFullMap(e),n=t.toUpperCase();return n in r?{id:n,...r[n]}:{id:"US",...r.US}},exports.getFlagEmoji=getFlagEmoji,exports.getNavigatorLang=getNavigatorLang,exports.getSelection=getSelection,exports.hasCountry=hasCountry,exports.parseCountryCode=parseCountryCode,exports.pickMaskVariant=pickMaskVariant,exports.processBeforeInput=function processBeforeInput(t){if(!t.target)return;const e=t.target,r=t.data;"insertText"===t.inputType&&r&&(INVALID_PATTERN.test(r)||" "===r&&e.value.endsWith(" "))&&t.preventDefault()},exports.processInput=function processInput(t,e){if(!t.target)return;const r=t.target,{formatter:n}=e,s=n.getMaxDigits(),o=extractDigits(r.value,s);return{newDigits:o,caretDigitIndex:o.length}},exports.processKeydown=function processKeydown(t,e){if(!t.target)return;const r=t.target,{digits:n,formatter:s}=e;if(t.ctrlKey||t.metaKey||t.altKey||NAVIGATION_KEYS.includes(t.key))return;const[o,a]=getSelection(r);if("Backspace"!==t.key)if("Delete"!==t.key)/^[0-9]$/.test(t.key)?n.length>=s.getMaxDigits()&&t.preventDefault():1===t.key.length&&t.preventDefault();else{if(t.preventDefault(),o!==a){const t=s.getDigitRange(n,o,a);if(t){const[e,r]=t;return{newDigits:n.slice(0,e)+n.slice(r),caretDigitIndex:e}}}if(o<r.value.length){const t=s.getDigitRange(n,o,r.value.length);if(t){const[e]=t;return{newDigits:n.slice(0,e)+n.slice(e+1),caretDigitIndex:e}}}}else{if(t.preventDefault(),o!==a){const t=s.getDigitRange(n,o,a);if(t){const[e,r]=t;return{newDigits:n.slice(0,e)+n.slice(r),caretDigitIndex:e}}}if(o>0){const t=r.value;let e=o-1;for(;e>=0&&DELIMITERS.includes(t[e]);)e--;if(e>=0){const t=s.getDigitRange(n,e,e+1);if(t){const[e]=t;return{newDigits:n.slice(0,e)+n.slice(e+1),caretDigitIndex:e}}}}}},exports.processPaste=function processPaste(t,e){if(!t.target)return;t.preventDefault();const r=t.target,{digits:n,formatter:s}=e,o=t.clipboardData?.getData("text")||"",a=s.getMaxDigits(),i=extractDigits(o,a);if(0===i.length)return;const[c,l]=getSelection(r);if(c!==l){const t=s.getDigitRange(n,c,l);if(t){const[e,r]=t;return{newDigits:extractDigits(n.slice(0,e)+i+n.slice(r),a),caretDigitIndex:e+i.length}}}const u=s.getDigitRange(n,0,c),p=u?u[1]:0;return{newDigits:extractDigits(n.slice(0,p)+i+n.slice(p),a),caretDigitIndex:p+i.length}},exports.removeCountryCodePrefix=removeCountryCodePrefix,exports.setCaret=function setCaret(t,e){if(t)try{t.setSelectionRange(e,e)}catch{}},exports.toArray=toArray;
@@ -1 +1 @@
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"})});
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,r=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)},o="en",s=new Map,i=t=>{const e=t.toLowerCase(),n=s.get(e);if(n)return n;const r=new Intl.DisplayNames([t],{type:"region"});if(s.size>=10)for(const t of s.keys())if(t!==o){s.delete(t);break}return s.set(e,r),r},a=Object.entries(e),c=t=>t.split(/ (.*)/s);function u(t){let e="",n="";if(Array.isArray(t)){const r=[];for(const n of t){const[t,o]=c(n);e||(e=t),r.push(o)}n=r}else{const[r,o]=c(t);e=r,n=o}return[e,n]}const l=e,g=a.map(([t,e])=>({id:t,mask:e})),f=a.reduce((t,[e,n])=>{const[r,o]=u(n);return t[e]={code:r,mask:o},t},{}),p=a.map(([t,e])=>{const[n,r]=u(e);return{id:t,code:n,mask:r}}),d=a.reduce((t,[e,n])=>{const[o,s]=u(n);return t[e]={code:o,mask:s,flag:r(e)},t},{}),M=a.map(([t,e])=>{const[n,o]=u(e);return{id:t,code:n,mask:o,flag:r(t)}}),m=t=>{const e=i(t);return a.reduce((t,[n,o])=>{const[s,i]=u(o),a=e.of(n)??"";return t[n]={code:s,mask:i,name:a,flag:r(n)},t},{})},h=t=>{const e=i(t);return a.map(([t,n])=>{const[o,s]=u(n);return{id:t,code:o,mask:s,name:e.of(t)??"",flag:r(t)}})},C=m(o),D=h(o),y=r,S="https://ipapi.co/json/",A="@desource/phone-mask:geo",I=864e5;function T(){return"undefined"!=typeof navigator&&navigator.language||"en"}function E(t){const e=C;return t.toUpperCase()in e}function G(t,e){return t&&E(t)?t.toUpperCase():e||""}function k(t){return Array.isArray(t)?t:[t]}function P(t){return(t.match(/#/g)||[]).length}function R(t){return t.replace(/^\+\d+\s?/,"")}function N(t,e){if(1===t.length)return t[0];const n=t.map(t=>({mask:t,count:P(t)})),r=n.filter(t=>t.count>=e).sort((t,e)=>t.count-e.count);if(r.length>0)return r[0].mask;const o=n.sort((t,e)=>e.count-t.count)[0];return o?o.mask:t[0]}function U(t,e){let n="";const r=[];let o=0;const s=e.length,i=t.length;for(let a=0;a<i;a++){const i=t[a];if("#"===i){if(!(o<s))break;n+=e[o],r.push(o),o++}else{const e=-1!==t.indexOf("#",a+1)&&o<s;(n.length>0||e)&&(n+=i,r.push(-1))}}return{display:n,map:r}}async function B(t=S,e=1500){const n=new AbortController,r=setTimeout(()=>n.abort(),e);try{const e=await fetch(t,{signal:n.signal,headers:{Accept:"application/json"}});if(clearTimeout(r),!e.ok)return null;const o=await e.json();return(o.country||o.country_code||o.countryCode||o.country_code2||"").toString().toUpperCase()||null}catch{return clearTimeout(r),null}}const L=[" ","-","(",")"],K=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","Tab"],w=/[^\d\s\-()]/;function F(t,e){const n=t.replace(/\D/g,"");return e?n.slice(0,e):n}function O(t){return t?[t.selectionStart??0,t.selectionEnd??0]:[0,0]}t.CACHE_EXPIRY_MS=I,t.CACHE_KEY=A,t.DELIMITERS=L,t.GEO_IP_API_URL=S,t.GEO_IP_TIMEOUT_MS=1500,t.INVALID_PATTERN=w,t.Masks=p,t.MasksBase=g,t.MasksBaseMap=l,t.MasksFull=h,t.MasksFullEn=D,t.MasksFullMap=m,t.MasksFullMapEn=C,t.MasksMap=f,t.MasksWithFlag=M,t.MasksWithFlagMap=d,t.NAVIGATION_KEYS=K,t.countPlaceholders=P,t.createPhoneFormatter=function(t){const e=k(t.mask),n=e.map(t=>P(R(t))),r=Math.max(...n),o=t=>R(N(e,t));return{formatDisplay:t=>U(o(t.length),t).display,getMaxDigits:()=>r,getPlaceholder:()=>o(0),getCaretPosition:t=>{const e=o(t),{display:n,map:r}=U(e,"0".repeat(t));for(let e=0;e<r.length;e++)if(r[e]===t)return e;if(t>=r.length)return n.length;for(let e=0;e<r.length;e++)if(r[e]>t)return e;return n.length},getDigitRange:(t,e,n)=>{const r=o(t.length),{map:s}=U(r,t);let i=1/0,a=-1/0;for(let t=e;t<n&&t<s.length;t++){const e=s[t];void 0!==e&&e>=0&&(i=Math.min(i,e),a=Math.max(a,e))}return i===1/0?null:[i,a+1]},isComplete:t=>n.includes(t.length)}},t.detectByGeoIp=async function(){try{const t=localStorage.getItem(A);if(t){const e=JSON.parse(t),n=Date.now()-e.ts>I,r=G(e.country_code);if(r&&!n)return r;localStorage.removeItem(A)}}catch{}const t=G(await B());if(t){try{const e=JSON.stringify({country_code:t,ts:Date.now()});localStorage.setItem(A,e)}catch{}return t}return null},t.detectCountryFromGeoIP=B,t.detectCountryFromLocale=function(){try{const t=T();try{const e=new Intl.Locale(t);if(e.region)return e.region.toUpperCase()}catch{}const e=t.split(/[-_]/);if(e.length>1)return e[1]?.toUpperCase()||null}catch{}return null},t.extractDigits=F,t.filterCountries=function(t,e){const n=e.trim().toUpperCase();if(!n)return t;const r=n.replace(/\D/g,""),o=r.length>0;return t.map(t=>{const e=t.name.toUpperCase(),s=t.id.toUpperCase(),i=t.code.toUpperCase(),a=t.code.replace(/\D/g,"");let c=0;return e.startsWith(n)?c=1e3:e.includes(n)&&(c=500),i.startsWith(n)?c+=100:i.includes(n)&&(c+=50),s===n?c+=200:s.startsWith(n)&&(c+=150),o&&a.startsWith(r)?c+=80:o&&a.includes(r)&&(c+=40),{country:t,score:c}}).filter(t=>t.score>0).sort((t,e)=>e.score!==t.score?e.score-t.score:t.country.name.localeCompare(e.country.name)).map(t=>t.country)},t.formatDigitsWithMap=U,t.getCountry=function(t,e){const n=m(e),r=t.toUpperCase();return r in n?{id:r,...n[r]}:{id:"US",...n.US}},t.getFlagEmoji=y,t.getNavigatorLang=T,t.getSelection=O,t.hasCountry=E,t.parseCountryCode=G,t.pickMaskVariant=N,t.processBeforeInput=function(t){if(!t.target)return;const e=t.target,n=t.data;"insertText"===t.inputType&&n&&(w.test(n)||" "===n&&e.value.endsWith(" "))&&t.preventDefault()},t.processInput=function(t,e){if(!t.target)return;const n=t.target,{formatter:r}=e,o=r.getMaxDigits(),s=F(n.value,o);return{newDigits:s,caretDigitIndex:s.length}},t.processKeydown=function(t,e){if(!t.target)return;const n=t.target,{digits:r,formatter:o}=e;if(t.ctrlKey||t.metaKey||t.altKey||K.includes(t.key))return;const[s,i]=O(n);if("Backspace"!==t.key)if("Delete"!==t.key)/^[0-9]$/.test(t.key)?r.length>=o.getMaxDigits()&&t.preventDefault():1===t.key.length&&t.preventDefault();else{if(t.preventDefault(),s!==i){const t=o.getDigitRange(r,s,i);if(t){const[e,n]=t;return{newDigits:r.slice(0,e)+r.slice(n),caretDigitIndex:e}}}if(s<n.value.length){const t=o.getDigitRange(r,s,n.value.length);if(t){const[e]=t;return{newDigits:r.slice(0,e)+r.slice(e+1),caretDigitIndex:e}}}}else{if(t.preventDefault(),s!==i){const t=o.getDigitRange(r,s,i);if(t){const[e,n]=t;return{newDigits:r.slice(0,e)+r.slice(n),caretDigitIndex:e}}}if(s>0){const t=n.value;let e=s-1;for(;e>=0&&L.includes(t[e]);)e--;if(e>=0){const t=o.getDigitRange(r,e,e+1);if(t){const[e]=t;return{newDigits:r.slice(0,e)+r.slice(e+1),caretDigitIndex:e}}}}}},t.processPaste=function(t,e){if(!t.target)return;t.preventDefault();const n=t.target,{digits:r,formatter:o}=e,s=t.clipboardData?.getData("text")||"",i=o.getMaxDigits(),a=F(s,i);if(0===a.length)return;const[c,u]=O(n);if(c!==u){const t=o.getDigitRange(r,c,u);if(t){const[e,n]=t;return{newDigits:F(r.slice(0,e)+a+r.slice(n),i),caretDigitIndex:e+a.length}}}const l=o.getDigitRange(r,0,c),g=l?l[1]:0;return{newDigits:F(r.slice(0,g)+a+r.slice(g),i),caretDigitIndex:g+a.length}},t.removeCountryCodePrefix=R,t.setCaret=function(t,e){if(t)try{t.setSelectionRange(e,e)}catch{}},t.toArray=k,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
@@ -1 +1 @@
1
- {"version":3,"file":"entries.d.ts","sourceRoot":"","sources":["../../src/entries.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,UAAU,QAAQ;IAChB,EAAE,EAAE,UAAU,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;CAC9B;AACD,UAAU,IAAK,SAAQ,QAAQ;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;AACD,UAAU,YAAa,SAAQ,IAAI;IACjC,IAAI,EAAE,MAAM,CAAC;CACd;AACD,UAAU,QAAS,SAAQ,YAAY;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AACD,KAAK,WAAW,GAAG,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9D,KAAK,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACpD,KAAK,eAAe,GAAG,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;AACpE,KAAK,WAAW,GAAG,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;AAsB5D;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,WAAkB,CAAC;AAC9C;;;GAGG;AACH,eAAO,MAAM,SAAS,YAA4D,CAAC;AACnF;;;;GAIG;AACH,eAAO,MAAM,QAAQ,SAIJ,CAAC;AAClB;;;;GAIG;AACH,eAAO,MAAM,KAAK,QAGhB,CAAC;AACH;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,iBAIJ,CAAC;AAC1B;;;;GAIG;AACH,eAAO,MAAM,aAAa,gBAGxB,CAAC;AACH;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,gBAQxC,CAAC;AACF;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,eAYrC,CAAC;AACF;;;;GAIG;AACH,eAAO,MAAM,cAAc,aAKN,CAAC;AACtB;;;;GAIG;AACH,eAAO,MAAM,WAAW,YAUtB,CAAC;AACH,yCAAyC;AACzC,eAAO,MAAM,YAAY,wBAAmB,CAAC;AAE7C,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC"}
1
+ {"version":3,"file":"entries.d.ts","sourceRoot":"","sources":["../../src/entries.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,UAAU,QAAQ;IAChB,EAAE,EAAE,UAAU,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;CAC9B;AACD,UAAU,IAAK,SAAQ,QAAQ;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;AACD,UAAU,YAAa,SAAQ,IAAI;IACjC,IAAI,EAAE,MAAM,CAAC;CACd;AACD,UAAU,QAAS,SAAQ,YAAY;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AACD,KAAK,WAAW,GAAG,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9D,KAAK,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACpD,KAAK,eAAe,GAAG,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;AACpE,KAAK,WAAW,GAAG,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;AA4C5D;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,WAAkB,CAAC;AAC9C;;;GAGG;AACH,eAAO,MAAM,SAAS,YAA4D,CAAC;AACnF;;;;GAIG;AACH,eAAO,MAAM,QAAQ,SAIJ,CAAC;AAClB;;;;GAIG;AACH,eAAO,MAAM,KAAK,QAGhB,CAAC;AACH;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,iBAIJ,CAAC;AAC1B;;;;GAIG;AACH,eAAO,MAAM,aAAa,gBAGxB,CAAC;AACH;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,gBAQxC,CAAC;AACF;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,eAYrC,CAAC;AACF;;;;GAIG;AACH,eAAO,MAAM,cAAc,aAA6B,CAAC;AACzD;;;;GAIG;AACH,eAAO,MAAM,WAAW,YAA0B,CAAC;AACnD,yCAAyC;AACzC,eAAO,MAAM,YAAY,wBAAmB,CAAC;AAE7C,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { MaskFull } from './entries';
2
+ /**
3
+ * Formatter interface for digit range and caret calculations
4
+ */
5
+ export interface FormatterHelpers {
6
+ /**
7
+ * Format digits into display string with mask delimiters
8
+ */
9
+ formatDisplay: (digits: string) => string;
10
+ /**
11
+ * Get maximum number of digits for the current country
12
+ */
13
+ getMaxDigits: () => number;
14
+ /**
15
+ * Get placeholder string for the input
16
+ */
17
+ getPlaceholder: () => string;
18
+ /**
19
+ * Get caret position in display string for given digit index
20
+ */
21
+ getCaretPosition: (digitIndex: number) => number;
22
+ /**
23
+ * Get digit range [start, end) for selection range in display string
24
+ * Returns null if no digits are selected
25
+ */
26
+ getDigitRange: (digits: string, selStart: number, selEnd: number) => [number, number] | null;
27
+ /**
28
+ * Check if the current number of digits is a valid complete phone number
29
+ */
30
+ isComplete: (digits: string) => boolean;
31
+ }
32
+ /**
33
+ * Create a phone formatter for a given country
34
+ */
35
+ export declare function createPhoneFormatter(country: MaskFull): FormatterHelpers;
36
+ //# sourceMappingURL=formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;IAE1C;;OAEG;IACH,YAAY,EAAE,MAAM,MAAM,CAAC;IAE3B;;OAEG;IACH,cAAc,EAAE,MAAM,MAAM,CAAC;IAE7B;;OAEG;IACH,gBAAgB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,CAAC;IAEjD;;;OAGG;IACH,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IAE7F;;OAEG;IACH,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;CACzC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,QAAQ,GAAG,gBAAgB,CA6DxE"}
@@ -0,0 +1,63 @@
1
+ import { FormatterHelpers } from './formatter';
2
+ export declare const DELIMITERS: string[];
3
+ export declare const NAVIGATION_KEYS: string[];
4
+ export declare const INVALID_PATTERN: RegExp;
5
+ /** Result of processInput */
6
+ interface InputResult {
7
+ newDigits: string;
8
+ caretDigitIndex: number;
9
+ }
10
+ /** Result of processKeydown */
11
+ interface KeydownResult {
12
+ newDigits: string;
13
+ caretDigitIndex: number;
14
+ }
15
+ /** Result of processPaste */
16
+ interface PasteResult {
17
+ newDigits: string;
18
+ caretDigitIndex: number;
19
+ }
20
+ /** Parameters for processInput */
21
+ interface ProcessInputParams {
22
+ formatter: FormatterHelpers;
23
+ }
24
+ /** Parameters for processKeydown */
25
+ interface ProcessKeydownParams {
26
+ digits: string;
27
+ formatter: FormatterHelpers;
28
+ }
29
+ /** Parameters for processPaste */
30
+ interface ProcessPasteParams {
31
+ digits: string;
32
+ formatter: FormatterHelpers;
33
+ }
34
+ /**
35
+ * Extract digits from a string, optionally limiting to maxLength
36
+ */
37
+ export declare function extractDigits(value: string, maxLength?: number): string;
38
+ /**
39
+ * Get current selection range from input element
40
+ */
41
+ export declare function getSelection(el: HTMLInputElement | null): [number, number];
42
+ /**
43
+ * Set caret position in input element
44
+ */
45
+ export declare function setCaret(el: HTMLInputElement | null, position: number): void;
46
+ /**
47
+ * Process beforeinput event - determine if input should be blocked
48
+ */
49
+ export declare function processBeforeInput(e: InputEvent): void;
50
+ /**
51
+ * Process input event - extract digits and calculate caret position
52
+ */
53
+ export declare function processInput(e: Event, params: ProcessInputParams): InputResult | undefined;
54
+ /**
55
+ * Process keydown event - handle backspace, delete, digits, etc.
56
+ */
57
+ export declare function processKeydown(e: KeyboardEvent, params: ProcessKeydownParams): KeydownResult | undefined;
58
+ /**
59
+ * Process paste event - extract digits and insert at correct position
60
+ */
61
+ export declare function processPaste(e: ClipboardEvent, params: ProcessPasteParams): PasteResult | undefined;
62
+ export {};
63
+ //# sourceMappingURL=handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/handlers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,eAAO,MAAM,UAAU,UAAuB,CAAC;AAC/C,eAAO,MAAM,eAAe,UAA4E,CAAC;AACzG,eAAO,MAAM,eAAe,QAAgB,CAAC;AAE7C,6BAA6B;AAC7B,UAAU,WAAW;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,+BAA+B;AAC/B,UAAU,aAAa;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,6BAA6B;AAC7B,UAAU,WAAW;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,kCAAkC;AAClC,UAAU,kBAAkB;IAC1B,SAAS,EAAE,gBAAgB,CAAC;CAC7B;AAED,oCAAoC;AACpC,UAAU,oBAAoB;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,gBAAgB,CAAC;CAC7B;AAED,kCAAkC;AAClC,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,gBAAgB,CAAC;CAC7B;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAGvE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,gBAAgB,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAG1E;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,EAAE,EAAE,gBAAgB,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAO5E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,UAAU,GAAG,IAAI,CAYtD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,kBAAkB,GAAG,WAAW,GAAG,SAAS,CAc1F;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,oBAAoB,GAAG,aAAa,GAAG,SAAS,CAsGxG;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,kBAAkB,GAAG,WAAW,GAAG,SAAS,CAkDnG"}
@@ -1,4 +1,6 @@
1
1
  export * from './entries';
2
2
  export * from './services';
3
3
  export * from './utils';
4
+ export * from './handlers';
5
+ export * from './formatter';
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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"}
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;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
@@ -3,5 +3,5 @@
3
3
  * Attempts to fetch country code from external API with timeout
4
4
  */
5
5
  export declare function detectCountryFromGeoIP(url?: string, timeout?: number): Promise<string | null>;
6
- export declare function detectByGeoIp(hasCountry: (code: string) => boolean): Promise<string | null>;
6
+ export declare function detectByGeoIp(): Promise<string | null>;
7
7
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/services/geoip/utils.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,SAAiB,EACpB,OAAO,SAAoB,GAC1B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwBxB;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAoC5D"}
@@ -1,14 +1,17 @@
1
- import { MaskFull, MaskFullMap } from './entries';
1
+ import { MaskFull } from './entries';
2
2
  export type FormatResult = {
3
3
  display: string;
4
4
  map: number[];
5
5
  };
6
6
  /** Get navigator language with fallback to 'en' */
7
7
  export declare function getNavigatorLang(): string;
8
- /** Get full mask map for a given locale */
9
- export declare function getMasksFullMapByLocale(locale: string): MaskFullMap;
8
+ /** Detect country from browser locale */
9
+ export declare function detectCountryFromLocale(): string | null;
10
+ /** Check if a country exists in the full mask map */
11
+ export declare function hasCountry(code: string): boolean;
10
12
  /** Get country data by ISO code and locale with fallback to US */
11
13
  export declare function getCountry(code: string, locale: string): MaskFull;
14
+ export declare function parseCountryCode(code?: string | null, fallback?: string): string;
12
15
  /** Ensure mask is an array of strings */
13
16
  export declare function toArray<T>(mask: T | T[]): T[];
14
17
  /** Count number of placeholders (#) in a mask string */
@@ -19,4 +22,6 @@ export declare function removeCountryCodePrefix(maskStr: string): string;
19
22
  export declare function pickMaskVariant(variants: string[], typedDigitsCount: number): string;
20
23
  /** Formatting with mapping for efficient position tracking */
21
24
  export declare function formatDigitsWithMap(maskTemplate: string, digitStr: string): FormatResult;
25
+ /** Filter and rank countries by a search query */
26
+ export declare function filterCountries(countries: MaskFull[], search: string): MaskFull[];
22
27
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEtD,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,yCAAyC;AACzC,wBAAgB,uBAAuB,IAAI,MAAM,GAAG,IAAI,CAkBvD;AAED,qDAAqD;AACrD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKhD;AAED,kEAAkE;AAClE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CASjE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhF;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;AAED,kDAAkD;AAClD,wBAAgB,eAAe,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE,CAiCjF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@desource/phone-mask",
3
- "version": "0.3.0",
3
+ "version": "1.0.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",
@@ -32,9 +32,13 @@
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "main": "dist/phone-mask.cjs.js",
35
+ "type": "module",
36
+ "main": "dist/phone-mask.cjs",
36
37
  "module": "dist/esm/index.js",
37
38
  "types": "dist/types/index.d.ts",
39
+ "unpkg": "dist/phone-mask.umd.min.js",
40
+ "jsdelivr": "dist/phone-mask.umd.min.js",
41
+ "browser": "dist/phone-mask.umd.min.js",
38
42
  "files": [
39
43
  "dist",
40
44
  "CHANGELOG.md",
@@ -45,20 +49,26 @@
45
49
  ".": {
46
50
  "types": "./dist/types/index.d.ts",
47
51
  "import": "./dist/esm/index.js",
48
- "require": "./dist/phone-mask.cjs.js"
49
- }
52
+ "require": "./dist/phone-mask.cjs",
53
+ "default": "./dist/esm/index.js"
54
+ },
55
+ "./package.json": "./package.json"
50
56
  },
51
57
  "devDependencies": {
52
- "@rollup/plugin-terser": "^0.4.4",
58
+ "@rollup/plugin-terser": "^1.0.0",
53
59
  "google-libphonenumber": "^3.2.44",
54
60
  "vite-plugin-dts": "^4.5.4"
55
61
  },
56
62
  "scripts": {
57
- "clean": "rimraf dist",
58
- "build": "vite build",
63
+ "clean": "rimraf dist coverage",
64
+ "build": "pnpm clean && pnpm build:internal",
65
+ "build:internal": "pnpm build:lib && pnpm build:types",
66
+ "build:lib": "vite build",
59
67
  "build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
60
68
  "dev": "vite",
61
69
  "typecheck": "tsc -p tsconfig.json --noEmit",
70
+ "test:unit": "vitest run --config vitest.config.ts",
71
+ "test:unit:coverage": "vitest run --config vitest.config.ts --coverage.enabled --coverage.provider=v8 --coverage.reporter=lcov --coverage.reportsDirectory=coverage",
62
72
  "gen": "pnpm add -D google-libphonenumber@latest && node scripts/gen.js"
63
73
  }
64
74
  }