lite-phone-input 0.2.0 → 0.4.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/data/phone-countries.json +595 -245
- package/dist/core/index.cjs +598 -246
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +8 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.js +598 -246
- package/dist/core/index.js.map +1 -1
- package/dist/preact/index.cjs +678 -265
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.cts +4 -0
- package/dist/preact/index.d.ts +4 -0
- package/dist/preact/index.js +678 -265
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +678 -265
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +4 -0
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.js +678 -265
- package/dist/react/index.js.map +1 -1
- package/dist/vanilla/index.cjs +673 -265
- package/dist/vanilla/index.cjs.map +1 -1
- package/dist/vanilla/index.d.cts +11 -0
- package/dist/vanilla/index.d.ts +11 -0
- package/dist/vanilla/index.global.js +673 -265
- package/dist/vanilla/index.global.js.map +1 -1
- package/dist/vanilla/index.js +673 -265
- 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 |
|