@desource/phone-mask 1.0.0 → 1.1.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 +26 -0
- package/README.md +2 -2
- package/dist/country-code-emodji.d.ts +7 -0
- package/dist/country-code-emodji.d.ts.map +1 -0
- package/dist/data-types.d.ts +2 -0
- package/dist/data-types.d.ts.map +1 -0
- package/dist/entries.d.ts +81 -0
- package/dist/entries.d.ts.map +1 -0
- package/dist/esm/formatter.js +1 -1
- package/dist/esm/handlers.js +1 -1
- package/dist/esm/utils.js +1 -1
- package/dist/formatter.d.ts +36 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/handlers.d.ts +63 -0
- package/dist/handlers.d.ts.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/phone-mask.cjs +1 -1
- package/dist/phone-mask.umd.min.js +1 -1
- package/dist/services/geoip/consts.d.ts +5 -0
- package/dist/services/geoip/consts.d.ts.map +1 -0
- package/dist/services/geoip/index.d.ts +4 -0
- package/dist/services/geoip/index.d.ts.map +1 -0
- package/dist/services/geoip/types.d.ts +5 -0
- package/dist/services/geoip/types.d.ts.map +1 -0
- package/dist/services/geoip/utils.d.ts +7 -0
- package/dist/services/geoip/utils.d.ts.map +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/types/formatter.d.ts.map +1 -1
- package/dist/types/handlers.d.ts.map +1 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/utils.d.ts +27 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @desource/phone-mask
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Svelte Upgrades:
|
|
8
|
+
- Added attachment `phoneMaskAttachment` for usage in native input (for Svelte 5.29+ versions)
|
|
9
|
+
- Added action `phoneMaskAction` for usage in native input (for Svelte 5.0+ versions)
|
|
10
|
+
- Improved keyboard country selection flow and active-descendant accessibility behavior
|
|
11
|
+
- Refined dropdown/key navigation handling and related focus behavior
|
|
12
|
+
- `usePhoneMask` now exposes `formatter` in the return object
|
|
13
|
+
|
|
14
|
+
- Vue Upgrades:
|
|
15
|
+
- Directive was refactored to align with Svelte action
|
|
16
|
+
- Improved keyboard country selection flow and active-descendant accessibility behavior
|
|
17
|
+
- Refined dropdown/key navigation handling and related focus behavior
|
|
18
|
+
- `usePhoneMask` now exposes `formatter` in the return object
|
|
19
|
+
|
|
20
|
+
- React Upgrades:
|
|
21
|
+
- Improved keyboard country selection flow and active-descendant accessibility behavior
|
|
22
|
+
- Refined dropdown/key navigation handling and related focus behavior
|
|
23
|
+
- `usePhoneMask` now exposes `formatter` in the return object
|
|
24
|
+
|
|
25
|
+
- Core Upgrades:
|
|
26
|
+
- Fixed edge cases in mask variant selection and improved input handler robustness
|
|
27
|
+
- Applied reliability-focused refactors in formatter/handlers and build script generation logic
|
|
28
|
+
|
|
3
29
|
## 1.0.0
|
|
4
30
|
|
|
5
31
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -333,10 +333,10 @@ All exports are tree-shakeable — only import what you use!
|
|
|
333
333
|
|
|
334
334
|
## 🔗 Related Packages
|
|
335
335
|
|
|
336
|
-
- [@desource/phone-mask-vue](../phone-mask-vue) — Vue 3 component + directive
|
|
336
|
+
- [@desource/phone-mask-vue](../phone-mask-vue) — Vue 3 component + composable + directive
|
|
337
337
|
- [@desource/phone-mask-nuxt](../phone-mask-nuxt) — Nuxt module
|
|
338
338
|
- [@desource/phone-mask-react](../phone-mask-react) — React component + hook
|
|
339
|
-
- [@desource/phone-mask-svelte](../phone-mask-svelte) — Svelte component + composable
|
|
339
|
+
- [@desource/phone-mask-svelte](../phone-mask-svelte) — Svelte component + composable + action + attachment
|
|
340
340
|
|
|
341
341
|
## 📄 License
|
|
342
342
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"country-code-emodji.d.ts","sourceRoot":"","sources":["../src/country-code-emodji.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,IAAI,MAAM,KAAG,MAU7C,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type CountryKey = 'AC' | 'AD' | 'AE' | 'AF' | 'AG' | 'AI' | 'AL' | 'AM' | 'AO' | 'AR' | 'AS' | 'AT' | 'AU' | 'AW' | 'AX' | 'AZ' | 'BA' | 'BB' | 'BD' | 'BE' | 'BF' | 'BG' | 'BH' | 'BI' | 'BJ' | 'BL' | 'BM' | 'BN' | 'BO' | 'BQ' | 'BR' | 'BS' | 'BT' | 'BW' | 'BY' | 'BZ' | 'CA' | 'CC' | 'CD' | 'CF' | 'CG' | 'CH' | 'CI' | 'CK' | 'CL' | 'CM' | 'CN' | 'CO' | 'CR' | 'CU' | 'CV' | 'CW' | 'CX' | 'CY' | 'CZ' | 'DE' | 'DJ' | 'DK' | 'DM' | 'DO' | 'DZ' | 'EC' | 'EE' | 'EG' | 'EH' | 'ER' | 'ES' | 'ET' | 'FI' | 'FJ' | 'FK' | 'FM' | 'FO' | 'FR' | 'GA' | 'GB' | 'GD' | 'GE' | 'GF' | 'GG' | 'GH' | 'GI' | 'GL' | 'GM' | 'GN' | 'GP' | 'GQ' | 'GR' | 'GT' | 'GU' | 'GW' | 'GY' | 'HK' | 'HN' | 'HR' | 'HT' | 'HU' | 'ID' | 'IE' | 'IL' | 'IM' | 'IN' | 'IO' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JE' | 'JM' | 'JO' | 'JP' | 'KE' | 'KG' | 'KH' | 'KI' | 'KM' | 'KN' | 'KP' | 'KR' | 'KW' | 'KY' | 'KZ' | 'LA' | 'LB' | 'LC' | 'LI' | 'LK' | 'LR' | 'LS' | 'LT' | 'LU' | 'LV' | 'LY' | 'MA' | 'MC' | 'MD' | 'ME' | 'MF' | 'MG' | 'MH' | 'MK' | 'ML' | 'MM' | 'MN' | 'MO' | 'MP' | 'MQ' | 'MR' | 'MS' | 'MT' | 'MU' | 'MV' | 'MW' | 'MX' | 'MY' | 'MZ' | 'NA' | 'NC' | 'NE' | 'NF' | 'NG' | 'NI' | 'NL' | 'NO' | 'NP' | 'NR' | 'NU' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PF' | 'PG' | 'PH' | 'PK' | 'PL' | 'PM' | 'PR' | 'PS' | 'PT' | 'PW' | 'PY' | 'QA' | 'RE' | 'RO' | 'RS' | 'RU' | 'RW' | 'SA' | 'SB' | 'SC' | 'SD' | 'SE' | 'SG' | 'SH' | 'SI' | 'SJ' | 'SK' | 'SL' | 'SM' | 'SN' | 'SO' | 'SR' | 'SS' | 'ST' | 'SV' | 'SX' | 'SY' | 'SZ' | 'TA' | 'TC' | 'TD' | 'TG' | 'TH' | 'TJ' | 'TK' | 'TL' | 'TM' | 'TN' | 'TO' | 'TR' | 'TT' | 'TV' | 'TW' | 'TZ' | 'UA' | 'UG' | 'US' | 'UY' | 'UZ' | 'VA' | 'VC' | 'VE' | 'VG' | 'VI' | 'VN' | 'VU' | 'WF' | 'WS' | 'XK' | 'YE' | 'YT' | 'ZA' | 'ZM' | 'ZW';
|
|
2
|
+
//# sourceMappingURL=data-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-types.d.ts","sourceRoot":"","sources":["../src/data-types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { CountryKey } from './data-types';
|
|
2
|
+
interface MaskBase {
|
|
3
|
+
id: CountryKey;
|
|
4
|
+
mask: string | Array<string>;
|
|
5
|
+
}
|
|
6
|
+
interface Mask extends MaskBase {
|
|
7
|
+
code: string;
|
|
8
|
+
}
|
|
9
|
+
interface MaskWithFlag extends Mask {
|
|
10
|
+
flag: string;
|
|
11
|
+
}
|
|
12
|
+
interface MaskFull extends MaskWithFlag {
|
|
13
|
+
name: string;
|
|
14
|
+
}
|
|
15
|
+
type MaskBaseMap = Record<CountryKey, string | Array<string>>;
|
|
16
|
+
type MaskMap = Record<CountryKey, Omit<Mask, 'id'>>;
|
|
17
|
+
type MaskWithFlagMap = Record<CountryKey, Omit<MaskWithFlag, 'id'>>;
|
|
18
|
+
type MaskFullMap = Record<CountryKey, Omit<MaskFull, 'id'>>;
|
|
19
|
+
/**
|
|
20
|
+
* Base masks (including country code) map
|
|
21
|
+
* @example
|
|
22
|
+
* MasksBaseMap.US // "+1 ###-###-####"
|
|
23
|
+
*/
|
|
24
|
+
export declare const MasksBaseMap: MaskBaseMap;
|
|
25
|
+
/** Base masks (including country code) array
|
|
26
|
+
* @example
|
|
27
|
+
* MasksBase[0] // { id: 'US', mask: "+1 ###-###-####" }
|
|
28
|
+
*/
|
|
29
|
+
export declare const MasksBase: MaskBase[];
|
|
30
|
+
/**
|
|
31
|
+
* Masks map with country code as separate property
|
|
32
|
+
* @example
|
|
33
|
+
* MasksMap.US // { code: "+1", mask: "###-###-####" }
|
|
34
|
+
*/
|
|
35
|
+
export declare const MasksMap: MaskMap;
|
|
36
|
+
/**
|
|
37
|
+
* Masks array with country code as separate property
|
|
38
|
+
* @example
|
|
39
|
+
* Masks[0] // { id: 'US', code: "+1", mask: "###-###-####" }
|
|
40
|
+
*/
|
|
41
|
+
export declare const Masks: Mask[];
|
|
42
|
+
/**
|
|
43
|
+
* Masks map with flag emoji
|
|
44
|
+
* @example
|
|
45
|
+
* MasksWithFlagMap.US // { code: "+1", mask: "###-###-####", flag: "🇺🇸" }
|
|
46
|
+
*/
|
|
47
|
+
export declare const MasksWithFlagMap: MaskWithFlagMap;
|
|
48
|
+
/**
|
|
49
|
+
* Masks array with flag emoji
|
|
50
|
+
* @example
|
|
51
|
+
* MasksWithFlag[0] // { id: 'US', code: "+1", mask: "###-###-####", flag: "🇺🇸" }
|
|
52
|
+
*/
|
|
53
|
+
export declare const MasksWithFlag: MaskWithFlag[];
|
|
54
|
+
/**
|
|
55
|
+
* Full masks map with name and flag emoji. Name is localized based on provided language.
|
|
56
|
+
* @example
|
|
57
|
+
* MasksFullMap.US // { code: "+1", mask: "###-###-####", name: "United States", flag: "🇺🇸" }
|
|
58
|
+
*/
|
|
59
|
+
export declare const MasksFullMap: (lang: string) => MaskFullMap;
|
|
60
|
+
/**
|
|
61
|
+
* Full masks array with name and flag emoji. Name is localized based on provided language.
|
|
62
|
+
* @example
|
|
63
|
+
* MasksFull[0] // { id: 'US', code: "+1", mask: "###-###-####", name: "United States", flag: "🇺🇸" }
|
|
64
|
+
*/
|
|
65
|
+
export declare const MasksFull: (lang: string) => MaskFull[];
|
|
66
|
+
/**
|
|
67
|
+
* Full masks map with name and flag emoji in English
|
|
68
|
+
* @example
|
|
69
|
+
* MasksFullMapEn.US // { code: "+1", mask: "###-###-####", name: "United States", flag: "🇺🇸" }
|
|
70
|
+
*/
|
|
71
|
+
export declare const MasksFullMapEn: MaskFullMap;
|
|
72
|
+
/**
|
|
73
|
+
* Full masks array with name and flag emoji in English
|
|
74
|
+
* @example
|
|
75
|
+
* MasksFullEn[0] // { id: 'US', code: "+1", mask: "###-###-####", name: "United States", flag: "🇺🇸" }
|
|
76
|
+
*/
|
|
77
|
+
export declare const MasksFullEn: MaskFull[];
|
|
78
|
+
/** Get flag emoji by country ISO code */
|
|
79
|
+
export declare const getFlagEmoji: (cc: string) => string;
|
|
80
|
+
export type { CountryKey, MaskBaseMap, MaskBase, MaskMap, Mask, MaskWithFlagMap, MaskWithFlag, MaskFullMap, MaskFull };
|
|
81
|
+
//# sourceMappingURL=entries.d.ts.map
|
|
@@ -0,0 +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;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"}
|
package/dist/esm/formatter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{countPlaceholders as t,removeCountryCodePrefix as e,formatDigitsWithMap as n,toArray as r,pickMaskVariant as
|
|
1
|
+
import{countPlaceholders as t,removeCountryCodePrefix as e,formatDigitsWithMap as n,toArray as r,pickMaskVariant as a}from"./utils.js";function createPhoneFormatter(o){const i=r(o.mask),l=i.map(n=>t(e(n))),s=Math.max(...l),getMask=t=>{const n=a(i,t);return e(n)};return{formatDisplay:t=>{const e=getMask(t.length);return n(e,t).display},getMaxDigits:()=>s,getPlaceholder:()=>getMask(0),getCaretPosition:t=>{const e=Math.max(0,t);if(0===e)return 0;const r=getMask(e),{display:a}=n(r,"0".repeat(e));return a.length},getDigitRange:(t,e,r)=>{const a=getMask(t.length),{map:o}=n(a,t);let i=1/0,l=-1/0;for(let t=e;t<r&&t<o.length;t++){const e=o[t];void 0!==e&&e>=0&&(i=Math.min(i,e),l=Math.max(l,e))}return i===1/0?null:[i,l+1]},isComplete:t=>l.includes(t.length)}}export{createPhoneFormatter};
|
package/dist/esm/handlers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const e=[" ","-","(",")"],t=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","Tab"],n=/[^\d\s\-()]/;function removeDigitsRange(e,t,n){return{newDigits:e.slice(0,t)+e.slice(n),caretDigitIndex:t}}function removeSelectedDigits(e,t,n,i){if(n===i)return;const r=t.getDigitRange(e,n,i);if(!r)return;const[s,g]=r;return removeDigitsRange(e,s,g)}function extractDigits(e,t){const n=e.replace(/\D/g,"");return t?n.slice(0,t):n}function getSelection(e){return e?[e.selectionStart??0,e.selectionEnd??0]:[0,0]}function setCaret(e,t){if(e)try{e.setSelectionRange(t,t)}catch{}}function processBeforeInput(e){if(!e.target)return;const t=e.target,i=e.data;"insertText"===e.inputType&&i&&(n.test(i)||" "===i&&t.value.endsWith(" "))&&e.preventDefault()}function processInput(e,t){if(!e.target)return;const n=e.target,{formatter:i}=t,r=i.getMaxDigits(),s=extractDigits(n.value,r);return{newDigits:s,caretDigitIndex:s.length}}function processKeydown(n,i){if(!n.target)return;const r=n.target,{digits:s,formatter:g}=i;if(function shouldIgnoreKeydown(e){return e.ctrlKey||e.metaKey||e.altKey||t.includes(e.key)}(n))return;const[o,c]=getSelection(r),a=r.value;return"Backspace"===n.key?(n.preventDefault(),removeSelectedDigits(s,g,o,c)??function removePreviousDigit(t,n,i,r){if(r<=0)return;let s=r-1;for(;s>=0&&e.includes(i[s]);)s--;if(s<0)return;const g=n.getDigitRange(t,s,s+1);if(!g)return;const[o]=g;return removeDigitsRange(t,o,o+1)}(s,g,a,o)):"Delete"===n.key?(n.preventDefault(),removeSelectedDigits(s,g,o,c)??function removeNextDigit(e,t,n,i){if(i>=n.length)return;const r=t.getDigitRange(e,i,n.length);if(!r)return;const[s]=r;return removeDigitsRange(e,s,s+1)}(s,g,a,o)):void(/^\d$/.test(n.key)?s.length>=g.getMaxDigits()&&n.preventDefault():1===n.key.length&&n.preventDefault())}function processPaste(e,t){if(!e.target)return;e.preventDefault();const n=e.target,{digits:i,formatter:r}=t,s=e.clipboardData?.getData("text")||"",g=r.getMaxDigits(),o=extractDigits(s,g);if(0===o.length)return;const[c,a]=getSelection(n);if(c!==a){const e=r.getDigitRange(i,c,a);if(e){const[t,n]=e;return{newDigits:extractDigits(i.slice(0,t)+o+i.slice(n),g),caretDigitIndex:t+o.length}}}const u=r.getDigitRange(i,0,c),l=u?u[1]:0;return{newDigits:extractDigits(i.slice(0,l)+o+i.slice(l),g),caretDigitIndex:l+o.length}}export{e as DELIMITERS,n as INVALID_PATTERN,t as NAVIGATION_KEYS,extractDigits,getSelection,processBeforeInput,processInput,processKeydown,processPaste,setCaret};
|
package/dist/esm/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MasksFullMap as t,MasksFullMapEn as
|
|
1
|
+
import{MasksFullMap as t,MasksFullMapEn as r}from"./entries.js";function getNavigatorLang(){return globalThis.navigator?.language||"en"}function detectCountryFromLocale(){try{const t=getNavigatorLang();try{const r=new Intl.Locale(t);if(r.region)return r.region.toUpperCase()}catch{}const r=t.split(/[-_]/);if(r.length>1)return r[1]?.toUpperCase()||null}catch{}return null}function hasCountry(t){const e=r;return t.toUpperCase()in e}function getCountry(r,e){const n=t(e),o=r.toUpperCase();return o in n?{id:o,...n[o]}:{id:"US",...n.US}}function parseCountryCode(t,r){return t&&hasCountry(t)?t.toUpperCase():r||""}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,r){if(!t.length)return"";if(1===t.length)return t[0];const e=t.map(t=>({mask:t,count:countPlaceholders(t)})),n=e.filter(t=>t.count>=r).sort((t,r)=>t.count-r.count);if(n.length>0)return n[0].mask;const o=e.sort((t,r)=>r.count-t.count)[0];return o?o.mask:t[0]}function formatDigitsWithMap(t,r){let e="";const n=[];let o=0;const a=r.length,s=t.length;for(let c=0;c<s;c++){const s=t[c];if("#"===s){if(!(o<a))break;e+=r[o],n.push(o),o++}else{const r=-1!==t.indexOf("#",c+1)&&o<a;(e.length>0||r)&&(e+=s,n.push(-1))}}return{display:e,map:n}}function filterCountries(t,r){const e=r.trim().toUpperCase();if(!e)return t;const n=e.replace(/\D/g,""),o=n.length>0;return t.map(t=>{const r=t.name.toUpperCase(),a=t.id.toUpperCase(),s=t.code.toUpperCase(),c=t.code.replace(/\D/g,"");let i=0;return r.startsWith(e)?i=1e3:r.includes(e)&&(i=500),s.startsWith(e)?i+=100:s.includes(e)&&(i+=50),a===e?i+=200:a.startsWith(e)&&(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,r)=>r.score===t.score?t.country.name.localeCompare(r.country.name):r.score-t.score).map(t=>t.country)}export{countPlaceholders,detectCountryFromLocale,filterCountries,formatDigitsWithMap,getCountry,getNavigatorLang,hasCountry,parseCountryCode,pickMaskVariant,removeCountryCodePrefix,toArray};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { 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,CAuDxE"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { 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;AAoED;;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,CA2CxG;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,kBAAkB,GAAG,WAAW,GAAG,SAAS,CAkDnG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +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;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
|
package/dist/phone-mask.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const data={AC:"+247 #####",AD:["+376 ### ###","+376 #### ####"],AE:["+971 # ### ####","+971 ## ### ####","+971 ### ######","+971 ### # #####"],AF:"+93 ## ### ####",AG:"+1 ###-###-####",AI:"+1 ###-###-####",AL:["+355 ## ### ###","+355 ## ### ####","+355 ### ####","+355 ### ###","+355 ### #####"],AM:["+374 ## ######","+374 ### ## ###"],AO:"+244 ### ### ###",AR:["+54 ## ####-####","+54 # ## ####-####","+54 ###-###-####"],AS:"+1 ###-###-####",AT:["+43 # #########","+43 ### ######"],AU:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###","+61 ## ### ##"],AW:"+297 ### ####",AX:["+358 ## #######","+358 ### ######"],AZ:["+994 ## ### ## ##","+994 ### ## ## ##"],BA:["+387 ## ###-###","+387 ## ### ###"],BB:"+1 ###-###-####",BD:["+880 #-#######","+880 ####-######","+880 ###-#######"],BE:["+32 ## ## ## ##","+32 ### ## ## ##","+32 ### ## ###"],BF:"+226 ## ## ## ##",BG:["+359 # ### ###","+359 ## ### ###","+359 ### ## ###"],BH:"+973 #### ####",BI:"+257 ## ## ## ##",BJ:["+229 ## ## ## ## ##","+229 ## ## ## ##"],BL:"+590 ### ## ## ##",BM:"+1 ###-###-####",BN:"+673 ### ####",BO:["+591 # #######","+591 ########","+591 ### ## ####"],BQ:"+599 ### ####",BR:["+55 ## ####-####","+55 ## #####-####","+55 ### ## ####","+55 ####-####"],BS:"+1 ###-###-####",BT:["+975 # ### ###","+975 ## ## ## ##"],BW:["+267 ### ####","+267 ## ### ###","+267 #### ### ###","+267 ## #####"],BY:["+375 ### ##-##-##","+375 ## ###-##-##","+375 ### ### ####"],BZ:["+501 ###-####","+501 #-###-####-###"],CA:"+1 ###-###-####",CC:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###"],CD:["+243 ## #####","+243 ### ### ###"],CF:"+236 ## ## ## ##",CG:["+242 ## ### ####","+242 # #### ####"],CH:["+41 ## ### ## ##","+41 ### ### ###"],CI:["+225 ## ## # #####","+225 ## ## ## ####"],CK:"+682 ## ###",CL:["+56 ### ### ###","+56 # #### ####","+56 ### ### ####","+56 ## ### ####"],CM:["+237 # ## ## ## ##","+237 ## ## ## ##"],CN:["+86 ## #### ####","+86 ### #### ####","+86 ### ### ####","+86 ########"],CO:["+57 ### #######","+57 # ### #######"],CR:["+506 #### ####","+506 ###-###-####"],CU:["+53 # #######","+53 ### #######"],CV:"+238 ### ## ##",CW:["+599 # ### ####","+599 ### ####"],CX:["+61 # #### ####","+61 ### ### ###","+61 #### ### ###"],CY:"+357 ## ######",CZ:"+420 ### ### ###",DE:["+49 ## ######","+49 #### #######","+49 ### ##########","+49 ### # ######","+49 ### # ####","+49 ### #### ####","+49 ########"],DJ:"+253 ## ## ## ##",DK:"+45 ## ## ## ##",DM:"+1 ###-###-####",DO:"+1 ###-###-####",DZ:["+213 ## ## ## ##","+213 ### ## ## ##","+213 ## ### ## ##"],EC:["+593 #-###-####","+593 ## ### ####","+593 #### ### ####"],EE:["+372 ### ####","+372 #### ####","+372 ## ## ####"],EG:["+20 # ########","+20 ## ########","+20 ### ### ####"],EH:["+212 # ## ## ## ##","+212 ##-#######"],ER:"+291 # ### ###",ES:["+34 ### ## ## ##","+34 ### ### ###"],ET:"+251 ## ### ####",FI:["+358 ## #######","+358 ### ######"],FJ:["+679 ### ####","+679 #### ### ####"],FK:"+500 #####",FM:"+691 ### ####",FO:"+298 ######",FR:["+33 # ## ## ## ##","+33 ### ## ## ##"],GA:"+241 ## ## ## ##",GB:["+44 ### ### ####","+44 #### ######","+44 ## #### ####"],GD:"+1 ###-###-####",GE:["+995 ## ### ## ##","+995 ### ## ## ##","+995 ### ### ###"],GF:"+594 ### ## ## ##",GG:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],GH:["+233 ## ### ####","+233 ### #####"],GI:["+350 ### #####","+350 ########"],GL:"+299 ## ## ##",GM:"+220 ### ####",GN:["+224 ## ## ## ##","+224 ### ## ## ##"],GP:"+590 ### ## ## ##",GQ:["+240 ### ### ###","+240 ### ######"],GR:["+30 ## #### ####","+30 ### ### ####"],GT:["+502 #### ####","+502 #### ### ####"],GU:"+1 ###-###-####",GW:["+245 ### ### ###","+245 ### ####"],GY:"+592 ### ####",HK:["+852 #### ####","+852 ### ### ###","+852 ### ## ### ###"],HN:["+504 ####-####","+504 ###########"],HR:["+385 # #### ###","+385 ## ### ####","+385 ### ### ###","+385 ## ## ###","+385 ## ### ###"],HT:"+509 ## ## ####",HU:["+36 # ### ####","+36 ## ### ####","+36 ## ### ###"],ID:["+62 ## #######","+62 ###-###-###","+62 ### #######","+62 ### # ### ###","+62 ### ### ####"],IE:["+353 ## #####","+353 ## ### ####","+353 #### ### ###","+353 ### ### ###"],IL:["+972 #-###-####","+972 ##-###-####","+972 #-###-###-###"],IM:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],IN:["+91 ##### #####","+91 #### ## ####","+91 #### ### ### ###","+91 #### ### ####"],IO:"+246 ### ####",IQ:["+964 # ### ####","+964 ### ### ####"],IR:["+98 ## #### ####","+98 ### ### ####"],IS:"+354 ### ####",IT:["+39 ## #### ####","+39 ### ### ####","+39 ### ### ###"],JE:["+44 #### ######","+44 ### ### ####","+44 ## #### ####"],JM:"+1 ###-###-####",JO:["+962 # ### ####","+962 # #### ####","+962 ### #####","+962 ## #######"],JP:["+81 #-####-####","+81 ##-####-####","+81 ###-###-###","+81 ##-###-####"],KE:["+254 ## #######","+254 ### ######","+254 ### ### ###"],KG:["+996 ### ### ###","+996 ### ### # ##"],KH:["+855 ## ### ###","+855 #### ### ###"],KI:["+686 #####","+686 ########"],KM:"+269 ### ## ##",KN:"+1 ###-###-####",KP:["+850 # ### ####","+850 ### ### ####"],KR:["+82 #-###-####","+82 ##-####-####","+82 ##-###-####"],KW:["+965 #### ####","+965 ### #####","+965 #### ###"],KY:"+1 ###-###-####",KZ:["+7 ##### # ## ##","+7 ### ### ####","+7 ### ###-##-##"],LA:["+856 ## ### ###","+856 ## ## ### ###"],LB:["+961 # ### ###","+961 ## ### ###"],LC:"+1 ###-###-####",LI:["+423 ### ## ##","+423 ### ### ###"],LK:["+94 ### ### ###","+94 ## ### ####"],LR:["+231 ## ### ###","+231 ## ### ####"],LS:"+266 #### ####",LT:["+370 ### #####","+370 ### ## ###"],LU:["+352 ## ## ## ##","+352 ### ### ###","+352 ### ## ###"],LV:"+371 ## ### ###",LY:"+218 ##-#######",MA:["+212 # ## ## ## ##","+212 ##-#######"],MC:["+377 ## ## ## ##","+377 # ## ## ## ##"],MD:["+373 ## ### ###","+373 ### ## ###","+373 ### #####"],ME:"+382 ## ### ###",MF:"+590 ### ## ## ##",MG:"+261 ## ## ### ##",MH:"+692 ###-####",MK:["+389 # ### ####","+389 ## ### ###","+389 ### # ## ##"],ML:"+223 ## ## ## ##",MM:["+95 # ### ###","+95 # ### ####","+95 ### ### ####"],MN:"+976 #### ####",MO:["+853 #### ####","+853 #### ###"],MP:"+1 ###-###-####",MQ:"+596 ### ## ## ##",MR:"+222 ## ## ## ##",MS:"+1 ###-###-####",MT:"+356 #### ####",MU:["+230 #### ####","+230 ### ####"],MV:["+960 ###-####","+960 ### ### ####"],MW:["+265 # ### ###","+265 ### ## ## ##"],MX:"+52 ### ### ####",MY:["+60 #-#### ####","+60 ##-### ####","+60 #-###-##-####","+60 ###-### ####"],MZ:["+258 ## ### ###","+258 ## ### ####","+258 ### ### ###"],NA:["+264 ## ### ###","+264 ## ### ####","+264 ### ### ###"],NC:"+687 ##.##.##",NE:["+227 ## ## ## ##","+227 ## ### ###"],NF:["+672 ## ####","+672 # #####"],NG:["+234 #### ## ####","+234 ### ### ####","+234 ### #### ####"],NI:"+505 #### ####",NL:["+31 ## ### ####","+31 # ########","+31 ### ####","+31 ## #######"],NO:["+47 ## ## ## ##","+47 ### ## ###"],NP:["+977 #-#######","+977 ###-#######","+977 ###########"],NR:"+674 ### ####",NU:["+683 ####","+683 ### ####"],NZ:["+64 # ### ####","+64 ## ### ####","+64 ### ### ###"],OM:["+968 ## ######","+968 #### ####","+968 ### #####"],PA:["+507 ###-####","+507 ####-####"],PE:["+51 # #######","+51 ### ### ###","+51 ### #####"],PF:["+689 ## ## ## ##","+689 ### ## ## ##"],PG:["+675 ### ####","+675 #### ####"],PH:["+63 # #### ####","+63 ### ### ####","+63 #### # ### ####"],PK:["+92 ## ########","+92 ### #######","+92 ### ### ##","+92 #### #####"],PL:["+48 ## ### ## ##","+48 ### ### ###"],PM:["+508 ## ## ##","+508 ### ## ## ##"],PR:"+1 ###-###-####",PS:["+970 # ### ####","+970 ### ### ###","+970 #### ### ###"],PT:["+351 ## ### ####","+351 ### ### ###"],PW:"+680 ### ####",PY:["+595 ## ### ####","+595 ### ######","+595 #### ### ####"],QA:["+974 #### ####","+974 ### ####"],RE:"+262 ### ## ## ##",RO:["+40 ## ### ####","+40 ### ### ###"],RS:["+381 ## ######","+381 ## #######","+381 ### #####"],RU:"+7 ### ###-##-##",RW:"+250 ### ### ###",SA:["+966 ## ### ####","+966 ### ### ####","+966 #### #####"],SB:["+677 #####","+677 ## #####"],SC:["+248 # ### ###","+248 #######"],SD:"+249 ## ### ####",SE:["+46 # ## ## ##","+46 ## ### ## ##","+46 ## ## ## ##","+46 ### ## ## ###"],SG:["+65 #### ####","+65 #### ### ####"],SH:"+290 #####",SI:["+386 # ### ## ##","+386 ## ### ###","+386 ## ######","+386 ### #####"],SJ:["+47 ## ## ## ##","+47 ### ## ###"],SK:["+421 #/### ### ##","+421 ### ### ###","+421 #######"],SL:"+232 ## ######",SM:["+378 #### ######","+378 ## ## ## ##"],SN:["+221 ## ### ## ##","+221 ### ## ## ##"],SO:["+252 # ######","+252 # #######"],SR:["+597 ###-###","+597 ###-####","+597 ##-##-##"],SS:"+211 ### ### ###",ST:"+239 ### ####",SV:["+503 #### ####","+503 ### ####"],SX:"+1 ###-###-####",SY:["+963 ## ### ####","+963 ### ### ###"],SZ:["+268 #### ####","+268 ##### ####"],TA:"+290 ####",TC:"+1 ###-###-####",TD:"+235 ## ## ## ##",TG:"+228 ## ## ## ##",TH:["+66 # ### ####","+66 ## ### ####","+66 #### ### ###"],TJ:["+992 ### ## ####","+992 ## ### ####"],TK:"+690 ####",TL:["+670 ### ####","+670 #### ####"],TM:["+993 ## ##-##-##","+993 ## ######"],TN:"+216 ## ### ###",TO:["+676 ##-###","+676 ### ####","+676 #### ###"],TR:["+90 ### ### ## ##","+90 ### ### ####"],TT:"+1 ###-###-####",TV:["+688 ## ###","+688 ## ####"],TW:["+886 # #### ####","+886 ### ### ###","+886 ## ### ####","+886 ## #### ####"],TZ:["+255 ## ### ####","+255 ### ### ###","+255 ### ## ####"],UA:["+380 #### #####","+380 ## ### ####","+380 ### ### ###"],UG:["+256 ## #######","+256 ### ######"],US:"+1 ###-###-####",UY:["+598 #### ####","+598 ## ### ###","+598 ### ####"],UZ:"+998 ## ### ## ##",VA:["+39 ## #### ####","+39 ### ### ####","+39 ### ### ###"],VC:"+1 ###-###-####",VE:"+58 ###-#######",VG:"+1 ###-###-####",VI:"+1 ###-###-####",VN:["+84 ### #### ###","+84 ### ### ###","+84 #### ######","+84 ## ### ## ##"],VU:["+678 #####","+678 ### ####"],WF:["+681 ## ## ##","+681 ### ## ## ##"],WS:["+685 #####","+685 ## #####","+685 ### ###"],XK:["+383 ## ### ###","+383 ### #####"],YE:["+967 # ### ###","+967 ### ### ###"],YT:"+262 ### ## ## ##",ZA:["+27 ## ### ####","+27 ### ### ###"],ZM:["+260 ### ### ###","+260 ## #######","+260 #########"],ZW:["+263 ## #####","+263 ## ### ####","+263 ### ####","+263 #### ######"]},CC_REGEX=/^[a-z]{2}$/i,countryCodeEmoji=t=>{if(!CC_REGEX.test(t)){const e=typeof t;throw new TypeError(`cc argument must be an ISO 3166-1 alpha-2 string, but got '${"string"===e?t:e}' instead.`)}const e=[...t.toUpperCase()].map(t=>(t.codePointAt(0)??0)+127397);return String.fromCodePoint(...e)},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
|
+
"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,o]=divideMask(r);e||(e=t),n.push(o)}r=n}else{const[n,o]=divideMask(t);e=n,r=o}return[e,r]}const MasksBaseMap=data,MasksBase=dataEntries.map(([t,e])=>({id:t,mask:e})),MasksMap=dataEntries.reduce((t,[e,r])=>{const[n,o]=getCodeAndMask(r);return t[e]={code:n,mask:o},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,o]=getCodeAndMask(r);return t[e]={code:n,mask:o,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[o,s]=getCodeAndMask(n),a=e.of(r)??"";return t[r]={code:o,mask:s,name:a,flag:countryCodeEmoji(r)},t},{})},MasksFull=t=>{const e=getDisplayNames(t);return dataEntries.map(([t,r])=>{const[n,o]=getCodeAndMask(r);return{id:t,code:n,mask:o,name:e.of(t)??"",flag:countryCodeEmoji(t)}})},MasksFullMapEn=MasksFullMap("en"),MasksFullEn=MasksFull("en"),getFlagEmoji=countryCodeEmoji,CACHE_KEY="@desource/phone-mask:geo";function getNavigatorLang(){return globalThis.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(!t.length)return"";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 s=e.length,a=t.length;for(let i=0;i<a;i++){const a=t[i];if("#"===a){if(!(o<s))break;r+=e[o],n.push(o),o++}else{const e=-1!==t.indexOf("#",i+1)&&o<s;(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 o=await e.json();return(o.country||o.country_code||o.countryCode||o.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 removeDigitsRange(t,e,r){return{newDigits:t.slice(0,e)+t.slice(r),caretDigitIndex:e}}function removeSelectedDigits(t,e,r,n){if(r===n)return;const o=e.getDigitRange(t,r,n);if(!o)return;const[s,a]=o;return removeDigitsRange(t,s,a)}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=Math.max(0,t);if(0===e)return 0;const r=getMask(e),{display:n}=formatDigitsWithMap(r,"0".repeat(e));return n.length},getDigitRange:(t,e,r)=>{const n=getMask(t.length),{map:o}=formatDigitsWithMap(n,t);let s=1/0,a=-1/0;for(let t=e;t<r&&t<o.length;t++){const e=o[t];void 0!==e&&e>=0&&(s=Math.min(s,e),a=Math.max(a,e))}return s===1/0?null:[s,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,""),o=n.length>0;return t.map(t=>{const e=t.name.toUpperCase(),s=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),s===r?c+=200:s.startsWith(r)&&(c+=150),o&&i.startsWith(n)?c+=80:o&&i.includes(n)&&(c+=40),{country:t,score:c}}).filter(t=>t.score>0).sort((t,e)=>e.score===t.score?t.country.name.localeCompare(e.country.name):e.score-t.score).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,o=n.getMaxDigits(),s=extractDigits(r.value,o);return{newDigits:s,caretDigitIndex:s.length}},exports.processKeydown=function processKeydown(t,e){if(!t.target)return;const r=t.target,{digits:n,formatter:o}=e;if(function shouldIgnoreKeydown(t){return t.ctrlKey||t.metaKey||t.altKey||NAVIGATION_KEYS.includes(t.key)}(t))return;const[s,a]=getSelection(r),i=r.value;return"Backspace"===t.key?(t.preventDefault(),removeSelectedDigits(n,o,s,a)??function removePreviousDigit(t,e,r,n){if(n<=0)return;let o=n-1;for(;o>=0&&DELIMITERS.includes(r[o]);)o--;if(o<0)return;const s=e.getDigitRange(t,o,o+1);if(!s)return;const[a]=s;return removeDigitsRange(t,a,a+1)}(n,o,i,s)):"Delete"===t.key?(t.preventDefault(),removeSelectedDigits(n,o,s,a)??function removeNextDigit(t,e,r,n){if(n>=r.length)return;const o=e.getDigitRange(t,n,r.length);if(!o)return;const[s]=o;return removeDigitsRange(t,s,s+1)}(n,o,i,s)):void(/^\d$/.test(t.key)?n.length>=o.getMaxDigits()&&t.preventDefault():1===t.key.length&&t.preventDefault())},exports.processPaste=function processPaste(t,e){if(!t.target)return;t.preventDefault();const r=t.target,{digits:n,formatter:o}=e,s=t.clipboardData?.getData("text")||"",a=o.getMaxDigits(),i=extractDigits(s,a);if(0===i.length)return;const[c,u]=getSelection(r);if(c!==u){const t=o.getDigitRange(n,c,u);if(t){const[e,r]=t;return{newDigits:extractDigits(n.slice(0,e)+i+n.slice(r),a),caretDigitIndex:e+i.length}}}const l=o.getDigitRange(n,0,c),g=l?l[1]:0;return{newDigits:extractDigits(n.slice(0,g)+i+n.slice(g),a),caretDigitIndex:g+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,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
|
+
!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,a=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},i=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=i.map(([t,e])=>({id:t,mask:e})),f=i.reduce((t,[e,n])=>{const[r,o]=u(n);return t[e]={code:r,mask:o},t},{}),p=i.map(([t,e])=>{const[n,r]=u(e);return{id:t,code:n,mask:r}}),d=i.reduce((t,[e,n])=>{const[o,s]=u(n);return t[e]={code:o,mask:s,flag:r(e)},t},{}),M=i.map(([t,e])=>{const[n,o]=u(e);return{id:t,code:n,mask:o,flag:r(t)}}),m=t=>{const e=a(t);return i.reduce((t,[n,o])=>{const[s,a]=u(o),i=e.of(n)??"";return t[n]={code:s,mask:a,name:i,flag:r(n)},t},{})},h=t=>{const e=a(t);return i.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),y=h(o),D=r,S="https://ipapi.co/json/",A="@desource/phone-mask:geo",I=864e5;function T(){return globalThis.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(!t.length)return"";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,a=t.length;for(let i=0;i<a;i++){const a=t[i];if("#"===a){if(!(o<s))break;n+=e[o],r.push(o),o++}else{const e=-1!==t.indexOf("#",i+1)&&o<s;(n.length>0||e)&&(n+=a,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"],F=/[^\d\s\-()]/;function O(t,e,n){return{newDigits:t.slice(0,e)+t.slice(n),caretDigitIndex:e}}function w(t,e,n,r){if(n===r)return;const o=e.getDigitRange(t,n,r);if(!o)return;const[s,a]=o;return O(t,s,a)}function W(t,e){const n=t.replace(/\D/g,"");return e?n.slice(0,e):n}function x(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=F,t.Masks=p,t.MasksBase=g,t.MasksBaseMap=l,t.MasksFull=h,t.MasksFullEn=y,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=Math.max(0,t);if(0===e)return 0;const n=o(e),{display:r}=U(n,"0".repeat(e));return r.length},getDigitRange:(t,e,n)=>{const r=o(t.length),{map:s}=U(r,t);let a=1/0,i=-1/0;for(let t=e;t<n&&t<s.length;t++){const e=s[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=>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=W,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(),a=t.code.toUpperCase(),i=t.code.replace(/\D/g,"");let c=0;return e.startsWith(n)?c=1e3:e.includes(n)&&(c=500),a.startsWith(n)?c+=100:a.includes(n)&&(c+=50),s===n?c+=200:s.startsWith(n)&&(c+=150),o&&i.startsWith(r)?c+=80:o&&i.includes(r)&&(c+=40),{country:t,score:c}}).filter(t=>t.score>0).sort((t,e)=>e.score===t.score?t.country.name.localeCompare(e.country.name):e.score-t.score).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=D,t.getNavigatorLang=T,t.getSelection=x,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&&(F.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=W(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(function(t){return t.ctrlKey||t.metaKey||t.altKey||K.includes(t.key)}(t))return;const[s,a]=x(n),i=n.value;return"Backspace"===t.key?(t.preventDefault(),w(r,o,s,a)??function(t,e,n,r){if(r<=0)return;let o=r-1;for(;o>=0&&L.includes(n[o]);)o--;if(o<0)return;const s=e.getDigitRange(t,o,o+1);if(!s)return;const[a]=s;return O(t,a,a+1)}(r,o,i,s)):"Delete"===t.key?(t.preventDefault(),w(r,o,s,a)??function(t,e,n,r){if(r>=n.length)return;const o=e.getDigitRange(t,r,n.length);if(!o)return;const[s]=o;return O(t,s,s+1)}(r,o,i,s)):void(/^\d$/.test(t.key)?r.length>=o.getMaxDigits()&&t.preventDefault():1===t.key.length&&t.preventDefault())},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")||"",a=o.getMaxDigits(),i=W(s,a);if(0===i.length)return;const[c,u]=x(n);if(c!==u){const t=o.getDigitRange(r,c,u);if(t){const[e,n]=t;return{newDigits:W(r.slice(0,e)+i+r.slice(n),a),caretDigitIndex:e+i.length}}}const l=o.getDigitRange(r,0,c),g=l?l[1]:0;return{newDigits:W(r.slice(0,g)+i+r.slice(g),a),caretDigitIndex:g+i.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"})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/services/geoip/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,2BAA2B,CAAC;AACvD,eAAO,MAAM,iBAAiB,OAAQ,CAAC;AAEvC,eAAO,MAAM,SAAS,6BAA6B,CAAC;AACpD,eAAO,MAAM,eAAe,QAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/geoip/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/services/geoip/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;CACZ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect country from GeoIP service.
|
|
3
|
+
* Attempts to fetch country code from external API with timeout
|
|
4
|
+
*/
|
|
5
|
+
export declare function detectCountryFromGeoIP(url?: string, timeout?: number): Promise<string | null>;
|
|
6
|
+
export declare function detectByGeoIp(): Promise<string | null>;
|
|
7
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/services/geoip/utils.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
|
@@ -1 +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,
|
|
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,CAuDxE"}
|
|
@@ -1 +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;
|
|
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;AAoED;;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,CA2CxG;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,kBAAkB,GAAG,WAAW,GAAG,SAAS,CAkDnG"}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,CAiBpF;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/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MaskFull } from './entries';
|
|
2
|
+
export type FormatResult = {
|
|
3
|
+
display: string;
|
|
4
|
+
map: number[];
|
|
5
|
+
};
|
|
6
|
+
/** Get navigator language with fallback to 'en' */
|
|
7
|
+
export declare function getNavigatorLang(): string;
|
|
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;
|
|
12
|
+
/** Get country data by ISO code and locale with fallback to US */
|
|
13
|
+
export declare function getCountry(code: string, locale: string): MaskFull;
|
|
14
|
+
export declare function parseCountryCode(code?: string | null, fallback?: string): string;
|
|
15
|
+
/** Ensure mask is an array of strings */
|
|
16
|
+
export declare function toArray<T>(mask: T | T[]): T[];
|
|
17
|
+
/** Count number of placeholders (#) in a mask string */
|
|
18
|
+
export declare function countPlaceholders(maskStr: string): number;
|
|
19
|
+
/** Remove country code prefix (e.g., +1 ) from a mask string */
|
|
20
|
+
export declare function removeCountryCodePrefix(maskStr: string): string;
|
|
21
|
+
/** Pick the most suitable mask variant based on typed digits count */
|
|
22
|
+
export declare function pickMaskVariant(variants: string[], typedDigitsCount: number): string;
|
|
23
|
+
/** Formatting with mapping for efficient position tracking */
|
|
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[];
|
|
27
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,CAiBpF;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": "1.
|
|
3
|
+
"version": "1.1.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",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"vite-plugin-dts": "^4.5.4"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
|
-
"clean": "rimraf dist coverage",
|
|
63
|
+
"clean": "rimraf dist coverage tsconfig.tsbuildinfo",
|
|
64
64
|
"build": "pnpm clean && pnpm build:internal",
|
|
65
65
|
"build:internal": "pnpm build:lib && pnpm build:types",
|
|
66
66
|
"build:lib": "vite build",
|