@adamlui/geolocate 2.0.10 → 2.0.12
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 +38 -31
- package/dist/cli.min.js +12 -11
- package/dist/geolocate.min.js +2 -2
- package/docs/LICENSE.md +1 -1
- package/docs/README.md +38 -31
- package/docs/SECURITY.md +1 -3
- package/package.json +23 -9
package/README.md
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://media.geolocatejs.org/images/icons/wire-globe/white/icon32.png?
|
|
1
|
+
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://media.geolocatejs.org/images/icons/wire-globe/white/icon32.png?0d36e26"><img height=28 src="https://media.geolocatejs.org/images/icons/wire-globe/black/icon32.png?0d36e26"></picture> geolocate
|
|
2
2
|
|
|
3
3
|
### Fetch IP geolocation data from the CLI.
|
|
4
4
|
|
|
5
|
-
<a href="https://www.npmjs.com/package/@adamlui/geolocate"
|
|
6
|
-
<
|
|
7
|
-
<a href="
|
|
8
|
-
<
|
|
9
|
-
<a href="https://github.com/adamlui/js-utils/
|
|
10
|
-
<
|
|
11
|
-
<a href="https://
|
|
5
|
+
<a href="https://www.npmjs.com/package/@adamlui/geolocate">
|
|
6
|
+
<img height=31 src="https://img.shields.io/npm/dm/@adamlui/geolocate?logo=npm&color=af68ff&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
7
|
+
<a href="#%EF%B8%8F-mit-license">
|
|
8
|
+
<img height=31 src="https://img.shields.io/badge/License-MIT-fc4f2d.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
9
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.0.12">
|
|
10
|
+
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.0.12-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@adamlui/geolocate?activeTab=code">
|
|
12
|
+
<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>
|
|
13
|
+
<a href="https://github.com/adamlui/js-utils/blob/geolocate-2.0.12/geolocate/dist/geolocate.min.js">
|
|
14
|
+
<img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/geolocate/dist/geolocate.min.js?branch=geolocate-2.0.12&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
15
|
+
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:geolocate/src/geolocate.js">
|
|
16
|
+
<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>
|
|
17
|
+
<a href="https://github.com/toolleeo/cli-apps#networking">
|
|
18
|
+
<img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-c4a2bd?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
12
19
|
|
|
13
20
|
<br>
|
|
14
21
|
|
|
15
|
-
<img height=6px width="100%" src="https://
|
|
22
|
+
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
|
16
23
|
|
|
17
24
|
## ⚡ Installation
|
|
18
25
|
|
|
@@ -36,9 +43,9 @@ $ npm install @adamlui/geolocate
|
|
|
36
43
|
|
|
37
44
|
<br>
|
|
38
45
|
|
|
39
|
-
<a href="https://github.com/sponsors/adamlui"><img src="https://
|
|
46
|
+
<a href="https://github.com/sponsors/adamlui"><img src="https://assets.js-utils.org/images/banners/sponsor/$10/banner1660x260.png?v=0d36e26"></a>
|
|
40
47
|
|
|
41
|
-
<img height=6px width="100%" src="https://
|
|
48
|
+
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
|
42
49
|
|
|
43
50
|
## 💻 Command line usage
|
|
44
51
|
|
|
@@ -50,7 +57,7 @@ $ geolocate [ip1] [ip2] [...]
|
|
|
50
57
|
|
|
51
58
|
Sample output:
|
|
52
59
|
|
|
53
|
-
<img src="https://media.geolocatejs.org/images/screenshots/cli/geolocate-8.8.8.8-cmd-output.png?
|
|
60
|
+
<img src="https://media.geolocatejs.org/images/screenshots/cli/geolocate-8.8.8.8-cmd-output.png?0d36e26">
|
|
54
61
|
|
|
55
62
|
**📝 Note:** If no IPv4 address is passed, your own one will be used.
|
|
56
63
|
|
|
@@ -67,13 +74,13 @@ Info commands:
|
|
|
67
74
|
|
|
68
75
|
<br>
|
|
69
76
|
|
|
70
|
-
<img height=6px width="100%" src="https://
|
|
77
|
+
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
|
71
78
|
|
|
72
79
|
## 🔌 Importing the API
|
|
73
80
|
|
|
74
81
|
You can also import **geolocate** into your app to use its main API method.
|
|
75
82
|
|
|
76
|
-
### <img height=18 src="https://
|
|
83
|
+
### <img height=18 src="https://assets.js-utils.org/images/icons/platforms/node.js/icon25x28.png?v=0d36e26"> Node.js
|
|
77
84
|
|
|
78
85
|
#### ECMAScript*:
|
|
79
86
|
|
|
@@ -89,28 +96,28 @@ const geo = require('@adamlui/geolocate');
|
|
|
89
96
|
|
|
90
97
|
###### _*Node.js version 14 or higher required_
|
|
91
98
|
|
|
92
|
-
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
99
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://assets.js-utils.org/images/icons/platforms/web/light/icon25.png?v=0d36e26"><img width=16 src="https://assets.js-utils.org/images/icons/platforms/web/dark/icon25.png?v=0d36e26"></picture> Web
|
|
93
100
|
|
|
94
101
|
#### <> HTML script tag:
|
|
95
102
|
|
|
96
103
|
```html
|
|
97
|
-
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
104
|
+
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.12/dist/geolocate.min.js"></script>
|
|
98
105
|
```
|
|
99
106
|
|
|
100
107
|
#### ES6:
|
|
101
108
|
|
|
102
109
|
```js
|
|
103
110
|
(async () => {
|
|
104
|
-
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
111
|
+
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.12/dist/geolocate.min.js');
|
|
105
112
|
// Your code here...
|
|
106
113
|
})();
|
|
107
114
|
```
|
|
108
115
|
|
|
109
|
-
### <img height=17 src="https://
|
|
116
|
+
### <img height=17 src="https://assets.js-utils.org/images/icons/platforms/tampermonkey/icon28.png?v=0d36e26"><img height=17.5 src="https://assets.js-utils.org/images/icons/platforms/violentmonkey/icon25.png?v=0d36e26"> Greasemonkey
|
|
110
117
|
|
|
111
118
|
```js
|
|
112
119
|
...
|
|
113
|
-
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
120
|
+
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.12/dist/geolocate.min.js
|
|
114
121
|
// ==/UserScript==
|
|
115
122
|
|
|
116
123
|
// Your code here...
|
|
@@ -118,11 +125,11 @@ const geo = require('@adamlui/geolocate');
|
|
|
118
125
|
|
|
119
126
|
<br>
|
|
120
127
|
|
|
121
|
-
**📝 Note:** To always import the latest version (not recommended in production!) remove the `@2.0.
|
|
128
|
+
**📝 Note:** To always import the latest version (not recommended in production!) remove the `@2.0.12` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
|
|
122
129
|
|
|
123
130
|
<br>
|
|
124
131
|
|
|
125
|
-
<img height=6px width="100%" src="https://
|
|
132
|
+
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
|
126
133
|
|
|
127
134
|
## 📋 API usage
|
|
128
135
|
|
|
@@ -173,11 +180,11 @@ Name | Type | Description | Default Value
|
|
|
173
180
|
|
|
174
181
|
<br>
|
|
175
182
|
|
|
176
|
-
<img height=6px width="100%" src="https://
|
|
183
|
+
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
|
177
184
|
|
|
178
185
|
## 🏛️ MIT License
|
|
179
186
|
|
|
180
|
-
**Copyright © 2024 [Adam Lui](https://github.com/adamlui).**
|
|
187
|
+
**Copyright © 2024–2026 [Adam Lui](https://github.com/adamlui).**
|
|
181
188
|
|
|
182
189
|
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
190
|
|
|
@@ -187,32 +194,32 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
187
194
|
|
|
188
195
|
<br>
|
|
189
196
|
|
|
190
|
-
<img height=6px width="100%" src="https://
|
|
197
|
+
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
|
191
198
|
|
|
192
199
|
## 🛠️ Related utilities
|
|
193
200
|
|
|
194
|
-
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://media.generate-ip.org/images/icons/node-graph/white/icon55x49.png?b4eb06e"><img height=21 src="https://media.generate-ip.org/images/icons/node-graph/black/icon55x49.png?b4eb06e"></picture> [generate-ip](https://js-utils.
|
|
201
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://media.generate-ip.org/images/icons/node-graph/white/icon55x49.png?b4eb06e"><img height=21 src="https://media.generate-ip.org/images/icons/node-graph/black/icon55x49.png?b4eb06e"></picture> [generate-ip](https://js-utils.org/generate-ip) <a href="https://github.com/toolleeo/cli-apps#networking"><img height=18 src="https://assets.js-utils.org/images/badges/awesome/badge.svg?v=0d36e26"></a>
|
|
195
202
|
|
|
196
203
|
> Randomly generate, format, and validate IPv4 + IPv6 + MAC addresses.
|
|
197
204
|
<br>[Install](https://docs.generate-ip.org/#-installation) /
|
|
198
205
|
[Readme](https://docs.generate-ip.org/#readme) /
|
|
199
206
|
[API usage](https://docs.generate-ip.org/#-api-usage) /
|
|
200
207
|
[CLI usage](https://docs.generate-ip.org/#-command-line-usage) /
|
|
201
|
-
[Discuss](https://github.js-utils
|
|
208
|
+
[Discuss](https://github.com/adamlui/js-utils/discussions)
|
|
202
209
|
|
|
203
|
-
### [🔒 generate-pw](../generate-pw) <a href="https://github.com/toolleeo/cli-apps#password-managers"><img height=18 src="https://
|
|
210
|
+
### [🔒 generate-pw](../generate-pw) <a href="https://github.com/toolleeo/cli-apps#password-managers"><img height=18 src="https://assets.js-utils.org/images/badges/awesome/badge.svg?v=0d36e26"></a>
|
|
204
211
|
|
|
205
212
|
> Randomly generate, strengthen, and validate cryptographically-secure passwords.
|
|
206
213
|
<br>[Install](https://docs.generatepw.org/#-installation) /
|
|
207
214
|
[Readme](https://docs.generatepw.org/#readme) /
|
|
208
215
|
[API usage](https://docs.generatepw.org/#-api-usage) /
|
|
209
216
|
[CLI usage](https://docs.generatepw.org/#-command-line-usage) /
|
|
210
|
-
[Discuss](https://github.js-utils
|
|
217
|
+
[Discuss](https://github.com/adamlui/js-utils/discussions)
|
|
211
218
|
|
|
212
219
|
<br>
|
|
213
220
|
|
|
214
|
-
<img height=6px width="100%" src="https://
|
|
221
|
+
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
|
215
222
|
|
|
216
|
-
<picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
217
|
-
<a href="https://github.js-utils
|
|
223
|
+
<picture><source media="(prefers-color-scheme: dark)" srcset="https://assets.js-utils.org/images/icons/home/white/icon32x27.png?v=0d36e26"><img height=13 src="https://assets.js-utils.org/images/icons/home/dark-gray/icon32x27.png?v=0d36e26"></picture> <a href="https://js-utils.org">**More JavaScript utilities**</a> /
|
|
224
|
+
<a href="https://github.com/adamlui/js-utils/discussions">Discuss</a> /
|
|
218
225
|
<a href="#-geolocate">Back to top ↑</a>
|
package/dist/cli.min.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* © 2024 Adam Lui under the MIT license.
|
|
3
|
+
* © 2024–2026 Adam Lui under the MIT license.
|
|
4
4
|
* Source: https://code.geolocatejs.org
|
|
5
5
|
* Documentation: https://docs.geolocatejs.org
|
|
6
6
|
*/
|
|
7
|
-
const pkgName="@adamlui/geolocate",copyright="© 2024 Adam Lui under the MIT license.",cmdFormat="geolocate [ip1] [ip2] [...] [options|commands]",srcURL="https://code.geolocatejs.org",docURL="https://docs.geolocatejs.org/#-command-line-usage";(async()=>{const e=require(__dirname.match(/src/)?"./geolocate":"./geolocate.min"),n=require("fs"),s=require("path"),i=require("child_process")
|
|
8
|
-
${"[1;91m"+(
|
|
9
|
-
${"[1;33m"+(
|
|
10
|
-
${
|
|
11
|
-
IP:
|
|
12
|
-
${
|
|
13
|
-
|
|
14
|
-
${r}o ${
|
|
15
|
-
${r}o ${
|
|
16
|
-
${
|
|
7
|
+
const pkgName="@adamlui/geolocate",copyright="© 2024–2026 Adam Lui under the MIT license.",cmdFormat="geolocate [ip1] [ip2] [...] [options|commands]",srcURL="https://code.geolocatejs.org",docURL="https://docs.geolocatejs.org/#-command-line-usage",latestLocaleCommitHash="cc58ad6";(async()=>{"use strict";const e=require(__dirname.match(/src/)?"./geolocate":"./geolocate.min"),n=require("fs"),s=require("path"),{execSync:i,execFileSync:o}=require("child_process"),t="[0m",r="[1;97m";let p="en";if("win32"==process.platform)try{p=i("(Get-Culture).TwoLetterISOLanguageName",{shell:"powershell",encoding:"utf-8"}).trim()}catch(e){_("Error loading system language: "+e)}else{var a=process.env;p=(a.LANG||a.LANGUAGE||a.LC_ALL||a.LC_MESSAGES||a.LC_NAME||"en").split(".")[0]}let c={};var l,g,a=new Promise((t,r)=>{const a=`https://cdn.jsdelivr.net/gh/adamlui/js-utils@4e0119f46a73abd6c87d4c0405bf2d3c977d5421/geolocate/_locales/`,e=`${p?p.replace("-","_"):"en"}/`;let c=a+e+"messages.json",l=0;u(c).then(async function o(e){try{const n=await e.json(),s={};for(const i in n)"object"==typeof n[i]&&"message"in n[i]&&(s[i]=n[i].message);t(s)}catch(e){if(3==++l)return t({});u(c=p.includes("-")&&1==l?c.replace(/([^_]*)_[^/]*(\/.*)/,"$1$2"):a+"en/messages.json").then(o).catch(r)}}).catch(r)});try{c=await a}catch(e){_("Error fetching messages: "+e)}const m={},f={flags:{quietMode:/^--?q(?:uiet)?(?:-?mode)?$/},infoCmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/}};if(process.argv.forEach(o=>{var e,n;o.startsWith("-")&&(e=Object.keys(f.flags).find(e=>f.flags[e].test(o)),n=Object.keys(f.infoCmds).find(e=>f.infoCmds[e].test(o)),e?m[e]=!0:n||(console.error(`
|
|
8
|
+
${"[1;91m"+(c.prefix_error||"ERROR")}: `+`Arg [${o}] ${c.error_notRecognized||"not recognized"}.[0m`),console.info(`
|
|
9
|
+
${"[1;33m"+(c.info_validArgs||"Valid arguments are below")}.[0m`),v(["configOptions","infoCmds"]),process.exit(1)))}),process.argv.some(e=>f.infoCmds.help.test(e)))v();else if(process.argv.some(e=>f.infoCmds.version.test(e))){a=i(`npm view ${pkgName} version`).toString().trim()||"none";let e,o=process.cwd();for(;"/"!=o;){var d=s.join(o,"package.json");if(n.existsSync(d)){d=require(d);e=(d.dependencies?.[pkgName]||d.devDependencies?.[pkgName])?.match(/^[~^>=]?\d+\.\d+\.\d+$/)?.[1]||"none";break}o=s.dirname(o)}console.info(`
|
|
10
|
+
${c.prefix_globalVer||"Global version"}: `+a),console.info(`${c.prefix_localVer||"Local version"}: `+e)}else{var $,h=[];for(const L of process.argv.slice(2))L.startsWith("-")||($=L.replace(/[[\]]/g,""),h.push($));a=await e.locate(h,{verbose:!m.quietMode});a||process.exit(1),m.quietMode||1!=a.length||(console.info(`
|
|
11
|
+
IP: ${r}${a[0].ip}[0m`),console.info(`${c.geoLabel_country||"Country"}: ${r}${a[0].country}${t}}`),console.info(`${c.geoLabel_region||"Region"}: ${r}${a[0].regionName}${t}}`),console.info(`${c.geoLabel_city||"City"}: ${r}${a[0].city}${t}}`),console.info(`${c.geoLabel_zip||"Zip"}: ${r}${a[0].zip}${t}}`),console.info(`${c.geoLabel_lat||"Latitude"}: ${r}${a[0].lat}${t}}`),console.info(`${c.geoLabel_lon||"Longitude"}: ${r}${a[0].lon}${t}}`),console.info(`${c.geoLabel_timeZone||"Time zone"}: ${r}${a[0].timezone.replace(/_/g," ").replace(/\//g," / ")}${t}`),console.info(`ISP: ${r}${a[0].isp}[0m}`)),_(`
|
|
12
|
+
${c.info_copying||"Copying to clipboard"}...`),l=(l=JSON.stringify(a,void 0,2)).replace(/"/g,'""'),g={darwin:{binPath:"/usr/bin/pbcopy",args:[]},linux:{binPath:"/usr/bin/xclip",args:["-selection","clipboard"]},win32:{binPath:s.join(process.env.SYSTEMROOT,"System32","WindowsPowerShell","v1.0","powershell.exe"),args:["-Command","Set-Clipboard -Value $input"]}},o(...Object.values(g[process.platform]),{input:l})}function u(s){return new Promise((n,e)=>{var o=s.match(/^([^:]+):\/\//)[1];/^https?$/.test(o)||e(new Error(`${c.error_invalidURL||"Invalid URL"}.`)),require(o).get(s,e=>{let o="";e.on("data",e=>o+=e),e.on("end",()=>n({json:()=>JSON.parse(o)}))}).on("error",e)})}function v(e=["header","usage","configOptions","infoCmds"]){var o=`[106m[30m ${pkgName.replace(/^@[^/]+\//,"")} [0m `;const n={header:[`
|
|
13
|
+
├ `+o+(c.appCopyright||copyright),o+(c.prefix_source||"Source")+": "+srcURL],usage:[`
|
|
14
|
+
${r}o ${c.helpSection_usage||"Usage"}:[0m`,` ${r}» [1;92m${cmdFormat}[0m`],configOptions:[`
|
|
15
|
+
${r}o ${c.helpSection_configOptions||"Config options"}:[0m`,` -q, --quiet ${c.optionDesc_quiet||"Suppress all logging except errors"}.`],infoCmds:[`
|
|
16
|
+
${r}o ${c.helpSection_infoCmds||"Info commands"}:[0m`," -h, --help "+(c.optionDesc_help||"Display help screen."),` -v, --version ${c.optionDesc_version||"Show version number"}.`]};e.forEach(r=>n[r]?.forEach(e=>{{var s=/header|usage/.test(r)?1:29;const i=process.stdout.columns||80,t=[],o=e.match(/\S+|\s+/g);let n="";o.forEach(e=>{var o=i-(t.length?s:0);n.length+"| ".length+e.length>o&&(t.push(t.length?n.trimStart():n),n=""),n+=e}),t.push(t.length?n.trimStart():n),t.forEach((e,o)=>console.info("| "+(0==o?e:" ".repeat(s)+e)))}})),console.info(`
|
|
17
|
+
${c.info_moreHelp||"For more help"}, ${c.info_visit||"visit"}: ${r}${docURL}[0m`)}function _(e){m.quietMode||console.info(e)}})();
|
package/dist/geolocate.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* © 2024 Adam Lui under the MIT license.
|
|
2
|
+
* © 2024–2026 Adam Lui under the MIT license.
|
|
3
3
|
* Source: https://code.geolocatejs.org
|
|
4
4
|
* Documentation: https://docs.geolocatejs.org
|
|
5
5
|
*/
|
|
6
|
-
async function geolocate(e,n={}){var o={verbose:!0};(e=Array.isArray(e)?e:[e])[0]
|
|
6
|
+
async function geolocate(e,n={}){var o={verbose:!0};(e=Array.isArray(e)?e:[e])[0]||=await 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"],o=require("util")["promisify"],{stdout:t,stderr:r}=await o(e)("curl -s ifconfig.me");return r?console.error("geolocate() »",r):t.trim()}catch(e){console.error("geolocate() »",e)}});for(const t of e){n.verbose&&console.info(`geolocate() » Validating ${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}))return console.error(`geolocate() » ERROR: ${t} is not a valid IPv4 address.`)}if(validateOptions(n,o,"https://docs.geolocatejs.org/#locateips-options","geolocate('8.8.8.8', { verbose: false })")){n={...o,...n};try{var c=[];for(const i of e){n.verbose&&console.info(`geolocate() » Fetching geolocation data for ${i}...`);let{status:e,org:o,as:t,query:r,...a}=await(await fetchData("http://ip-api.com/json/"+i)).json();a={ip:i,...a},c.push(a)}return n.verbose&&"undefined"!=typeof window&&console.info("geolocate() » Success! Check returned array."),c}catch(e){console.error("geolocate() » ERROR:",e.message)}}}function fetchData(r){return"undefined"==typeof fetch?new Promise((t,o)=>{try{var e=r.match(/^([^:]+):\/\//)[1];/^https?$/.test(e)||o(new Error("Invalid fetchData() URL.")),require(e).get(r,e=>{let o="";e.on("data",e=>o+=e),e.on("end",()=>t({json:()=>JSON.parse(o)}))}).on("error",e=>o(new Error(e.message)))}catch(e){o(new Error("Environment not supported."))}}):fetch(r)}function validateOptions(e,o,t,r){const a=JSON.stringify(o,void 0,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),n=Object.keys(o).join(", "),c=Object.keys(o).filter(e=>"boolean"==typeof o[e]),i=`${validateOptions.caller?.name||"validateOptions"}() » `;var s=r.split(",").findIndex(e=>e.trim().startsWith("{"))+1,l=(s+=["st","nd","rd"][s-1]||"th",()=>{console.info(i+`Valid options: [ ${n} ]`),console.info(i+"If omitted, default settings are: "+a)}),p=()=>{console.info(i+"For more help, please visit "+t)};if("object"!=typeof e)return console.error(i+`ERROR: ${"0th"==s?"[O":s+" arg [o"}ptions] can only be an object of key/values.`),console.info(i+"Example valid call: "+r),l(),p(),!1;for(const f in e){if(!Object.prototype.hasOwnProperty.call(o,f))return console.error(i+`ERROR: \`${f}\` is an invalid option.`),l(),p(),!1;if(c.includes(f)&&"boolean"!=typeof e[f])return console.error(i+`ERROR: [${f}] option can only be \`true\` or \`false\`.`),p(),!1}return!0}const geoAliases={geolocate:["Geolocate","geoLocate","GeoLocate","locate","Locate"]};try{module.exports={geolocate:geolocate}}catch(e){}try{window.geo={geolocate:geolocate}}catch(e){}for(const $ in geoAliases){try{geoAliases[$].forEach(e=>module.exports[e]=module.exports[$])}catch(e){}try{geoAliases[$].forEach(e=>window.geo[e]=window.geo[$])}catch(e){}}
|
package/docs/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 🏛️ MIT License
|
|
2
2
|
|
|
3
|
-
**Copyright © 2024 [Adam Lui](https://github.com/adamlui)**
|
|
3
|
+
**Copyright © 2024–2026 [Adam Lui](https://github.com/adamlui)**
|
|
4
4
|
|
|
5
5
|
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:
|
|
6
6
|
|
package/docs/README.md
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://media.geolocatejs.org/images/icons/wire-globe/white/icon32.png?
|
|
1
|
+
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://media.geolocatejs.org/images/icons/wire-globe/white/icon32.png?0d36e26"><img height=28 src="https://media.geolocatejs.org/images/icons/wire-globe/black/icon32.png?0d36e26"></picture> geolocate
|
|
2
2
|
|
|
3
3
|
### Fetch IP geolocation data from the CLI.
|
|
4
4
|
|
|
5
|
-
<a href="https://www.npmjs.com/package/@adamlui/geolocate"
|
|
6
|
-
<
|
|
7
|
-
<a href="
|
|
8
|
-
<
|
|
9
|
-
<a href="https://github.com/adamlui/js-utils/
|
|
10
|
-
<
|
|
11
|
-
<a href="https://
|
|
5
|
+
<a href="https://www.npmjs.com/package/@adamlui/geolocate">
|
|
6
|
+
<img height=31 src="https://img.shields.io/npm/dm/@adamlui/geolocate?logo=npm&color=af68ff&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
7
|
+
<a href="#%EF%B8%8F-mit-license">
|
|
8
|
+
<img height=31 src="https://img.shields.io/badge/License-MIT-fc4f2d.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
9
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.0.12">
|
|
10
|
+
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.0.12-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@adamlui/geolocate?activeTab=code">
|
|
12
|
+
<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>
|
|
13
|
+
<a href="https://github.com/adamlui/js-utils/blob/geolocate-2.0.12/geolocate/dist/geolocate.min.js">
|
|
14
|
+
<img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/geolocate/dist/geolocate.min.js?branch=geolocate-2.0.12&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
15
|
+
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:geolocate/src/geolocate.js">
|
|
16
|
+
<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>
|
|
17
|
+
<a href="https://github.com/toolleeo/cli-apps#networking">
|
|
18
|
+
<img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-c4a2bd?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
12
19
|
|
|
13
20
|
<br>
|
|
14
21
|
|
|
15
|
-
<img height=6px width="100%" src="https://
|
|
22
|
+
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
|
16
23
|
|
|
17
24
|
## ⚡ Installation
|
|
18
25
|
|
|
@@ -36,9 +43,9 @@ $ npm install @adamlui/geolocate
|
|
|
36
43
|
|
|
37
44
|
<br>
|
|
38
45
|
|
|
39
|
-
<a href="https://github.com/sponsors/adamlui"><img src="https://
|
|
46
|
+
<a href="https://github.com/sponsors/adamlui"><img src="https://assets.js-utils.org/images/banners/sponsor/$10/banner1660x260.png?v=0d36e26"></a>
|
|
40
47
|
|
|
41
|
-
<img height=6px width="100%" src="https://
|
|
48
|
+
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
|
42
49
|
|
|
43
50
|
## 💻 Command line usage
|
|
44
51
|
|
|
@@ -50,7 +57,7 @@ $ geolocate [ip1] [ip2] [...]
|
|
|
50
57
|
|
|
51
58
|
Sample output:
|
|
52
59
|
|
|
53
|
-
<img src="https://media.geolocatejs.org/images/screenshots/cli/geolocate-8.8.8.8-cmd-output.png?
|
|
60
|
+
<img src="https://media.geolocatejs.org/images/screenshots/cli/geolocate-8.8.8.8-cmd-output.png?0d36e26">
|
|
54
61
|
|
|
55
62
|
**📝 Note:** If no IPv4 address is passed, your own one will be used.
|
|
56
63
|
|
|
@@ -67,13 +74,13 @@ Info commands:
|
|
|
67
74
|
|
|
68
75
|
<br>
|
|
69
76
|
|
|
70
|
-
<img height=6px width="100%" src="https://
|
|
77
|
+
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
|
71
78
|
|
|
72
79
|
## 🔌 Importing the API
|
|
73
80
|
|
|
74
81
|
You can also import **geolocate** into your app to use its main API method.
|
|
75
82
|
|
|
76
|
-
### <img height=18 src="https://
|
|
83
|
+
### <img height=18 src="https://assets.js-utils.org/images/icons/platforms/node.js/icon25x28.png?v=0d36e26"> Node.js
|
|
77
84
|
|
|
78
85
|
#### ECMAScript*:
|
|
79
86
|
|
|
@@ -89,28 +96,28 @@ const geo = require('@adamlui/geolocate');
|
|
|
89
96
|
|
|
90
97
|
###### _*Node.js version 14 or higher required_
|
|
91
98
|
|
|
92
|
-
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
99
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://assets.js-utils.org/images/icons/platforms/web/light/icon25.png?v=0d36e26"><img width=16 src="https://assets.js-utils.org/images/icons/platforms/web/dark/icon25.png?v=0d36e26"></picture> Web
|
|
93
100
|
|
|
94
101
|
#### <> HTML script tag:
|
|
95
102
|
|
|
96
103
|
```html
|
|
97
|
-
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
104
|
+
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.12/dist/geolocate.min.js"></script>
|
|
98
105
|
```
|
|
99
106
|
|
|
100
107
|
#### ES6:
|
|
101
108
|
|
|
102
109
|
```js
|
|
103
110
|
(async () => {
|
|
104
|
-
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
111
|
+
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.12/dist/geolocate.min.js');
|
|
105
112
|
// Your code here...
|
|
106
113
|
})();
|
|
107
114
|
```
|
|
108
115
|
|
|
109
|
-
### <img height=17 src="https://
|
|
116
|
+
### <img height=17 src="https://assets.js-utils.org/images/icons/platforms/tampermonkey/icon28.png?v=0d36e26"><img height=17.5 src="https://assets.js-utils.org/images/icons/platforms/violentmonkey/icon25.png?v=0d36e26"> Greasemonkey
|
|
110
117
|
|
|
111
118
|
```js
|
|
112
119
|
...
|
|
113
|
-
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
120
|
+
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.12/dist/geolocate.min.js
|
|
114
121
|
// ==/UserScript==
|
|
115
122
|
|
|
116
123
|
// Your code here...
|
|
@@ -118,11 +125,11 @@ const geo = require('@adamlui/geolocate');
|
|
|
118
125
|
|
|
119
126
|
<br>
|
|
120
127
|
|
|
121
|
-
**📝 Note:** To always import the latest version (not recommended in production!) remove the `@2.0.
|
|
128
|
+
**📝 Note:** To always import the latest version (not recommended in production!) remove the `@2.0.12` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
|
|
122
129
|
|
|
123
130
|
<br>
|
|
124
131
|
|
|
125
|
-
<img height=6px width="100%" src="https://
|
|
132
|
+
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
|
126
133
|
|
|
127
134
|
## 📋 API usage
|
|
128
135
|
|
|
@@ -173,11 +180,11 @@ Name | Type | Description | Default Value
|
|
|
173
180
|
|
|
174
181
|
<br>
|
|
175
182
|
|
|
176
|
-
<img height=6px width="100%" src="https://
|
|
183
|
+
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
|
177
184
|
|
|
178
185
|
## 🏛️ MIT License
|
|
179
186
|
|
|
180
|
-
**Copyright © 2024 [Adam Lui](https://github.com/adamlui).**
|
|
187
|
+
**Copyright © 2024–2026 [Adam Lui](https://github.com/adamlui).**
|
|
181
188
|
|
|
182
189
|
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
190
|
|
|
@@ -187,32 +194,32 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
187
194
|
|
|
188
195
|
<br>
|
|
189
196
|
|
|
190
|
-
<img height=6px width="100%" src="https://
|
|
197
|
+
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
|
191
198
|
|
|
192
199
|
## 🛠️ Related utilities
|
|
193
200
|
|
|
194
|
-
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://media.generate-ip.org/images/icons/node-graph/white/icon55x49.png?b4eb06e"><img height=21 src="https://media.generate-ip.org/images/icons/node-graph/black/icon55x49.png?b4eb06e"></picture> [generate-ip](https://js-utils.
|
|
201
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://media.generate-ip.org/images/icons/node-graph/white/icon55x49.png?b4eb06e"><img height=21 src="https://media.generate-ip.org/images/icons/node-graph/black/icon55x49.png?b4eb06e"></picture> [generate-ip](https://js-utils.org/generate-ip) <a href="https://github.com/toolleeo/cli-apps#networking"><img height=18 src="https://assets.js-utils.org/images/badges/awesome/badge.svg?v=0d36e26"></a>
|
|
195
202
|
|
|
196
203
|
> Randomly generate, format, and validate IPv4 + IPv6 + MAC addresses.
|
|
197
204
|
<br>[Install](https://docs.generate-ip.org/#-installation) /
|
|
198
205
|
[Readme](https://docs.generate-ip.org/#readme) /
|
|
199
206
|
[API usage](https://docs.generate-ip.org/#-api-usage) /
|
|
200
207
|
[CLI usage](https://docs.generate-ip.org/#-command-line-usage) /
|
|
201
|
-
[Discuss](https://github.js-utils
|
|
208
|
+
[Discuss](https://github.com/adamlui/js-utils/discussions)
|
|
202
209
|
|
|
203
|
-
### [🔒 generate-pw](../generate-pw) <a href="https://github.com/toolleeo/cli-apps#password-managers"><img height=18 src="https://
|
|
210
|
+
### [🔒 generate-pw](../generate-pw) <a href="https://github.com/toolleeo/cli-apps#password-managers"><img height=18 src="https://assets.js-utils.org/images/badges/awesome/badge.svg?v=0d36e26"></a>
|
|
204
211
|
|
|
205
212
|
> Randomly generate, strengthen, and validate cryptographically-secure passwords.
|
|
206
213
|
<br>[Install](https://docs.generatepw.org/#-installation) /
|
|
207
214
|
[Readme](https://docs.generatepw.org/#readme) /
|
|
208
215
|
[API usage](https://docs.generatepw.org/#-api-usage) /
|
|
209
216
|
[CLI usage](https://docs.generatepw.org/#-command-line-usage) /
|
|
210
|
-
[Discuss](https://github.js-utils
|
|
217
|
+
[Discuss](https://github.com/adamlui/js-utils/discussions)
|
|
211
218
|
|
|
212
219
|
<br>
|
|
213
220
|
|
|
214
|
-
<img height=6px width="100%" src="https://
|
|
221
|
+
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
|
215
222
|
|
|
216
|
-
<picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
217
|
-
<a href="https://github.js-utils
|
|
223
|
+
<picture><source media="(prefers-color-scheme: dark)" srcset="https://assets.js-utils.org/images/icons/home/white/icon32x27.png?v=0d36e26"><img height=13 src="https://assets.js-utils.org/images/icons/home/dark-gray/icon32x27.png?v=0d36e26"></picture> <a href="https://js-utils.org">**More JavaScript utilities**</a> /
|
|
224
|
+
<a href="https://github.com/adamlui/js-utils/discussions">Discuss</a> /
|
|
218
225
|
<a href="#-geolocate">Back to top ↑</a>
|
package/docs/SECURITY.md
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
# 🛡️ Security Policy
|
|
2
2
|
|
|
3
|
-
If you find a vulnerability, please
|
|
4
|
-
|
|
5
|
-
Pull requests are also welcome, but for safety reasons, send an email to <adam@kudoai.com> and wait for a response before making it public.
|
|
3
|
+
If you find a vulnerability, please follow the reporting instructions @ https://tidelift.com/security
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamlui/geolocate",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12",
|
|
4
4
|
"description": "Fetch IP geolocation data from the CLI.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Adam Lui",
|
|
@@ -9,6 +9,24 @@
|
|
|
9
9
|
},
|
|
10
10
|
"homepage": "https://geolocatejs.org",
|
|
11
11
|
"license": "MIT",
|
|
12
|
+
"funding": [
|
|
13
|
+
{
|
|
14
|
+
"type": "cashapp",
|
|
15
|
+
"url": "https://cash.app/$AdamLui"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"type": "github",
|
|
19
|
+
"url": "http://github.com/sponsors/adamlui"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"type": "ko-fi",
|
|
23
|
+
"url": "https://ko-fi.com/adamlui"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"type": "paypal",
|
|
27
|
+
"url": "https://paypal.me/adamlui"
|
|
28
|
+
}
|
|
29
|
+
],
|
|
12
30
|
"main": "dist/geolocate.min.js",
|
|
13
31
|
"files": [
|
|
14
32
|
"docs/"
|
|
@@ -21,14 +39,10 @@
|
|
|
21
39
|
"doc": "./docs"
|
|
22
40
|
},
|
|
23
41
|
"scripts": {
|
|
24
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
25
42
|
"build": "bash utils/build.sh",
|
|
26
43
|
"bump:patch": "bash utils/bump.sh patch",
|
|
27
44
|
"bump:minor": "bash utils/bump.sh minor",
|
|
28
|
-
"bump:major": "bash utils/bump.sh major"
|
|
29
|
-
"publish:patch": "bash utils/bump.sh patch --publish",
|
|
30
|
-
"publish:minor": "bash utils/bump.sh minor --publish",
|
|
31
|
-
"publish:major": "bash utils/bump.sh major --publish"
|
|
45
|
+
"bump:major": "bash utils/bump.sh major"
|
|
32
46
|
},
|
|
33
47
|
"repository": {
|
|
34
48
|
"type": "git",
|
|
@@ -43,12 +57,12 @@
|
|
|
43
57
|
"cli"
|
|
44
58
|
],
|
|
45
59
|
"bugs": {
|
|
46
|
-
"url": "https://
|
|
60
|
+
"url": "https://support.geolocatejs.org"
|
|
47
61
|
},
|
|
48
62
|
"dependencies": {
|
|
49
|
-
"generate-ip": "^2.4.
|
|
63
|
+
"generate-ip": "^2.4.5"
|
|
50
64
|
},
|
|
51
65
|
"devDependencies": {
|
|
52
|
-
"@adamlui/minify.js": "^1.8.
|
|
66
|
+
"@adamlui/minify.js": "^1.8.6"
|
|
53
67
|
}
|
|
54
68
|
}
|