lite-phone-input 0.3.0 → 0.5.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/README.md +30 -0
- package/dist/core/index.cjs +27 -2
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +3 -1
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.js +27 -2
- package/dist/core/index.js.map +1 -1
- package/dist/preact/index.cjs +54 -10
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.cts +1 -0
- package/dist/preact/index.d.ts +1 -0
- package/dist/preact/index.js +54 -10
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +54 -10
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +54 -10
- package/dist/react/index.js.map +1 -1
- package/dist/vanilla/index.cjs +52 -10
- package/dist/vanilla/index.cjs.map +1 -1
- package/dist/vanilla/index.d.cts +3 -0
- package/dist/vanilla/index.d.ts +3 -0
- package/dist/vanilla/index.global.js +52 -10
- package/dist/vanilla/index.global.js.map +1 -1
- package/dist/vanilla/index.js +52 -10
- package/dist/vanilla/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,6 +97,36 @@ Same API as React. Uses `preact/hooks` directly — no `preact/compat` required.
|
|
|
97
97
|
</script>
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
+
## Geo IP Lookup
|
|
101
|
+
|
|
102
|
+
Auto-detect the user's country at mount time using any geo-IP service. The lookup runs once, and the result is ignored if the user has already interacted with the widget.
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
const phone = PhoneInput.mount(document.getElementById('phone'), {
|
|
106
|
+
defaultCountry: 'US',
|
|
107
|
+
geoIpLookup: (callback) => {
|
|
108
|
+
// Cloudflare (free, no API key)
|
|
109
|
+
fetch('/cdn-cgi/trace')
|
|
110
|
+
.then(res => res.text())
|
|
111
|
+
.then(text => {
|
|
112
|
+
const match = text.match(/loc=(\w+)/);
|
|
113
|
+
callback(match ? match[1] : null);
|
|
114
|
+
})
|
|
115
|
+
.catch(() => callback(null));
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
// Alternative: ipapi.co
|
|
122
|
+
geoIpLookup: (callback) => {
|
|
123
|
+
fetch('https://ipapi.co/json/')
|
|
124
|
+
.then(res => res.json())
|
|
125
|
+
.then(data => callback(data.country_code))
|
|
126
|
+
.catch(() => callback(null));
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
100
130
|
## Documentation
|
|
101
131
|
|
|
102
132
|
| Guide | Description |
|
package/dist/core/index.cjs
CHANGED
|
@@ -2842,7 +2842,27 @@ var phone_countries_default = [
|
|
|
2842
2842
|
// src/core/format.ts
|
|
2843
2843
|
var TRAILING_SEP = /[\s\-]+$/;
|
|
2844
2844
|
var FALLBACK_GROUP = /(.{4})(?=.)/g;
|
|
2845
|
-
var
|
|
2845
|
+
var NUMERAL_BASES = [
|
|
2846
|
+
1632,
|
|
2847
|
+
// Arabic-Indic ٠-٩
|
|
2848
|
+
1776,
|
|
2849
|
+
// Persian ۰-۹
|
|
2850
|
+
2406,
|
|
2851
|
+
// Devanagari ०-९
|
|
2852
|
+
2534,
|
|
2853
|
+
// Bengali ০-৯
|
|
2854
|
+
3664,
|
|
2855
|
+
// Thai ๐-๙
|
|
2856
|
+
3792,
|
|
2857
|
+
// Lao ໐-໙
|
|
2858
|
+
4160,
|
|
2859
|
+
// Myanmar ၀-၉
|
|
2860
|
+
6112,
|
|
2861
|
+
// Khmer ០-៩
|
|
2862
|
+
65296
|
|
2863
|
+
// Fullwidth 0-9
|
|
2864
|
+
];
|
|
2865
|
+
var NON_ASCII_DIGITS = /[\u0660-\u0669\u06F0-\u06F9\u0966-\u096F\u09E6-\u09EF\u0E50-\u0E59\u0ED0-\u0ED9\u1040-\u1049\u17E0-\u17E9\uFF10-\uFF19]/g;
|
|
2846
2866
|
function isRelevantChar(ch) {
|
|
2847
2867
|
const c = ch.charCodeAt(0);
|
|
2848
2868
|
return c >= 48 && c <= 57 || c === 43;
|
|
@@ -2892,7 +2912,12 @@ function extractDigits(value) {
|
|
|
2892
2912
|
function normalizeNumerals(value) {
|
|
2893
2913
|
return value.replace(NON_ASCII_DIGITS, (c) => {
|
|
2894
2914
|
const code = c.charCodeAt(0);
|
|
2895
|
-
|
|
2915
|
+
for (const base of NUMERAL_BASES) {
|
|
2916
|
+
if (code >= base && code <= base + 9) {
|
|
2917
|
+
return String(code - base);
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
return c;
|
|
2896
2921
|
});
|
|
2897
2922
|
}
|
|
2898
2923
|
|