2.0.7 ā€¢ Published 2 days ago

@adamlui/geolocate v2.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 days ago

geolocate

Fetch IP geolocation data from the CLI.

āš” Installation

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

šŸ’» Command line usage

The basic global command is:

$ geolocate [ip1] [ip2] [...]

Sample output:

šŸ“ Note: If no IPv4 address is passed, your own one will be used.

Command line options

Boolean options:
 -q, --quiet                 Suppress all logging except errors.

Info commands:
 -h, --help                  Display help screen.
 -v, --version               Show version number.

šŸ”Œ Importing the API

You can also import geolocate into your app to use its main API method.

Node.js

ECMAScript*:

import * as geo from '@adamlui/geolocate';

CommonJS:

const geo = require('@adamlui/geolocate');
*Node.js version 14 or higher required

Web

<> HTML script tag:

<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.7/dist/geolocate.min.js"></script>

ES6:

(async () => {
    await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.7/dist/geolocate.min.js');
    // Your code here...
})();

Greasemonkey

...
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.7/dist/geolocate.min.js
// ==/UserScript==

// Your code here...

šŸ“ Note: To always import the latest version (not recommended in production!) remove the @2.0.7 version tag from the jsDelivr URL: https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js

šŸ“‹ API usage

locate([ips, options])

šŸ’” 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):

NameTypeDescriptionDefault Value
verboseBooleanShow logging in console/terminal.true

šŸ›ļø MIT License

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.

šŸ› ļø Related utilities

generate-ip

Randomly generate, format, and validate IPv4 + IPv6 + MAC addresses. Install / Readme / API usage / CLI usage / Discuss

šŸ”’ generate-pw

Randomly generate, strengthen, and validate cryptographically-secure passwords. Install / Readme / API usage / CLI usage / Discuss

More JavaScript utilities / Discuss / Back to top ā†‘

2.0.7

2 days ago

2.0.6

6 days ago

2.0.5

7 days ago

2.0.4

12 days ago

2.0.3

13 days ago

2.0.2

14 days ago

2.0.1

21 days ago

2.0.0

22 days ago

1.0.4

23 days ago

1.0.3

25 days ago

1.0.2

30 days ago

1.0.1

1 month ago

1.0.0

1 month ago