As a global utility:
$ npm install -g @adamlui/geolocate
As a dev dependency, from your project root:
$ npm install -D @adamlui/geolocate
As a runtime dependency, from your project root:
$ npm install @adamlui/geolocate
The basic global command is:
$ geolocate [ip1] [ip2] [...]
Sample output:
📝 Note: If no IPv4 address is passed, your own one will be used.
Boolean options:
-q, --quiet Suppress all logging except errors.
Info commands:
-h, --help Display help screen.
-v, --version Show version number.
You can also import geolocate into your app to use its main API method.
import geo from '@adamlui/geolocate';
const geo = require('@adamlui/geolocate');
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.10/dist/geolocate.min.js"></script>
(async () => {
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.10/dist/geolocate.min.js');
// Your code here...
})();
...
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.10/dist/geolocate.min.js
// ==/UserScript==
// Your code here...
📝 Note: To always import the latest version (not recommended in production!) remove the @2.0.10
version tag from the jsDelivr URL: https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js
💡 Asynchronous method to fetch geolocation data for each ip
passed in an array, returned as an array of data objects.
Example:
const geo = require('@adamlui/geolocate');
// Using await syntax
(async () => {
const location = await geo.locate('8.8.8.8');
console.log(location);
})();
// Using .then() syntax
geo.locate('8.8.8.8').then(location => {
console.log(location);
});
/* outputs:
[{
ip: '8.8.8.8',
country: 'United States',
countryCode: 'US',
region: 'VA',
regionName: 'Virginia',
city: 'Ashburn',
zip: '20149',
lat: 39.03,
lon: -77.5,
timezone: 'America/New_York',
isp: 'Google LLC'
}]
*/
📝 Note: If no IPv4 address is passed, your own one will be used.
Available options (passed as object properties):
Name | Type | Description | Default Value |
---|---|---|---|
verbose |
Boolean | Show logging in console/terminal. | true |
Copyright © 2024 Adam Lui.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Randomly generate, format, and validate IPv4 + IPv6 + MAC addresses.
Install / Readme / API usage / CLI usage / Discuss
Randomly generate, strengthen, and validate cryptographically-secure passwords.
Install / Readme / API usage / CLI usage / Discuss