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 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 |