@rpcbase/ui 0.261.0 → 0.262.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/dist/assets/sha256.worker-BEf4_Y9w.js.map +1 -0
- package/dist/components/FilesUploadField/index.d.ts +19 -6
- package/dist/components/FilesUploadField/index.d.ts.map +1 -1
- package/dist/components/FilesUploadField/sha256.d.ts +5 -0
- package/dist/components/FilesUploadField/sha256.d.ts.map +1 -0
- package/dist/components/FilesUploadField/sha256.worker.d.ts +4 -0
- package/dist/components/FilesUploadField/sha256.worker.d.ts.map +1 -0
- package/dist/components/ImagesField/index.d.ts +4 -2
- package/dist/components/ImagesField/index.d.ts.map +1 -1
- package/dist/index.js +10 -10
- package/dist/index298.js +11 -803
- package/dist/index298.js.map +1 -1
- package/dist/index299.js +865 -28
- package/dist/index299.js.map +1 -1
- package/dist/index300.js +26 -510
- package/dist/index300.js.map +1 -1
- package/dist/index301.js +481 -755
- package/dist/index301.js.map +1 -1
- package/dist/index302.js +786 -7428
- package/dist/index302.js.map +1 -1
- package/dist/index303.js +7429 -7
- package/dist/index303.js.map +1 -1
- package/dist/index304.js +6 -12
- package/dist/index304.js.map +1 -1
- package/dist/index305.js +12 -5
- package/dist/index305.js.map +1 -1
- package/dist/index306.js +3 -3
- package/dist/index306.js.map +1 -1
- package/dist/index307.js +5 -469
- package/dist/index307.js.map +1 -1
- package/dist/index308.js +464 -32
- package/dist/index308.js.map +1 -1
- package/dist/index309.js +36 -18
- package/dist/index309.js.map +1 -1
- package/dist/index310.js +17 -28
- package/dist/index310.js.map +1 -1
- package/dist/index311.js +30 -4
- package/dist/index311.js.map +1 -1
- package/dist/index312.js +4 -59
- package/dist/index312.js.map +1 -1
- package/dist/index313.js +59 -9
- package/dist/index313.js.map +1 -1
- package/dist/index314.js +9 -5
- package/dist/index314.js.map +1 -1
- package/dist/index315.js +5 -9
- package/dist/index315.js.map +1 -1
- package/dist/index316.js +9 -12
- package/dist/index316.js.map +1 -1
- package/dist/index317.js +13 -3
- package/dist/index317.js.map +1 -1
- package/dist/index318.js +3 -17
- package/dist/index318.js.map +1 -1
- package/dist/index319.js +14 -23
- package/dist/index319.js.map +1 -1
- package/dist/index320.js +23 -39
- package/dist/index320.js.map +1 -1
- package/dist/index321.js +41 -5
- package/dist/index321.js.map +1 -1
- package/dist/index322.js +5 -25
- package/dist/index322.js.map +1 -1
- package/dist/index323.js +24 -18
- package/dist/index323.js.map +1 -1
- package/dist/index324.js +17 -32
- package/dist/index324.js.map +1 -1
- package/dist/index325.js +34 -5
- package/dist/index325.js.map +1 -1
- package/dist/index326.js +5 -9
- package/dist/index326.js.map +1 -1
- package/dist/index327.js +8 -7
- package/dist/index327.js.map +1 -1
- package/dist/index328.js +8 -9
- package/dist/index328.js.map +1 -1
- package/dist/index329.js +9 -10
- package/dist/index329.js.map +1 -1
- package/dist/index330.js +10 -7
- package/dist/index330.js.map +1 -1
- package/dist/index331.js +7 -75
- package/dist/index331.js.map +1 -1
- package/dist/index332.js +66 -153
- package/dist/index332.js.map +1 -1
- package/dist/index333.js +147 -99
- package/dist/index333.js.map +1 -1
- package/dist/index334.js +113 -13
- package/dist/index334.js.map +1 -1
- package/dist/index335.js +12 -78
- package/dist/index335.js.map +1 -1
- package/dist/index336.js +57 -23
- package/dist/index336.js.map +1 -1
- package/dist/index337.js +45 -12
- package/dist/index337.js.map +1 -1
- package/dist/index338.js +13 -16
- package/dist/index338.js.map +1 -1
- package/dist/index339.js +15 -100
- package/dist/index339.js.map +1 -1
- package/dist/index340.js +95 -50
- package/dist/index340.js.map +1 -1
- package/dist/index341.js +5 -57
- package/dist/index341.js.map +1 -1
- package/dist/index342.js +78 -41
- package/dist/index342.js.map +1 -1
- package/dist/index343.js +58 -100
- package/dist/index343.js.map +1 -1
- package/dist/index344.js +104 -46
- package/dist/index344.js.map +1 -1
- package/dist/index345.js +51 -39
- package/dist/index345.js.map +1 -1
- package/dist/index346.js +42 -142
- package/dist/index346.js.map +1 -1
- package/dist/index347.js +123 -120
- package/dist/index347.js.map +1 -1
- package/dist/index348.js +108 -224
- package/dist/index348.js.map +1 -1
- package/dist/index349.js +174 -158
- package/dist/index349.js.map +1 -1
- package/dist/index350.js +144 -213
- package/dist/index350.js.map +1 -1
- package/dist/index351.js +309 -5
- package/dist/index351.js.map +1 -1
- package/dist/index352.js +5 -6
- package/dist/index352.js.map +1 -1
- package/dist/index353.js +6 -7
- package/dist/index353.js.map +1 -1
- package/dist/index354.js +5 -4
- package/dist/index354.js.map +1 -1
- package/dist/index355.js +4 -4
- package/dist/index355.js.map +1 -1
- package/dist/index356.js +6 -21
- package/dist/index356.js.map +1 -1
- package/dist/index357.js +21 -10
- package/dist/index357.js.map +1 -1
- package/dist/index358.js +10 -128
- package/dist/index358.js.map +1 -1
- package/dist/index359.js +122 -36
- package/dist/index359.js.map +1 -1
- package/dist/index360.js +38 -64
- package/dist/index360.js.map +1 -1
- package/dist/index361.js +66 -115
- package/dist/index361.js.map +1 -1
- package/dist/index362.js +112 -485
- package/dist/index362.js.map +1 -1
- package/dist/index363.js +490 -13
- package/dist/index363.js.map +1 -1
- package/dist/index364.js +13 -4
- package/dist/index364.js.map +1 -1
- package/dist/index365.js +4 -47
- package/dist/index365.js.map +1 -1
- package/dist/index366.js +44 -15
- package/dist/index366.js.map +1 -1
- package/dist/index367.js +19 -5
- package/dist/index367.js.map +1 -1
- package/dist/index368.js +5 -27
- package/dist/index368.js.map +1 -1
- package/dist/index369.js +27 -48
- package/dist/index369.js.map +1 -1
- package/dist/index370.js +46 -27
- package/dist/index370.js.map +1 -1
- package/dist/index371.js +27 -16
- package/dist/index371.js.map +1 -1
- package/dist/index372.js +16 -41
- package/dist/index372.js.map +1 -1
- package/dist/index373.js +42 -14
- package/dist/index373.js.map +1 -1
- package/dist/index374.js +14 -10
- package/dist/index374.js.map +1 -1
- package/dist/index375.js +9 -51
- package/dist/index375.js.map +1 -1
- package/dist/index376.js +53 -43
- package/dist/index376.js.map +1 -1
- package/dist/index377.js +43 -16
- package/dist/index377.js.map +1 -1
- package/dist/index378.js +15 -4
- package/dist/index378.js.map +1 -1
- package/dist/index379.js +4 -4
- package/dist/index379.js.map +1 -1
- package/dist/index380.js +4 -9
- package/dist/index380.js.map +1 -1
- package/dist/index381.js +9 -340
- package/dist/index381.js.map +1 -1
- package/dist/index382.js +339 -4
- package/dist/index382.js.map +1 -1
- package/dist/index383.js +5 -16
- package/dist/index383.js.map +1 -1
- package/dist/index384.js +16 -111
- package/dist/index384.js.map +1 -1
- package/dist/index385.js +109 -19
- package/dist/index385.js.map +1 -1
- package/dist/index386.js +18 -18
- package/dist/index386.js.map +1 -1
- package/dist/index387.js +21 -5
- package/dist/index387.js.map +1 -1
- package/dist/index388.js +5 -20
- package/dist/index388.js.map +1 -1
- package/dist/index389.js +19 -13
- package/dist/index389.js.map +1 -1
- package/dist/index390.js +13 -84
- package/dist/index390.js.map +1 -1
- package/dist/index391.js +84 -7
- package/dist/index391.js.map +1 -1
- package/dist/index392.js +9 -29
- package/dist/index392.js.map +1 -1
- package/dist/index393.js +28 -9
- package/dist/index393.js.map +1 -1
- package/dist/index394.js +9 -5
- package/dist/index394.js.map +1 -1
- package/dist/index395.js +6 -252
- package/dist/index395.js.map +1 -1
- package/dist/index396.js +250 -10
- package/dist/index396.js.map +1 -1
- package/dist/index397.js +11 -10
- package/dist/index397.js.map +1 -1
- package/dist/index398.js +10 -6
- package/dist/index398.js.map +1 -1
- package/dist/index399.js +6 -22
- package/dist/index399.js.map +1 -1
- package/dist/index400.js +21 -21
- package/dist/index400.js.map +1 -1
- package/dist/index401.js +21 -107
- package/dist/index401.js.map +1 -1
- package/dist/index402.js +109 -15
- package/dist/index402.js.map +1 -1
- package/dist/index403.js +15 -12
- package/dist/index403.js.map +1 -1
- package/dist/index404.js +10 -8
- package/dist/index404.js.map +1 -1
- package/dist/index405.js +8 -242
- package/dist/index405.js.map +1 -1
- package/dist/index406.js +238 -25
- package/dist/index406.js.map +1 -1
- package/dist/index407.js +29 -51
- package/dist/index407.js.map +1 -1
- package/dist/index408.js +51 -10
- package/dist/index408.js.map +1 -1
- package/dist/index409.js +11 -128
- package/dist/index409.js.map +1 -1
- package/dist/index410.js +124 -35
- package/dist/index410.js.map +1 -1
- package/dist/index411.js +36 -23
- package/dist/index411.js.map +1 -1
- package/dist/index412.js +26 -11
- package/dist/index412.js.map +1 -1
- package/dist/index413.js +11 -23
- package/dist/index413.js.map +1 -1
- package/dist/index414.js +19 -13
- package/dist/index414.js.map +1 -1
- package/dist/index415.js +14 -13
- package/dist/index415.js.map +1 -1
- package/dist/index416.js +14 -322
- package/dist/index416.js.map +1 -1
- package/dist/index417.js +323 -61
- package/dist/index417.js.map +1 -1
- package/dist/index418.js +63 -4
- package/dist/index418.js.map +1 -1
- package/dist/index419.js +4 -28
- package/dist/index419.js.map +1 -1
- package/dist/index420.js +25 -468
- package/dist/index420.js.map +1 -1
- package/dist/index421.js +452 -250
- package/dist/index421.js.map +1 -1
- package/dist/index422.js +272 -0
- package/dist/index422.js.map +1 -0
- package/package.json +2 -1
package/dist/index358.js
CHANGED
|
@@ -1,132 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"810"
|
|
11
|
-
];
|
|
12
|
-
function s(e) {
|
|
13
|
-
return e && n.includes(e) ? e : "US";
|
|
14
|
-
}
|
|
15
|
-
function c(e) {
|
|
16
|
-
if (typeof Intl > "u" || Intl.DisplayNames === void 0) return null;
|
|
17
|
-
try {
|
|
18
|
-
let t = Array.isArray(e) ? e : e ? [e] : void 0;
|
|
19
|
-
return new Intl.DisplayNames(t, { type: "region" });
|
|
20
|
-
} catch {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function l(t) {
|
|
25
|
-
let r = c(t), i = c("en");
|
|
26
|
-
return n.map((t) => {
|
|
27
|
-
let n = e(t), a = r?.of(t) ?? i?.of(t) ?? t, o = i?.of(t) ?? a, s = x(t), c = Array.from(new Set([
|
|
28
|
-
a,
|
|
29
|
-
o,
|
|
30
|
-
t.toUpperCase(),
|
|
31
|
-
t.toLowerCase(),
|
|
32
|
-
...s
|
|
33
|
-
].filter(Boolean)));
|
|
34
|
-
return {
|
|
35
|
-
value: t,
|
|
36
|
-
name: a,
|
|
37
|
-
dialCode: n,
|
|
38
|
-
label: `${a} (+${n})`,
|
|
39
|
-
flag: g(t),
|
|
40
|
-
searchableTokens: c,
|
|
41
|
-
normalizedSearchableTokens: c.map((e) => y(e))
|
|
42
|
-
};
|
|
43
|
-
}).sort((e, t) => {
|
|
44
|
-
let n = u(e.value), r = u(t.value);
|
|
45
|
-
return n === r ? e.name.localeCompare(t.name) : n - r;
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function u(t) {
|
|
49
|
-
return t === "US" ? 0 : t === "CA" ? 1 : e(t) === "1" ? 2 : 3;
|
|
50
|
-
}
|
|
51
|
-
function d(e) {
|
|
52
|
-
return e ? Array.isArray(e) ? e.join("\0") : e : i;
|
|
53
|
-
}
|
|
54
|
-
function f(e) {
|
|
55
|
-
if (e !== i) {
|
|
56
|
-
if (e.includes("\0")) {
|
|
57
|
-
let t = e.split("\0").filter(Boolean);
|
|
58
|
-
return t.length === 0 ? void 0 : t.length === 1 ? t[0] ?? void 0 : t;
|
|
59
|
-
}
|
|
60
|
-
return e;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function p(e, t) {
|
|
64
|
-
let n = r.get(t);
|
|
65
|
-
if (n) return n;
|
|
66
|
-
let i = l(e);
|
|
67
|
-
return r.set(t, i), i;
|
|
68
|
-
}
|
|
69
|
-
function m(e) {
|
|
70
|
-
return {
|
|
71
|
-
code: e.value,
|
|
72
|
-
name: e.name,
|
|
73
|
-
dialCode: e.dialCode,
|
|
74
|
-
flag: e.flag
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function h(t) {
|
|
78
|
-
return {
|
|
79
|
-
code: t,
|
|
80
|
-
name: t,
|
|
81
|
-
dialCode: e(t),
|
|
82
|
-
flag: g(t)
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
function g(e) {
|
|
86
|
-
let t = e?.toUpperCase();
|
|
87
|
-
if (!t || t.length !== 2 || /[^A-Z]/.test(t)) return "";
|
|
88
|
-
let n = 127397;
|
|
89
|
-
return String.fromCodePoint(t.charCodeAt(0) + n, t.charCodeAt(1) + n);
|
|
90
|
-
}
|
|
91
|
-
var _ = /[\u0300-\u036f]/g;
|
|
92
|
-
function v(e) {
|
|
93
|
-
return e.normalize("NFD").replace(_, "");
|
|
94
|
-
}
|
|
95
|
-
function y(e) {
|
|
96
|
-
return v(e).toLowerCase();
|
|
97
|
-
}
|
|
98
|
-
function b(e, t) {
|
|
99
|
-
let n = 2 ** 53 - 1;
|
|
100
|
-
for (let r of e) {
|
|
101
|
-
let e = r.indexOf(t);
|
|
102
|
-
e >= 0 && e < n && (n = e);
|
|
103
|
-
}
|
|
104
|
-
return n === 2 ** 53 - 1 ? 2 ** 53 - 1 : n;
|
|
105
|
-
}
|
|
106
|
-
function x(e) {
|
|
107
|
-
switch (e) {
|
|
108
|
-
case "US": return [
|
|
109
|
-
"USA",
|
|
110
|
-
"United States",
|
|
111
|
-
"America",
|
|
112
|
-
"United States of America"
|
|
113
|
-
];
|
|
114
|
-
case "GB": return [
|
|
115
|
-
"UK",
|
|
116
|
-
"United Kingdom",
|
|
117
|
-
"Great Britain",
|
|
118
|
-
"England"
|
|
119
|
-
];
|
|
120
|
-
case "AE": return ["UAE", "United Arab Emirates"];
|
|
121
|
-
case "KR": return ["South Korea", "Korea"];
|
|
122
|
-
case "CN": return ["China", "PRC"];
|
|
123
|
-
case "CD": return ["DRC", "Congo-Kinshasa"];
|
|
124
|
-
case "CG": return ["Congo-Brazzaville"];
|
|
125
|
-
case "BR": return ["Brazil"];
|
|
126
|
-
default: return [];
|
|
127
|
-
}
|
|
1
|
+
import { getCountries as e } from "./index355.js";
|
|
2
|
+
//#region src/components/PhoneNumberInput/countries.ts
|
|
3
|
+
var t = /* @__PURE__ */ new Set([
|
|
4
|
+
"IM",
|
|
5
|
+
"GG",
|
|
6
|
+
"JE"
|
|
7
|
+
]), n = e().filter((e) => !t.has(e));
|
|
8
|
+
function r() {
|
|
9
|
+
return n;
|
|
128
10
|
}
|
|
129
11
|
//#endregion
|
|
130
|
-
export {
|
|
12
|
+
export { r as getCountryList };
|
|
131
13
|
|
|
132
14
|
//# sourceMappingURL=index358.js.map
|
package/dist/index358.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index358.js","names":["CountryCode","getCountryCallingCode","CountryOption","PhoneNumberSelectedCountry","getCountryList","DEFAULT_COUNTRY","COUNTRY_OPTIONS","COUNTRY_OPTIONS_CACHE","Map","DEFAULT_LOCALE_CACHE_KEY","COUNTRY_DIAL_CODES","Array","from","Set","map","code","sort","a","b","length","MAX_DIAL_CODE_LENGTH","reduce","max","dial","Math","COMMON_IDD_PREFIXES","getValidCountry","input","includes","createDisplayNames","locale","Intl","DisplayNames","locales","isArray","undefined","type","buildCountryOptions","displayNames","englishDisplayNames","country","dialCode","localizedName","of","englishName","aliasTokens","getCountryAliases","searchableTokens","toUpperCase","toLowerCase","filter","Boolean","value","name","label","flag","countryCodeToFlagEmoji","normalizedSearchableTokens","token","normalizeSearchValue","priorityA","getCountryPriority","priorityB","localeCompare","getLocaleCacheKey","join","parseLocaleCacheKey","cacheKey","parts","split","getCachedCountryOptions","cached","get","built","set","toSelectedCountry","option","buildFallbackSelectedCountry","upper","test","base","String","fromCodePoint","charCodeAt","DIACRITICS_REGEX","stripDiacritics","normalize","replace","optionMatchIndex","tokens","query","best","Number","MAX_SAFE_INTEGER","index","indexOf"],"sources":["../src/components/PhoneNumberInput/country-options.ts"],"sourcesContent":["import type { CountryCode } from \"libphonenumber-js\"\nimport { getCountryCallingCode } from \"libphonenumber-js\"\n\nimport type { CountryOption, PhoneNumberSelectedCountry } from \"./types\"\nimport { getCountryList } from \"./countries\"\n\n\nexport const DEFAULT_COUNTRY: CountryCode = \"US\"\nconst COUNTRY_OPTIONS = getCountryList()\n\nconst COUNTRY_OPTIONS_CACHE = new Map<string, CountryOption[]>()\nconst DEFAULT_LOCALE_CACHE_KEY = \"__default_locale__\"\nexport const COUNTRY_DIAL_CODES = Array.from(\n new Set(COUNTRY_OPTIONS.map((code) => getCountryCallingCode(code)))\n).sort((a, b) => b.length - a.length)\nexport const MAX_DIAL_CODE_LENGTH = COUNTRY_DIAL_CODES.reduce(\n (max, dial) => Math.max(max, dial.length),\n 0\n)\nexport const COMMON_IDD_PREFIXES = [\"0011\", \"001\", \"011\", \"00\", \"810\"]\n\nexport function getValidCountry(input: CountryCode | undefined) {\n if (!input) {\n return DEFAULT_COUNTRY\n }\n\n return COUNTRY_OPTIONS.includes(input) ? input : DEFAULT_COUNTRY\n}\n\nfunction createDisplayNames(locale?: string | string[]) {\n if (typeof Intl === \"undefined\" || typeof Intl.DisplayNames === \"undefined\") {\n return null\n }\n\n try {\n const locales = Array.isArray(locale) ? locale : locale ? [locale] : undefined\n return new Intl.DisplayNames(locales, { type: \"region\" })\n } catch {\n return null\n }\n}\n\nfunction buildCountryOptions(locale?: string | string[]) {\n const displayNames = createDisplayNames(locale)\n const englishDisplayNames = createDisplayNames(\"en\")\n\n return COUNTRY_OPTIONS\n .map((country) => {\n const dialCode = getCountryCallingCode(country)\n const localizedName = displayNames?.of(country) ?? englishDisplayNames?.of(country) ?? country\n const englishName = englishDisplayNames?.of(country) ?? localizedName\n const aliasTokens = getCountryAliases(country)\n const searchableTokens = Array.from(\n new Set(\n [localizedName, englishName, country.toUpperCase(), country.toLowerCase(), ...aliasTokens].filter(\n Boolean\n )\n )\n ) as string[]\n return {\n value: country,\n name: localizedName,\n dialCode,\n label: `${localizedName} (+${dialCode})`,\n flag: countryCodeToFlagEmoji(country),\n searchableTokens,\n normalizedSearchableTokens: searchableTokens.map((token) => normalizeSearchValue(token)),\n }\n })\n .sort((a, b) => {\n const priorityA = getCountryPriority(a.value)\n const priorityB = getCountryPriority(b.value)\n if (priorityA !== priorityB) {\n return priorityA - priorityB\n }\n return a.name.localeCompare(b.name)\n })\n}\n\nfunction getCountryPriority(code: CountryCode) {\n if (code === \"US\") return 0\n if (code === \"CA\") return 1\n if (getCountryCallingCode(code) === \"1\") return 2\n return 3\n}\n\nexport function getLocaleCacheKey(locale?: string | string[]) {\n if (!locale) {\n return DEFAULT_LOCALE_CACHE_KEY\n }\n if (Array.isArray(locale)) {\n return locale.join(\"\\u0000\")\n }\n return locale\n}\n\nexport function parseLocaleCacheKey(cacheKey: string): string | string[] | undefined {\n if (cacheKey === DEFAULT_LOCALE_CACHE_KEY) {\n return undefined\n }\n\n if (cacheKey.includes(\"\\u0000\")) {\n const parts = cacheKey.split(\"\\u0000\").filter(Boolean)\n if (parts.length === 0) {\n return undefined\n }\n if (parts.length === 1) {\n return parts[0] ?? undefined\n }\n return parts\n }\n\n return cacheKey\n}\n\nexport function getCachedCountryOptions(locale: string | string[] | undefined, cacheKey: string) {\n const cached = COUNTRY_OPTIONS_CACHE.get(cacheKey)\n if (cached) {\n return cached\n }\n const built = buildCountryOptions(locale)\n COUNTRY_OPTIONS_CACHE.set(cacheKey, built)\n return built\n}\n\nexport function toSelectedCountry(option: CountryOption): PhoneNumberSelectedCountry {\n return {\n code: option.value,\n name: option.name,\n dialCode: option.dialCode,\n flag: option.flag,\n }\n}\n\nexport function buildFallbackSelectedCountry(country: CountryCode): PhoneNumberSelectedCountry {\n return {\n code: country,\n name: country,\n dialCode: getCountryCallingCode(country),\n flag: countryCodeToFlagEmoji(country),\n }\n}\n\nfunction countryCodeToFlagEmoji(country: CountryCode) {\n const upper = country?.toUpperCase()\n\n if (!upper || upper.length !== 2 || /[^A-Z]/.test(upper)) {\n return \"\"\n }\n\n const base = 127397\n return String.fromCodePoint(\n upper.charCodeAt(0) + base,\n upper.charCodeAt(1) + base\n )\n}\n\nconst DIACRITICS_REGEX = /[\\u0300-\\u036f]/g\n\nfunction stripDiacritics(value: string) {\n return value.normalize(\"NFD\").replace(DIACRITICS_REGEX, \"\")\n}\n\nexport function normalizeSearchValue(value: string) {\n return stripDiacritics(value).toLowerCase()\n}\n\nexport function optionMatchIndex(tokens: string[], query: string) {\n let best = Number.MAX_SAFE_INTEGER\n for (const token of tokens) {\n const index = token.indexOf(query)\n if (index >= 0 && index < best) {\n best = index\n }\n }\n return best === Number.MAX_SAFE_INTEGER ? Number.MAX_SAFE_INTEGER : best\n}\n\nfunction getCountryAliases(code: CountryCode): string[] {\n switch (code) {\n case \"US\":\n return [\"USA\", \"United States\", \"America\", \"United States of America\"]\n case \"GB\":\n return [\"UK\", \"United Kingdom\", \"Great Britain\", \"England\"]\n case \"AE\":\n return [\"UAE\", \"United Arab Emirates\"]\n case \"KR\":\n return [\"South Korea\", \"Korea\"]\n case \"CN\":\n return [\"China\", \"PRC\"]\n case \"CD\":\n return [\"DRC\", \"Congo-Kinshasa\"]\n case \"CG\":\n return [\"Congo-Brazzaville\"]\n case \"BR\":\n return [\"Brazil\"]\n default:\n return []\n }\n}\n\n"],"mappings":";;AAQA,IAAMM,IAAkBF,EAAe,GAEjCG,oBAAwB,IAAIC,IAA6B,GACzDC,IAA2B,sBACpBC,IAAqBC,MAAMC,KACtC,IAAIC,IAAIP,EAAgBQ,KAAKC,MAASd,EAAsBc,CAAI,CAAC,CAAC,CACpE,CAAC,CAACC,MAAMC,GAAGC,MAAMA,EAAEC,SAASF,EAAEE,MAAM;AACAT,EAAmBW,QACpDC,GAAKC,MAASC,KAAKF,IAAIA,GAAKC,EAAKJ,MAAM,GACxC,CACF;AACA,IAAaM,IAAsB;CAAC;CAAQ;CAAO;CAAO;CAAM;AAAK;AAErE,SAAgBC,EAAgBC,GAAgC;CAK9D,OAJKA,KAIErB,EAAgBsB,SAASD,CAAK,IAAIA,IAAAA;AAC3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ACF;AAEA,IAAMI,IAAmB;AAEzB,SAASC,EAAgBjC,GAAe;CACtC,OAAOA,EAAMkC,UAAU,KAAK,CAAC,CAACC,QAAQH,GAAkB,EAAE;AAC5D;AAEA,SAAgBzB,EAAqBP,GAAe;CAClD,OAAOiC,EAAgBjC,CAAK,CAAC,CAACH,YAAY;AAC5C;AAEA,SAAgBuC,EAAiBC,GAAkBC,GAAe;CAChE,IAAIC;CACJ,KAAK,IAAMjC,KAAS+B,GAAQ;EAC1B,IAAMK,IAAQpC,EAAMqC,QAAQL,CAAK;EACjC,AAAII,KAAS,KAAKA,IAAQH,MACxBA,IAAOG;CAEX;CACA,OAAOH,kCAA6DA;AACtE;AAEA,SAAS7C,EAAkB/B,GAA6B;CACtD,QAAQA,GAAR;EACA,KAAK,MACH,OAAO;GAAC;GAAO;GAAiB;GAAW;EAA0B;EACvE,KAAK,MACH,OAAO;GAAC;GAAM;GAAkB;GAAiB;EAAS;EAC5D,KAAK,MACH,OAAO,CAAC,OAAO,sBAAsB;EACvC,KAAK,MACH,OAAO,CAAC,eAAe,OAAO;EAChC,KAAK,MACH,OAAO,CAAC,SAAS,KAAK;EACxB,KAAK,MACH,OAAO,CAAC,OAAO,gBAAgB;EACjC,KAAK,MACH,OAAO,CAAC,mBAAmB;EAC7B,KAAK,MACH,OAAO,CAAC,QAAQ;EAClB,SACE,OAAO,CAAA;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"index358.js","names":["getCountries","CountryCode","EXCLUDED_COUNTRIES","EXCLUDED_SET","Set","FILTERED_COUNTRIES","filter","code","has","getCountryList"],"sources":["../src/components/PhoneNumberInput/countries.ts"],"sourcesContent":["import { getCountries } from \"libphonenumber-js\"\nimport type { CountryCode } from \"libphonenumber-js\"\n\n\nconst EXCLUDED_COUNTRIES: CountryCode[] = [\"IM\", \"GG\", \"JE\"]\nconst EXCLUDED_SET = new Set(EXCLUDED_COUNTRIES)\n\nconst FILTERED_COUNTRIES = getCountries().filter((code) => !EXCLUDED_SET.has(code))\n\nexport function getCountryList(): CountryCode[] {\n return FILTERED_COUNTRIES\n}\n"],"mappings":";;AAKA,IAAMG,oBAAe,IAAIC,IAAIF;CADc;CAAM;CAAM;AAC1BA,CAAkB,GAEzCG,IAAqBL,EAAa,CAAC,CAACM,QAAQC,MAAS,CAACJ,EAAaK,IAAID,CAAI,CAAC;AAElF,SAAgBE,IAAgC;CAC9C,OAAOJ;AACT"}
|
package/dist/index359.js
CHANGED
|
@@ -1,46 +1,132 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
function
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import { getCountryCallingCode as e } from "./index356.js";
|
|
2
|
+
import { getCountryList as t } from "./index358.js";
|
|
3
|
+
var n = t(), r = /* @__PURE__ */ new Map(), i = "__default_locale__", a = Array.from(new Set(n.map((t) => e(t)))).sort((e, t) => t.length - e.length);
|
|
4
|
+
a.reduce((e, t) => Math.max(e, t.length), 0);
|
|
5
|
+
var o = [
|
|
6
|
+
"0011",
|
|
7
|
+
"001",
|
|
8
|
+
"011",
|
|
9
|
+
"00",
|
|
10
|
+
"810"
|
|
11
|
+
];
|
|
12
|
+
function s(e) {
|
|
13
|
+
return e && n.includes(e) ? e : "US";
|
|
14
|
+
}
|
|
15
|
+
function c(e) {
|
|
16
|
+
if (typeof Intl > "u" || Intl.DisplayNames === void 0) return null;
|
|
17
|
+
try {
|
|
18
|
+
let t = Array.isArray(e) ? e : e ? [e] : void 0;
|
|
19
|
+
return new Intl.DisplayNames(t, { type: "region" });
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function l(t) {
|
|
25
|
+
let r = c(t), i = c("en");
|
|
26
|
+
return n.map((t) => {
|
|
27
|
+
let n = e(t), a = r?.of(t) ?? i?.of(t) ?? t, o = i?.of(t) ?? a, s = x(t), c = Array.from(new Set([
|
|
28
|
+
a,
|
|
29
|
+
o,
|
|
30
|
+
t.toUpperCase(),
|
|
31
|
+
t.toLowerCase(),
|
|
32
|
+
...s
|
|
33
|
+
].filter(Boolean)));
|
|
34
|
+
return {
|
|
35
|
+
value: t,
|
|
36
|
+
name: a,
|
|
37
|
+
dialCode: n,
|
|
38
|
+
label: `${a} (+${n})`,
|
|
39
|
+
flag: g(t),
|
|
40
|
+
searchableTokens: c,
|
|
41
|
+
normalizedSearchableTokens: c.map((e) => y(e))
|
|
42
|
+
};
|
|
43
|
+
}).sort((e, t) => {
|
|
44
|
+
let n = u(e.value), r = u(t.value);
|
|
45
|
+
return n === r ? e.name.localeCompare(t.name) : n - r;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function u(t) {
|
|
49
|
+
return t === "US" ? 0 : t === "CA" ? 1 : e(t) === "1" ? 2 : 3;
|
|
50
|
+
}
|
|
51
|
+
function d(e) {
|
|
52
|
+
return e ? Array.isArray(e) ? e.join("\0") : e : i;
|
|
53
|
+
}
|
|
54
|
+
function f(e) {
|
|
55
|
+
if (e !== i) {
|
|
56
|
+
if (e.includes("\0")) {
|
|
57
|
+
let t = e.split("\0").filter(Boolean);
|
|
58
|
+
return t.length === 0 ? void 0 : t.length === 1 ? t[0] ?? void 0 : t;
|
|
59
|
+
}
|
|
60
|
+
return e;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function p(e, t) {
|
|
64
|
+
let n = r.get(t);
|
|
65
|
+
if (n) return n;
|
|
66
|
+
let i = l(e);
|
|
67
|
+
return r.set(t, i), i;
|
|
68
|
+
}
|
|
69
|
+
function m(e) {
|
|
70
|
+
return {
|
|
71
|
+
code: e.value,
|
|
72
|
+
name: e.name,
|
|
73
|
+
dialCode: e.dialCode,
|
|
74
|
+
flag: e.flag
|
|
22
75
|
};
|
|
23
|
-
|
|
76
|
+
}
|
|
77
|
+
function h(t) {
|
|
24
78
|
return {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
detectedCountry: c
|
|
79
|
+
code: t,
|
|
80
|
+
name: t,
|
|
81
|
+
dialCode: e(t),
|
|
82
|
+
flag: g(t)
|
|
30
83
|
};
|
|
31
84
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
85
|
+
function g(e) {
|
|
86
|
+
let t = e?.toUpperCase();
|
|
87
|
+
if (!t || t.length !== 2 || /[^A-Z]/.test(t)) return "";
|
|
88
|
+
let n = 127397;
|
|
89
|
+
return String.fromCodePoint(t.charCodeAt(0) + n, t.charCodeAt(1) + n);
|
|
34
90
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
91
|
+
var _ = /[\u0300-\u036f]/g;
|
|
92
|
+
function v(e) {
|
|
93
|
+
return e.normalize("NFD").replace(_, "");
|
|
94
|
+
}
|
|
95
|
+
function y(e) {
|
|
96
|
+
return v(e).toLowerCase();
|
|
97
|
+
}
|
|
98
|
+
function b(e, t) {
|
|
99
|
+
let n = 2 ** 53 - 1;
|
|
100
|
+
for (let r of e) {
|
|
101
|
+
let e = r.indexOf(t);
|
|
102
|
+
e >= 0 && e < n && (n = e);
|
|
103
|
+
}
|
|
104
|
+
return n === 2 ** 53 - 1 ? 2 ** 53 - 1 : n;
|
|
105
|
+
}
|
|
106
|
+
function x(e) {
|
|
107
|
+
switch (e) {
|
|
108
|
+
case "US": return [
|
|
109
|
+
"USA",
|
|
110
|
+
"United States",
|
|
111
|
+
"America",
|
|
112
|
+
"United States of America"
|
|
113
|
+
];
|
|
114
|
+
case "GB": return [
|
|
115
|
+
"UK",
|
|
116
|
+
"United Kingdom",
|
|
117
|
+
"Great Britain",
|
|
118
|
+
"England"
|
|
119
|
+
];
|
|
120
|
+
case "AE": return ["UAE", "United Arab Emirates"];
|
|
121
|
+
case "KR": return ["South Korea", "Korea"];
|
|
122
|
+
case "CN": return ["China", "PRC"];
|
|
123
|
+
case "CD": return ["DRC", "Congo-Kinshasa"];
|
|
124
|
+
case "CG": return ["Congo-Brazzaville"];
|
|
125
|
+
case "BR": return ["Brazil"];
|
|
126
|
+
default: return [];
|
|
41
127
|
}
|
|
42
128
|
}
|
|
43
129
|
//#endregion
|
|
44
|
-
export { a as
|
|
130
|
+
export { o as COMMON_IDD_PREFIXES, a as COUNTRY_DIAL_CODES, h as buildFallbackSelectedCountry, p as getCachedCountryOptions, d as getLocaleCacheKey, s as getValidCountry, y as normalizeSearchValue, b as optionMatchIndex, f as parseLocaleCacheKey, m as toSelectedCountry };
|
|
45
131
|
|
|
46
132
|
//# sourceMappingURL=index359.js.map
|
package/dist/index359.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index359.js","names":["CountryCode","AsYouType","validatePhoneNumberLength","LengthIssue","sanitizeDigits","value","replace","DETECTED_COUNTRY_OVERRIDES","Partial","Record","GG","JE","IM","canonicalizeDetectedCountry","candidate","undefined","formatWithAsYouType","baseCountry","international","national","formatted","phoneNumber","detectedCountry","formatter","input","getNumber","country","formatInternational","formatNational","stripPrefix","prefix","startsWith","slice","length","getLengthIssue","result"],"sources":["../src/components/PhoneNumberInput/normalization.ts"],"sourcesContent":["import type { CountryCode } from \"libphonenumber-js\"\nimport { AsYouType, validatePhoneNumberLength } from \"libphonenumber-js\"\n\n\nexport type LengthIssue = \"TOO_LONG\"\n\nexport function sanitizeDigits(value: string) {\n return value.replace(/\\D/g, \"\")\n}\n\nconst DETECTED_COUNTRY_OVERRIDES: Partial<Record<CountryCode, CountryCode>> = {\n GG: \"GB\",\n JE: \"GB\",\n IM: \"GB\",\n}\n\nfunction canonicalizeDetectedCountry(candidate: CountryCode | undefined): CountryCode | undefined {\n if (!candidate) {\n return undefined\n }\n return DETECTED_COUNTRY_OVERRIDES[candidate] ?? candidate\n}\n\nexport function formatWithAsYouType(value: string, baseCountry?: CountryCode) {\n if (value === \"+\") {\n return {\n international: \"+\",\n national: \"\",\n formatted: \"+\",\n phoneNumber: null,\n detectedCountry: undefined,\n }\n }\n\n const formatter = baseCountry ? new AsYouType(baseCountry) : new AsYouType()\n const formatted = formatter.input(value)\n const phoneNumber = formatter.getNumber()\n const detectedCountry = canonicalizeDetectedCountry(\n (phoneNumber?.country ?? formatter.country ?? undefined) as CountryCode | undefined\n )\n const international = phoneNumber?.formatInternational() ?? formatted\n const national = phoneNumber?.formatNational() ?? sanitizeDigits(international)\n\n return {\n international,\n national,\n formatted,\n phoneNumber,\n detectedCountry,\n }\n}\n\nexport function stripPrefix(value: string, prefix: string) {\n return value.startsWith(prefix) ? value.slice(prefix.length) : value\n}\n\nexport function getLengthIssue(value: string, country: CountryCode | undefined): LengthIssue | null {\n if (!country || !value) {\n return null\n }\n\n try {\n const result = validatePhoneNumberLength(value, country)\n return result === \"TOO_LONG\" ? \"TOO_LONG\" : null\n } catch {\n return null\n }\n}\n"],"mappings":";;;AAMA,SAAgBI,EAAeC,GAAe;CAC5C,OAAOA,EAAMC,QAAQ,OAAO,EAAE;AAChC;AAEA,IAAMC,IAAwE;CAC5EG,IAAI;CACJC,IAAI;CACJC,IAAI;AACN;AAEA,SAASC,EAA4BC,GAA6D;CAC3FA,OAGL,OAAOP,EAA2BO,MAAcA;AAClD;AAEA,SAAgBE,EAAoBX,GAAeY,GAA2B;CAC5E,IAAIZ,MAAU,KACZ,OAAO;EACLa,eAAe;EACfC,UAAU;EACVC,WAAW;EACXC,aAAa;EACbC,iBAAiBP,KAAAA;CACnB;CAGF,IAAMQ,IAAYN,IAAc,IAAIhB,EAAUgB,CAAW,IAAI,IAAIhB,EAAU,GACrEmB,IAAYG,EAAUC,MAAMnB,CAAK,GACjCgB,IAAcE,EAAUE,UAAU,GAClCH,IAAkBT,EACrBQ,GAAaK,WAAWH,EAAUG,WAAWX,KAAAA,CAChD,GACMG,IAAgBG,GAAaM,oBAAoB,KAAKP;CAG5D,OAAO;EACLF;EACAC,UAJeE,GAAaO,eAAe,KAAKxB,EAAec,CAAa;EAK5EE;EACAC;EACAC;CACF;AACF;AAEA,SAAgBO,EAAYxB,GAAeyB,GAAgB;CACzD,OAAOzB,EAAM0B,WAAWD,CAAM,IAAIzB,EAAM2B,MAAMF,EAAOG,MAAM,IAAI5B;AACjE;AAEA,SAAgB6B,EAAe7B,GAAeqB,GAAsD;CAClG,IAAI,CAACA,KAAW,CAACrB,GACf,OAAO;CAGT,IAAI;EAEF,OADeH,EAA0BG,GAAOqB,CACzCS,MAAW,aAAa,aAAa;CAC9C,QAAQ;EACN,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"index359.js","names":["CountryCode","getCountryCallingCode","CountryOption","PhoneNumberSelectedCountry","getCountryList","DEFAULT_COUNTRY","COUNTRY_OPTIONS","COUNTRY_OPTIONS_CACHE","Map","DEFAULT_LOCALE_CACHE_KEY","COUNTRY_DIAL_CODES","Array","from","Set","map","code","sort","a","b","length","MAX_DIAL_CODE_LENGTH","reduce","max","dial","Math","COMMON_IDD_PREFIXES","getValidCountry","input","includes","createDisplayNames","locale","Intl","DisplayNames","locales","isArray","undefined","type","buildCountryOptions","displayNames","englishDisplayNames","country","dialCode","localizedName","of","englishName","aliasTokens","getCountryAliases","searchableTokens","toUpperCase","toLowerCase","filter","Boolean","value","name","label","flag","countryCodeToFlagEmoji","normalizedSearchableTokens","token","normalizeSearchValue","priorityA","getCountryPriority","priorityB","localeCompare","getLocaleCacheKey","join","parseLocaleCacheKey","cacheKey","parts","split","getCachedCountryOptions","cached","get","built","set","toSelectedCountry","option","buildFallbackSelectedCountry","upper","test","base","String","fromCodePoint","charCodeAt","DIACRITICS_REGEX","stripDiacritics","normalize","replace","optionMatchIndex","tokens","query","best","Number","MAX_SAFE_INTEGER","index","indexOf"],"sources":["../src/components/PhoneNumberInput/country-options.ts"],"sourcesContent":["import type { CountryCode } from \"libphonenumber-js\"\nimport { getCountryCallingCode } from \"libphonenumber-js\"\n\nimport type { CountryOption, PhoneNumberSelectedCountry } from \"./types\"\nimport { getCountryList } from \"./countries\"\n\n\nexport const DEFAULT_COUNTRY: CountryCode = \"US\"\nconst COUNTRY_OPTIONS = getCountryList()\n\nconst COUNTRY_OPTIONS_CACHE = new Map<string, CountryOption[]>()\nconst DEFAULT_LOCALE_CACHE_KEY = \"__default_locale__\"\nexport const COUNTRY_DIAL_CODES = Array.from(\n new Set(COUNTRY_OPTIONS.map((code) => getCountryCallingCode(code)))\n).sort((a, b) => b.length - a.length)\nexport const MAX_DIAL_CODE_LENGTH = COUNTRY_DIAL_CODES.reduce(\n (max, dial) => Math.max(max, dial.length),\n 0\n)\nexport const COMMON_IDD_PREFIXES = [\"0011\", \"001\", \"011\", \"00\", \"810\"]\n\nexport function getValidCountry(input: CountryCode | undefined) {\n if (!input) {\n return DEFAULT_COUNTRY\n }\n\n return COUNTRY_OPTIONS.includes(input) ? input : DEFAULT_COUNTRY\n}\n\nfunction createDisplayNames(locale?: string | string[]) {\n if (typeof Intl === \"undefined\" || typeof Intl.DisplayNames === \"undefined\") {\n return null\n }\n\n try {\n const locales = Array.isArray(locale) ? locale : locale ? [locale] : undefined\n return new Intl.DisplayNames(locales, { type: \"region\" })\n } catch {\n return null\n }\n}\n\nfunction buildCountryOptions(locale?: string | string[]) {\n const displayNames = createDisplayNames(locale)\n const englishDisplayNames = createDisplayNames(\"en\")\n\n return COUNTRY_OPTIONS\n .map((country) => {\n const dialCode = getCountryCallingCode(country)\n const localizedName = displayNames?.of(country) ?? englishDisplayNames?.of(country) ?? country\n const englishName = englishDisplayNames?.of(country) ?? localizedName\n const aliasTokens = getCountryAliases(country)\n const searchableTokens = Array.from(\n new Set(\n [localizedName, englishName, country.toUpperCase(), country.toLowerCase(), ...aliasTokens].filter(\n Boolean\n )\n )\n ) as string[]\n return {\n value: country,\n name: localizedName,\n dialCode,\n label: `${localizedName} (+${dialCode})`,\n flag: countryCodeToFlagEmoji(country),\n searchableTokens,\n normalizedSearchableTokens: searchableTokens.map((token) => normalizeSearchValue(token)),\n }\n })\n .sort((a, b) => {\n const priorityA = getCountryPriority(a.value)\n const priorityB = getCountryPriority(b.value)\n if (priorityA !== priorityB) {\n return priorityA - priorityB\n }\n return a.name.localeCompare(b.name)\n })\n}\n\nfunction getCountryPriority(code: CountryCode) {\n if (code === \"US\") return 0\n if (code === \"CA\") return 1\n if (getCountryCallingCode(code) === \"1\") return 2\n return 3\n}\n\nexport function getLocaleCacheKey(locale?: string | string[]) {\n if (!locale) {\n return DEFAULT_LOCALE_CACHE_KEY\n }\n if (Array.isArray(locale)) {\n return locale.join(\"\\u0000\")\n }\n return locale\n}\n\nexport function parseLocaleCacheKey(cacheKey: string): string | string[] | undefined {\n if (cacheKey === DEFAULT_LOCALE_CACHE_KEY) {\n return undefined\n }\n\n if (cacheKey.includes(\"\\u0000\")) {\n const parts = cacheKey.split(\"\\u0000\").filter(Boolean)\n if (parts.length === 0) {\n return undefined\n }\n if (parts.length === 1) {\n return parts[0] ?? undefined\n }\n return parts\n }\n\n return cacheKey\n}\n\nexport function getCachedCountryOptions(locale: string | string[] | undefined, cacheKey: string) {\n const cached = COUNTRY_OPTIONS_CACHE.get(cacheKey)\n if (cached) {\n return cached\n }\n const built = buildCountryOptions(locale)\n COUNTRY_OPTIONS_CACHE.set(cacheKey, built)\n return built\n}\n\nexport function toSelectedCountry(option: CountryOption): PhoneNumberSelectedCountry {\n return {\n code: option.value,\n name: option.name,\n dialCode: option.dialCode,\n flag: option.flag,\n }\n}\n\nexport function buildFallbackSelectedCountry(country: CountryCode): PhoneNumberSelectedCountry {\n return {\n code: country,\n name: country,\n dialCode: getCountryCallingCode(country),\n flag: countryCodeToFlagEmoji(country),\n }\n}\n\nfunction countryCodeToFlagEmoji(country: CountryCode) {\n const upper = country?.toUpperCase()\n\n if (!upper || upper.length !== 2 || /[^A-Z]/.test(upper)) {\n return \"\"\n }\n\n const base = 127397\n return String.fromCodePoint(\n upper.charCodeAt(0) + base,\n upper.charCodeAt(1) + base\n )\n}\n\nconst DIACRITICS_REGEX = /[\\u0300-\\u036f]/g\n\nfunction stripDiacritics(value: string) {\n return value.normalize(\"NFD\").replace(DIACRITICS_REGEX, \"\")\n}\n\nexport function normalizeSearchValue(value: string) {\n return stripDiacritics(value).toLowerCase()\n}\n\nexport function optionMatchIndex(tokens: string[], query: string) {\n let best = Number.MAX_SAFE_INTEGER\n for (const token of tokens) {\n const index = token.indexOf(query)\n if (index >= 0 && index < best) {\n best = index\n }\n }\n return best === Number.MAX_SAFE_INTEGER ? Number.MAX_SAFE_INTEGER : best\n}\n\nfunction getCountryAliases(code: CountryCode): string[] {\n switch (code) {\n case \"US\":\n return [\"USA\", \"United States\", \"America\", \"United States of America\"]\n case \"GB\":\n return [\"UK\", \"United Kingdom\", \"Great Britain\", \"England\"]\n case \"AE\":\n return [\"UAE\", \"United Arab Emirates\"]\n case \"KR\":\n return [\"South Korea\", \"Korea\"]\n case \"CN\":\n return [\"China\", \"PRC\"]\n case \"CD\":\n return [\"DRC\", \"Congo-Kinshasa\"]\n case \"CG\":\n return [\"Congo-Brazzaville\"]\n case \"BR\":\n return [\"Brazil\"]\n default:\n return []\n }\n}\n\n"],"mappings":";;AAQA,IAAMM,IAAkBF,EAAe,GAEjCG,oBAAwB,IAAIC,IAA6B,GACzDC,IAA2B,sBACpBC,IAAqBC,MAAMC,KACtC,IAAIC,IAAIP,EAAgBQ,KAAKC,MAASd,EAAsBc,CAAI,CAAC,CAAC,CACpE,CAAC,CAACC,MAAMC,GAAGC,MAAMA,EAAEC,SAASF,EAAEE,MAAM;AACAT,EAAmBW,QACpDC,GAAKC,MAASC,KAAKF,IAAIA,GAAKC,EAAKJ,MAAM,GACxC,CACF;AACA,IAAaM,IAAsB;CAAC;CAAQ;CAAO;CAAO;CAAM;AAAK;AAErE,SAAgBC,EAAgBC,GAAgC;CAK9D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-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return n;
|
|
25
|
-
}
|
|
26
|
-
function a(e, t) {
|
|
27
|
-
let n = t;
|
|
28
|
-
for (; n < e.length && r(e[n] ?? "");) n += 1;
|
|
29
|
-
return n;
|
|
30
|
-
}
|
|
31
|
-
function o(e) {
|
|
32
|
-
let { value: n } = e, r = e.selectionStart ?? n.length, i = e.selectionEnd ?? r, a = r <= 1 && n.startsWith("+"), o = i <= 1 && n.startsWith("+");
|
|
1
|
+
import { validatePhoneNumberLength as e } from "./index353.js";
|
|
2
|
+
import { AsYouType as t } from "./index354.js";
|
|
3
|
+
//#region src/components/PhoneNumberInput/normalization.ts
|
|
4
|
+
function n(e) {
|
|
5
|
+
return e.replace(/\D/g, "");
|
|
6
|
+
}
|
|
7
|
+
var r = {
|
|
8
|
+
GG: "GB",
|
|
9
|
+
JE: "GB",
|
|
10
|
+
IM: "GB"
|
|
11
|
+
};
|
|
12
|
+
function i(e) {
|
|
13
|
+
if (e) return r[e] ?? e;
|
|
14
|
+
}
|
|
15
|
+
function a(e, r) {
|
|
16
|
+
if (e === "+") return {
|
|
17
|
+
international: "+",
|
|
18
|
+
national: "",
|
|
19
|
+
formatted: "+",
|
|
20
|
+
phoneNumber: null,
|
|
21
|
+
detectedCountry: void 0
|
|
22
|
+
};
|
|
23
|
+
let a = r ? new t(r) : new t(), o = a.input(e), s = a.getNumber(), c = i(s?.country ?? a.country ?? void 0), l = s?.formatInternational() ?? o;
|
|
33
24
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
preserveEndIndex: o,
|
|
40
|
-
wasAtStart: r === 0,
|
|
41
|
-
wasAtEnd: i === n.length
|
|
25
|
+
international: l,
|
|
26
|
+
national: s?.formatNational() ?? n(l),
|
|
27
|
+
formatted: o,
|
|
28
|
+
phoneNumber: s,
|
|
29
|
+
detectedCountry: c
|
|
42
30
|
};
|
|
43
31
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (e.wasAtStart) return {
|
|
54
|
-
start: 0,
|
|
55
|
-
end: 0
|
|
56
|
-
};
|
|
32
|
+
function o(e, t) {
|
|
33
|
+
return e.startsWith(t) ? e.slice(t.length) : e;
|
|
34
|
+
}
|
|
35
|
+
function s(t, n) {
|
|
36
|
+
if (!n || !t) return null;
|
|
37
|
+
try {
|
|
38
|
+
return e(t, n) === "TOO_LONG" ? "TOO_LONG" : null;
|
|
39
|
+
} catch {
|
|
40
|
+
return null;
|
|
57
41
|
}
|
|
58
|
-
let r = e.preserveStartIndex ? Math.min(e.selectionStart, t.length) : n(t, e.startDigits), i = e.preserveEndIndex ? Math.min(e.selectionEnd, t.length) : n(t, e.endDigits), a = r, o = i;
|
|
59
|
-
e.wasAtStart && (a = 0), e.wasAtEnd && (o = t.length), e.selectionStart === e.selectionEnd && (a = o);
|
|
60
|
-
let s = Math.min(Math.max(a, 0), t.length), c = Math.min(Math.max(o, 0), t.length);
|
|
61
|
-
return s > c ? {
|
|
62
|
-
start: c,
|
|
63
|
-
end: c
|
|
64
|
-
} : {
|
|
65
|
-
start: s,
|
|
66
|
-
end: c
|
|
67
|
-
};
|
|
68
42
|
}
|
|
69
43
|
//#endregion
|
|
70
|
-
export {
|
|
44
|
+
export { a as formatWithAsYouType, s as getLengthIssue, n as sanitizeDigits, o as stripPrefix };
|
|
71
45
|
|
|
72
46
|
//# sourceMappingURL=index360.js.map
|
package/dist/index360.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index360.js","names":["
|
|
1
|
+
{"version":3,"file":"index360.js","names":["CountryCode","AsYouType","validatePhoneNumberLength","LengthIssue","sanitizeDigits","value","replace","DETECTED_COUNTRY_OVERRIDES","Partial","Record","GG","JE","IM","canonicalizeDetectedCountry","candidate","undefined","formatWithAsYouType","baseCountry","international","national","formatted","phoneNumber","detectedCountry","formatter","input","getNumber","country","formatInternational","formatNational","stripPrefix","prefix","startsWith","slice","length","getLengthIssue","result"],"sources":["../src/components/PhoneNumberInput/normalization.ts"],"sourcesContent":["import type { CountryCode } from \"libphonenumber-js\"\nimport { AsYouType, validatePhoneNumberLength } from \"libphonenumber-js\"\n\n\nexport type LengthIssue = \"TOO_LONG\"\n\nexport function sanitizeDigits(value: string) {\n return value.replace(/\\D/g, \"\")\n}\n\nconst DETECTED_COUNTRY_OVERRIDES: Partial<Record<CountryCode, CountryCode>> = {\n GG: \"GB\",\n JE: \"GB\",\n IM: \"GB\",\n}\n\nfunction canonicalizeDetectedCountry(candidate: CountryCode | undefined): CountryCode | undefined {\n if (!candidate) {\n return undefined\n }\n return DETECTED_COUNTRY_OVERRIDES[candidate] ?? candidate\n}\n\nexport function formatWithAsYouType(value: string, baseCountry?: CountryCode) {\n if (value === \"+\") {\n return {\n international: \"+\",\n national: \"\",\n formatted: \"+\",\n phoneNumber: null,\n detectedCountry: undefined,\n }\n }\n\n const formatter = baseCountry ? new AsYouType(baseCountry) : new AsYouType()\n const formatted = formatter.input(value)\n const phoneNumber = formatter.getNumber()\n const detectedCountry = canonicalizeDetectedCountry(\n (phoneNumber?.country ?? formatter.country ?? undefined) as CountryCode | undefined\n )\n const international = phoneNumber?.formatInternational() ?? formatted\n const national = phoneNumber?.formatNational() ?? sanitizeDigits(international)\n\n return {\n international,\n national,\n formatted,\n phoneNumber,\n detectedCountry,\n }\n}\n\nexport function stripPrefix(value: string, prefix: string) {\n return value.startsWith(prefix) ? value.slice(prefix.length) : value\n}\n\nexport function getLengthIssue(value: string, country: CountryCode | undefined): LengthIssue | null {\n if (!country || !value) {\n return null\n }\n\n try {\n const result = validatePhoneNumberLength(value, country)\n return result === \"TOO_LONG\" ? \"TOO_LONG\" : null\n } catch {\n return null\n }\n}\n"],"mappings":";;;AAMA,SAAgBI,EAAeC,GAAe;CAC5C,OAAOA,EAAMC,QAAQ,OAAO,EAAE;AAChC;AAEA,IAAMC,IAAwE;CAC5EG,IAAI;CACJC,IAAI;CACJC,IAAI;AACN;AAEA,SAASC,EAA4BC,GAA6D;CAC3FA,OAGL,OAAOP,EAA2BO,MAAcA;AAClD;AAEA,SAAgBE,EAAoBX,GAAeY,GAA2B;CAC5E,IAAIZ,MAAU,KACZ,OAAO;EACLa,eAAe;EACfC,UAAU;EACVC,WAAW;EACXC,aAAa;EACbC,iBAAiBP,KAAAA;CACnB;CAGF,IAAMQ,IAAYN,IAAc,IAAIhB,EAAUgB,CAAW,IAAI,IAAIhB,EAAU,GACrEmB,IAAYG,EAAUC,MAAMnB,CAAK,GACjCgB,IAAcE,EAAUE,UAAU,GAClCH,IAAkBT,EACrBQ,GAAaK,WAAWH,EAAUG,WAAWX,KAAAA,CAChD,GACMG,IAAgBG,GAAaM,oBAAoB,KAAKP;CAG5D,OAAO;EACLF;EACAC,UAJeE,GAAaO,eAAe,KAAKxB,EAAec,CAAa;EAK5EE;EACAC;EACAC;CACF;AACF;AAEA,SAAgBO,EAAYxB,GAAeyB,GAAgB;CACzD,OAAOzB,EAAM0B,WAAWD,CAAM,IAAIzB,EAAM2B,MAAMF,EAAOG,MAAM,IAAI5B;AACjE;AAEA,SAAgB6B,EAAe7B,GAAeqB,GAAsD;CAClG,IAAI,CAACA,KAAW,CAACrB,GACf,OAAO;CAGT,IAAI;EAEF,OADeH,EAA0BG,GAAOqB,CACzCS,MAAW,aAAa,aAAa;CAC9C,QAAQ;EACN,OAAO;CACT;AACF"}
|