@adamlui/geolocate 1.0.1 → 1.0.2
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 +47 -19
- package/dist/cli.min.js +4 -2
- package/dist/geolocate.min.js +1 -1
- package/docs/README.md +222 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
### Fetch IP geolocation data from the CLI.
|
|
4
4
|
|
|
5
|
-
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-1.0.
|
|
5
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-1.0.2"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.0.2-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
6
6
|
<a href="https://www.npmjs.com/package/@adamlui/geolocate?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/%40adamlui%2Fgeolocate?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
|
|
7
|
-
<a href="https://github.com/adamlui/js-utils/blob/geolocate-1.0.
|
|
7
|
+
<a href="https://github.com/adamlui/js-utils/blob/geolocate-1.0.2/geolocate/dist/geolocate.min.js"><img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/geolocate/dist/geolocate.min.js?branch=geolocate-1.0.2&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
8
8
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:geolocate/src/geolocate.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Ageolocate%2Fsrc%2Fgeolocate.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
|
|
9
9
|
|
|
10
10
|
<br>
|
|
@@ -40,7 +40,7 @@ $ npm install @adamlui/geolocate
|
|
|
40
40
|
The basic **global command** is:
|
|
41
41
|
|
|
42
42
|
```
|
|
43
|
-
$ geolocate
|
|
43
|
+
$ geolocate [ip]
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
Sample output:
|
|
@@ -70,7 +70,7 @@ You can also import **geolocate** into your app to use its API methods.
|
|
|
70
70
|
|
|
71
71
|
### <img height=18 src="https://i.imgur.com/JIeAdsr.png"> Node.js
|
|
72
72
|
|
|
73
|
-
####
|
|
73
|
+
#### ECMAScript*:
|
|
74
74
|
|
|
75
75
|
```js
|
|
76
76
|
import * as geo from '@adamlui/geolocate';
|
|
@@ -89,14 +89,14 @@ const geo = require('@adamlui/geolocate');
|
|
|
89
89
|
#### <> HTML script tag:
|
|
90
90
|
|
|
91
91
|
```html
|
|
92
|
-
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@1.0.
|
|
92
|
+
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@1.0.2/dist/geolocate.min.js"></script>
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
#### ES6:
|
|
96
96
|
|
|
97
97
|
```js
|
|
98
98
|
(async () => {
|
|
99
|
-
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@1.0.
|
|
99
|
+
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@1.0.2/dist/geolocate.min.js');
|
|
100
100
|
// Your code here...
|
|
101
101
|
})();
|
|
102
102
|
```
|
|
@@ -105,7 +105,7 @@ const geo = require('@adamlui/geolocate');
|
|
|
105
105
|
|
|
106
106
|
```js
|
|
107
107
|
...
|
|
108
|
-
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@1.0.
|
|
108
|
+
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@1.0.2/dist/geolocate.min.js
|
|
109
109
|
// ==/UserScript==
|
|
110
110
|
|
|
111
111
|
// Your code here...
|
|
@@ -113,7 +113,7 @@ const geo = require('@adamlui/geolocate');
|
|
|
113
113
|
|
|
114
114
|
<br>
|
|
115
115
|
|
|
116
|
-
📝 **Note:** To always import the latest version (not recommended in production!) remove the `@1.0.
|
|
116
|
+
📝 **Note:** To always import the latest version (not recommended in production!) remove the `@1.0.2` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
|
|
117
117
|
|
|
118
118
|
<br>
|
|
119
119
|
|
|
@@ -123,17 +123,17 @@ const geo = require('@adamlui/geolocate');
|
|
|
123
123
|
|
|
124
124
|
### `locate([ip])`
|
|
125
125
|
|
|
126
|
-
Asynchronous method to fetch geolocation data for the `ip` passed, returned as an object
|
|
127
|
-
|
|
128
|
-
**💡 Note:** If no `ip` is supplied, your own one will be used.
|
|
126
|
+
Asynchronous method to fetch geolocation data for the `ip` passed, returned as an object:
|
|
129
127
|
|
|
130
128
|
```js
|
|
131
129
|
// Using await syntax
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
(async () => {
|
|
131
|
+
const location = await geo.locate('8.8.8.8');
|
|
132
|
+
console.log(location);
|
|
133
|
+
})();
|
|
134
134
|
|
|
135
135
|
// Using .then() syntax
|
|
136
|
-
geo.locate('
|
|
136
|
+
geo.locate('8.8.8.8').then(location => {
|
|
137
137
|
console.log(location);
|
|
138
138
|
});
|
|
139
139
|
|
|
@@ -154,6 +154,8 @@ geo.locate('192.12.85.186').then(location => {
|
|
|
154
154
|
*/
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
+
**💡 Note:** If no `ip` is supplied, your own one will be used.
|
|
158
|
+
|
|
157
159
|
#
|
|
158
160
|
|
|
159
161
|
### `getOwnIP()`
|
|
@@ -162,8 +164,10 @@ Asynchronous method to fetch/return your own IP as a string:
|
|
|
162
164
|
|
|
163
165
|
```js
|
|
164
166
|
// Using await syntax
|
|
165
|
-
|
|
166
|
-
|
|
167
|
+
(async () => {
|
|
168
|
+
const ip = await geo.getOwnIP();
|
|
169
|
+
console.log(ip); // outputs your IP
|
|
170
|
+
})();
|
|
167
171
|
|
|
168
172
|
// Using .then() syntax
|
|
169
173
|
geo.getOwnIP().then(ip => {
|
|
@@ -177,7 +181,7 @@ geo.getOwnIP().then(ip => {
|
|
|
177
181
|
|
|
178
182
|
## 🏛️ MIT License
|
|
179
183
|
|
|
180
|
-
**Copyright © 2023 [Adam Lui](https://github.com/adamlui)
|
|
184
|
+
**Copyright © 2023 [Adam Lui](https://github.com/adamlui).**
|
|
181
185
|
|
|
182
186
|
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:
|
|
183
187
|
|
|
@@ -189,6 +193,30 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
189
193
|
|
|
190
194
|
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
191
195
|
|
|
192
|
-
|
|
193
|
-
|
|
196
|
+
## 🛠️ Related utilities
|
|
197
|
+
|
|
198
|
+
### <img height=21px src="https://i.imgur.com/kvf7fXm.png"> [generate-ip](https://js-utils.com/generate-ip) <a href="https://github.com/toolleeo/cli-apps#networking"><img height=18 src="https://awesome.re/mentioned-badge.svg"></a>
|
|
199
|
+
|
|
200
|
+
> Randomly generate, format, and validate IPv4/IPv6 addresses.
|
|
201
|
+
<br>[Install](https://github.com/adamlui/js-utils/tree/main/generate-ip#-installation) /
|
|
202
|
+
[Readme](https://github.com/adamlui/js-utils/tree/main/generate-ip#readme) /
|
|
203
|
+
[API usage](https://github.com/adamlui/js-utils/tree/main/generate-ip#-api-usage) /
|
|
204
|
+
[CLI usage](https://github.com/adamlui/js-utils/tree/main/generate-ip#-command-line-usage) /
|
|
205
|
+
[Discuss](https://js-utils.com/discussions)
|
|
206
|
+
|
|
207
|
+
### [🔒 generate-pw](../generate-pw)
|
|
208
|
+
|
|
209
|
+
> Randomly generate, strengthen, and validate cryptographically-secure passwords.
|
|
210
|
+
<br>[Install](https://github.com/adamlui/js-utils/tree/main/generate-pw#-installation) /
|
|
211
|
+
[Readme](https://github.com/adamlui/js-utils/tree/main/generate-pw#readme) /
|
|
212
|
+
[API usage](https://github.com/adamlui/js-utils/tree/main/generate-pw#-api-usage) /
|
|
213
|
+
[CLI usage](https://github.com/adamlui/js-utils/tree/main/generate-pw#-command-line-usage) /
|
|
214
|
+
[Discuss](https://js-utils.com/discussions)
|
|
215
|
+
|
|
216
|
+
<br>
|
|
217
|
+
|
|
218
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
219
|
+
|
|
220
|
+
<picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/white/icon32x27.png"><img height=13 src="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/dark-gray/icon32x27.png"></picture> <a href="https://js-utils.com">**More JavaScript utilities**</a> /
|
|
221
|
+
<a href="https://js-utils.com/discussions">Discuss</a> /
|
|
194
222
|
<a href="#-geolocate">Back to top ↑</a>
|
package/dist/cli.min.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
(async()=>{const e=require(__dirname.match(/src/)?"./geolocate":"./geolocate.min"),o=require("generate-ip")["ipv4"],s=require("child_process")["execSync"],r="[1;33m",t={},n={flags:{quietMode:/^--?q(?:uiet)?(?:-?mode)?$/},infoCmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/}};if(process.argv.forEach(o=>{var e,s;o.startsWith("-")&&(e=Object.keys(n.flags).find(e=>n.flags[e].test(o)),s=Object.keys(n.infoCmds).find(e=>n.infoCmds[e].test(o)),e?t[e]=!0:s||(console.error(`
|
|
3
3
|
[1;91mERROR: Arg [${o}] not recognized.[0m`),console.info(`
|
|
4
|
-
${r}Valid arguments are below.[0m`),f(["flags","infoCmds"]),process.exit(1)))}),process.argv.some(e=>n.infoCmds.help.test(e)))f();else if(process.argv.some(e=>n.infoCmds.version.test(e)))console.info("v"+require("./package.json").version);else{var i,a=process.argv.slice(2),l=[];for(let e=0;e<a.length;e++)a[e].startsWith("-")||(o.validate(a[e],{verbose:!1})?l.push(a[e]):(i=0==e?"st":1==e?"nd":"th",console.error(`ERROR: ${e+1+i} arg '${a[e]}' is not a valid IPv4 address.`),
|
|
5
|
-
${r}geolocate [ip] [options|commands][0m`],flags:["\nBoolean options:"," -q, --quiet Suppress all logging except errors."],infoCmds:["\nInfo commands:"," -h, --help Display help screen."," -v, --version Show version number."]};e.forEach(e=>{o[e]?.forEach(e=>{{const r=process.stdout.columns||80,t=[],o=e.match(/\S+|\s+/g);let s="";o.forEach(e=>{var o=r-(0===t.length?0:29);s.length+e.length>o&&(t.push(0===t.length?s:s.trimStart()),s=""),s+=e}),t.push(0===t.length?s:s.trimStart()),t.forEach((e,o)=>console.info(0===o?e:" ".repeat(29)+e))}})})}function
|
|
4
|
+
${r}Valid arguments are below.[0m`),f(["flags","infoCmds"]),m(),process.exit(1)))}),process.argv.some(e=>n.infoCmds.help.test(e)))f();else if(process.argv.some(e=>n.infoCmds.version.test(e)))console.info("v"+require("./package.json").version);else{var i,a=process.argv.slice(2),l=[];for(let e=0;e<a.length;e++)a[e].startsWith("-")||(o.validate(a[e],{verbose:!1})?l.push(a[e]):(i=0==e?"st":1==e?"nd":"th",console.error(`ERROR: ${e+1+i} arg '${a[e]}' is not a valid IPv4 address.`),m(),process.exit(1)));0==l.length&&l.push(await e.getOwnIP()),l.forEach(e=>g(`Fetching geolocation data for ${e}...`));var c=[];for(const h of l)c.push(await e.locate(h));1==c.length&&g(c[0]),g("Copying to clipboard..."),p=(p=JSON.stringify(c)).replace(/\s+$/,"").replace(/"/g,'""'),"darwin"===process.platform?s(`printf "${p}" | pbcopy`):"linux"===process.platform?s(`printf "${p}" | xclip -selection clipboard`):"win32"===process.platform&&s(`Set-Clipboard -Value "${p}"`,{shell:"powershell"})}var p;function f(e=["cmdFormat","flags","infoCmds"]){const o={cmdFormat:[`
|
|
5
|
+
${r}geolocate [ip] [options|commands][0m`],flags:["\nBoolean options:"," -q, --quiet Suppress all logging except errors."],infoCmds:["\nInfo commands:"," -h, --help Display help screen."," -v, --version Show version number."]};e.forEach(e=>{o[e]?.forEach(e=>{{const r=process.stdout.columns||80,t=[],o=e.match(/\S+|\s+/g);let s="";o.forEach(e=>{var o=r-(0===t.length?0:29);s.length+e.length>o&&(t.push(0===t.length?s:s.trimStart()),s=""),s+=e}),t.push(0===t.length?s:s.trimStart()),t.forEach((e,o)=>console.info(0===o?e:" ".repeat(29)+e))}})})}function m(){console.info(`
|
|
6
|
+
${r}For more help, type 'minify-js --help' or visit
|
|
7
|
+
https://github.com/adamlui/js-utils/tree/main/geolocate#-command-line-usage[0m`)}function g(e){t.quietMode||console.info(e)}})();
|
package/dist/geolocate.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
async function e(t){let
|
|
1
|
+
async function e(t){let o;try{o=require("generate-ip").ipv4.validate}catch(e){await import("https://cdn.jsdelivr.net/npm/generate-ip/dist/generate-ip.min.js"),o=ipv4.validate}if(o&&!o(t,{verbose:!1}))console.error("geolocate() » ERROR: Invalid IP address passed."),console.info("geolocate() » For more help, please visit https://github.com/adamlui/js-utils/tree/main/geolocate#locateip");else try{let e;if("undefined"!=typeof fetch)e=await fetch("http://ip-api.com/json/"+t);else{if("function"!=typeof require)return console.error("geolocate() » ERROR: Environment not supported.");e=await require("axios").get("http://ip-api.com/json/"+t)}const{status:r,org:i,as:c,query:n,...a}=await e.json();return{ip:t,...a}}catch(e){console.error("geolocate() »",e)}}async function t(){return fetch("https://ifconfig.me/ip").then(e=>e.text()).catch(()=>fetch("http://ip-api.com/json/").then(e=>e.json()).then(e=>e.query)).catch(async()=>{try{var e=require("child_process")["exec"],t=require("util")["promisify"],{stdout:o,stderr:r}=await t(e)("curl -s ifconfig.me");return r?console.error("getOwnIP() »",r):o.trim()}catch(e){console.error("getOwnIP() »",e)}})}const o={geolocate:e,locate:e,getOwnIP:t};try{module.exports={...o}}catch(e){}try{window.geo={...o}}catch(e){}
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.com/adamlui/js-utils/blob/main/geolocate/media/images/icons/wire-globe/white/icon32.png"><img height=28 src="https://github.com/adamlui/js-utils/blob/main/geolocate/media/images/icons/wire-globe/black/icon32.png"></picture> geolocate
|
|
2
|
+
|
|
3
|
+
### Fetch IP geolocation data from the CLI.
|
|
4
|
+
|
|
5
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-1.0.2"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.0.2-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
6
|
+
<a href="https://www.npmjs.com/package/@adamlui/geolocate?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/%40adamlui%2Fgeolocate?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
|
|
7
|
+
<a href="https://github.com/adamlui/js-utils/blob/geolocate-1.0.2/geolocate/dist/geolocate.min.js"><img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/geolocate/dist/geolocate.min.js?branch=geolocate-1.0.2&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
8
|
+
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:geolocate/src/geolocate.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Ageolocate%2Fsrc%2Fgeolocate.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
|
|
9
|
+
|
|
10
|
+
<br>
|
|
11
|
+
|
|
12
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
13
|
+
|
|
14
|
+
## ⚡ Installation
|
|
15
|
+
|
|
16
|
+
As a **global utility**:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
$ npm install -g @adamlui/geolocate
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
As a **dev dependency**, from your project root:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
$ npm install -D @adamlui/geolocate
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
As a **runtime dependency**, from your project root:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
$ npm install @adamlui/geolocate
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
<br>
|
|
35
|
+
|
|
36
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
37
|
+
|
|
38
|
+
## 💻 Command line usage
|
|
39
|
+
|
|
40
|
+
The basic **global command** is:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
$ geolocate [ip]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Sample output:
|
|
47
|
+
|
|
48
|
+
<img src="https://github.com/adamlui/js-utils/blob/main/geolocate/media/images/screenshots/cli-geolocate-8.8.8.8.jpg">
|
|
49
|
+
|
|
50
|
+
**💡 Note:** If no IPv4 address is passed, your own one will be used.
|
|
51
|
+
|
|
52
|
+
### Command line options
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
Boolean options:
|
|
56
|
+
-q, --quiet Suppress all logging except errors.
|
|
57
|
+
|
|
58
|
+
Info commands:
|
|
59
|
+
-h, --help Display help screen.
|
|
60
|
+
-v, --version Show version number.
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
<br>
|
|
64
|
+
|
|
65
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
66
|
+
|
|
67
|
+
## 🔌 Importing the API
|
|
68
|
+
|
|
69
|
+
You can also import **geolocate** into your app to use its API methods.
|
|
70
|
+
|
|
71
|
+
### <img height=18 src="https://i.imgur.com/JIeAdsr.png"> Node.js
|
|
72
|
+
|
|
73
|
+
#### ECMAScript*:
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
import * as geo from '@adamlui/geolocate';
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
#### CommonJS:
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
const geo = require('@adamlui/geolocate');
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
###### _*Node.js version 14 or higher required_
|
|
86
|
+
|
|
87
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://i.imgur.com/JSEb19A.png"><img width=16 src="https://i.imgur.com/5VPxf9y.png"></picture> Web
|
|
88
|
+
|
|
89
|
+
#### <> HTML script tag:
|
|
90
|
+
|
|
91
|
+
```html
|
|
92
|
+
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@1.0.2/dist/geolocate.min.js"></script>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### ES6:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
(async () => {
|
|
99
|
+
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@1.0.2/dist/geolocate.min.js');
|
|
100
|
+
// Your code here...
|
|
101
|
+
})();
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### <img height=17 src="https://raw.githubusercontent.com/KudoAI/chatgpt.js/main/starters/media/images/icons/tampermonkey-icon28.png"><img height=17.5 src="https://raw.githubusercontent.com/KudoAI/chatgpt.js/main/starters/media/images/icons/violentmonkey-icon100.png"> Greasemonkey
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
...
|
|
108
|
+
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@1.0.2/dist/geolocate.min.js
|
|
109
|
+
// ==/UserScript==
|
|
110
|
+
|
|
111
|
+
// Your code here...
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
<br>
|
|
115
|
+
|
|
116
|
+
📝 **Note:** To always import the latest version (not recommended in production!) remove the `@1.0.2` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
|
|
117
|
+
|
|
118
|
+
<br>
|
|
119
|
+
|
|
120
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
121
|
+
|
|
122
|
+
## 📋 API usage
|
|
123
|
+
|
|
124
|
+
### `locate([ip])`
|
|
125
|
+
|
|
126
|
+
Asynchronous method to fetch geolocation data for the `ip` passed, returned as an object:
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
// Using await syntax
|
|
130
|
+
(async () => {
|
|
131
|
+
const location = await geo.locate('8.8.8.8');
|
|
132
|
+
console.log(location);
|
|
133
|
+
})();
|
|
134
|
+
|
|
135
|
+
// Using .then() syntax
|
|
136
|
+
geo.locate('8.8.8.8').then(location => {
|
|
137
|
+
console.log(location);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
/* outputs:
|
|
141
|
+
{
|
|
142
|
+
ip: '8.8.8.8',
|
|
143
|
+
country: 'United States',
|
|
144
|
+
countryCode: 'US',
|
|
145
|
+
region: 'VA',
|
|
146
|
+
regionName: 'Virginia',
|
|
147
|
+
city: 'Ashburn',
|
|
148
|
+
zip: '20149',
|
|
149
|
+
lat: 39.03,
|
|
150
|
+
lon: -77.5,
|
|
151
|
+
timezone: 'America/New_York',
|
|
152
|
+
isp: 'Google LLC'
|
|
153
|
+
}
|
|
154
|
+
*/
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**💡 Note:** If no `ip` is supplied, your own one will be used.
|
|
158
|
+
|
|
159
|
+
#
|
|
160
|
+
|
|
161
|
+
### `getOwnIP()`
|
|
162
|
+
|
|
163
|
+
Asynchronous method to fetch/return your own IP as a string:
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
// Using await syntax
|
|
167
|
+
(async () => {
|
|
168
|
+
const ip = await geo.getOwnIP();
|
|
169
|
+
console.log(ip); // outputs your IP
|
|
170
|
+
})();
|
|
171
|
+
|
|
172
|
+
// Using .then() syntax
|
|
173
|
+
geo.getOwnIP().then(ip => {
|
|
174
|
+
console.log(ip); // outputs your IP
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
<br>
|
|
179
|
+
|
|
180
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
181
|
+
|
|
182
|
+
## 🏛️ MIT License
|
|
183
|
+
|
|
184
|
+
**Copyright © 2023 [Adam Lui](https://github.com/adamlui).**
|
|
185
|
+
|
|
186
|
+
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:
|
|
187
|
+
|
|
188
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
189
|
+
|
|
190
|
+
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.
|
|
191
|
+
|
|
192
|
+
<br>
|
|
193
|
+
|
|
194
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
195
|
+
|
|
196
|
+
## 🛠️ Related utilities
|
|
197
|
+
|
|
198
|
+
### <img height=21px src="https://i.imgur.com/kvf7fXm.png"> [generate-ip](https://js-utils.com/generate-ip) <a href="https://github.com/toolleeo/cli-apps#networking"><img height=18 src="https://awesome.re/mentioned-badge.svg"></a>
|
|
199
|
+
|
|
200
|
+
> Randomly generate, format, and validate IPv4/IPv6 addresses.
|
|
201
|
+
<br>[Install](https://github.com/adamlui/js-utils/tree/main/generate-ip#-installation) /
|
|
202
|
+
[Readme](https://github.com/adamlui/js-utils/tree/main/generate-ip#readme) /
|
|
203
|
+
[API usage](https://github.com/adamlui/js-utils/tree/main/generate-ip#-api-usage) /
|
|
204
|
+
[CLI usage](https://github.com/adamlui/js-utils/tree/main/generate-ip#-command-line-usage) /
|
|
205
|
+
[Discuss](https://js-utils.com/discussions)
|
|
206
|
+
|
|
207
|
+
### [🔒 generate-pw](../generate-pw)
|
|
208
|
+
|
|
209
|
+
> Randomly generate, strengthen, and validate cryptographically-secure passwords.
|
|
210
|
+
<br>[Install](https://github.com/adamlui/js-utils/tree/main/generate-pw#-installation) /
|
|
211
|
+
[Readme](https://github.com/adamlui/js-utils/tree/main/generate-pw#readme) /
|
|
212
|
+
[API usage](https://github.com/adamlui/js-utils/tree/main/generate-pw#-api-usage) /
|
|
213
|
+
[CLI usage](https://github.com/adamlui/js-utils/tree/main/generate-pw#-command-line-usage) /
|
|
214
|
+
[Discuss](https://js-utils.com/discussions)
|
|
215
|
+
|
|
216
|
+
<br>
|
|
217
|
+
|
|
218
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
219
|
+
|
|
220
|
+
<picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/white/icon32x27.png"><img height=13 src="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/dark-gray/icon32x27.png"></picture> <a href="https://js-utils.com">**More JavaScript utilities**</a> /
|
|
221
|
+
<a href="https://js-utils.com/discussions">Discuss</a> /
|
|
222
|
+
<a href="#-geolocate">Back to top ↑</a>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamlui/geolocate",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Fetch IP geolocation data from the CLI.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Adam Lui",
|
|
@@ -35,7 +35,9 @@
|
|
|
35
35
|
"geolocate",
|
|
36
36
|
"geolocation",
|
|
37
37
|
"ip",
|
|
38
|
-
"networking"
|
|
38
|
+
"networking",
|
|
39
|
+
"api",
|
|
40
|
+
"cli"
|
|
39
41
|
],
|
|
40
42
|
"bugs": {
|
|
41
43
|
"url": "https://github.com/adamlui/js-utils/issues"
|
|
@@ -44,6 +46,6 @@
|
|
|
44
46
|
"generate-ip": "^2.2.0"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
|
-
"@adamlui/minify.js": "^1.
|
|
49
|
+
"@adamlui/minify.js": "^1.5.0"
|
|
48
50
|
}
|
|
49
51
|
}
|