@adamlui/geolocate 2.0.14 โ 2.0.15
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 +8 -8
- package/dist/cli/index.min.js +17 -0
- package/dist/cli/lib/data.min.js +6 -0
- package/dist/cli/lib/language.min.js +6 -0
- package/dist/data/app.json +17 -0
- package/dist/data/messages.json +27 -0
- package/docs/README.md +8 -8
- package/package.json +6 -4
- package/dist/cli.min.js +0 -22
package/README.md
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
<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>
|
|
9
9
|
<a href="#%EF%B8%8F-mit-license">
|
|
10
10
|
<img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
11
|
-
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.0.
|
|
12
|
-
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.0.
|
|
11
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.0.15">
|
|
12
|
+
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.0.15-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
13
13
|
<a href="https://www.npmjs.com/package/@adamlui/geolocate?activeTab=code">
|
|
14
14
|
<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>
|
|
15
|
-
<a href="https://github.com/adamlui/js-utils/blob/geolocate-2.0.
|
|
16
|
-
<img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/geolocate/dist/geolocate.min.js?branch=geolocate-2.0.
|
|
15
|
+
<a href="https://github.com/adamlui/js-utils/blob/geolocate-2.0.15/geolocate/dist/geolocate.min.js">
|
|
16
|
+
<img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/geolocate/dist/geolocate.min.js?branch=geolocate-2.0.15&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
17
17
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:geolocate/src/geolocate.js">
|
|
18
18
|
<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>
|
|
19
19
|
<a href="https://github.com/toolleeo/cli-apps#networking">
|
|
@@ -103,14 +103,14 @@ const geo = require('@adamlui/geolocate')
|
|
|
103
103
|
#### <> HTML script tag:
|
|
104
104
|
|
|
105
105
|
```html
|
|
106
|
-
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
106
|
+
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.15/dist/geolocate.min.js"></script>
|
|
107
107
|
```
|
|
108
108
|
|
|
109
109
|
#### ES6:
|
|
110
110
|
|
|
111
111
|
```js
|
|
112
112
|
(async () => {
|
|
113
|
-
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
113
|
+
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.15/dist/geolocate.min.js')
|
|
114
114
|
// Your code here...
|
|
115
115
|
})()
|
|
116
116
|
```
|
|
@@ -119,7 +119,7 @@ const geo = require('@adamlui/geolocate')
|
|
|
119
119
|
|
|
120
120
|
```js
|
|
121
121
|
...
|
|
122
|
-
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
122
|
+
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.15/dist/geolocate.min.js
|
|
123
123
|
// ==/UserScript==
|
|
124
124
|
|
|
125
125
|
// Your code here...
|
|
@@ -127,7 +127,7 @@ const geo = require('@adamlui/geolocate')
|
|
|
127
127
|
|
|
128
128
|
<br>
|
|
129
129
|
|
|
130
|
-
**๐ Note:** To always import the latest version (not recommended in production!) remove the `@2.0.
|
|
130
|
+
**๐ Note:** To always import the latest version (not recommended in production!) remove the `@2.0.15` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
|
|
131
131
|
|
|
132
132
|
<br>
|
|
133
133
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* ยฉ 2024โ2026 Adam Lui under the MIT license.
|
|
4
|
+
* Source: https://code.geolocatejs.org
|
|
5
|
+
* Documentation: https://docs.geolocatejs.org
|
|
6
|
+
*/
|
|
7
|
+
(async()=>{globalThis.env={devMode:__dirname.match(/[\\/]src/)};var e=require("node-clipboardy"),s=require("child_process").execSync,p=require("fs"),o=require(`../geolocate${env.devMode?"":".min"}.js`),{getMsgs:n,getSysLang:a}=require(`./lib/language${env.devMode?"":".min"}.js`),i=require("path");globalThis.app=require(`../${env.devMode?"../":"./data/"}app.json`),app.urls.docs+="/#-command-line-usage",app.msgs=await n(a()),app.regex={flags:{quietMode:/^--?q(?:uiet)?(?:-?mode)?$/},infoCmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/},version:/^[~^>=]?\d+\.\d+\.\d+$/};let r={nc:"[0m",br:"[1;91m",by:"[1;33m",bg:"[1;92m",bw:"[1;97m"};if(app.config={},process.argv.forEach(o=>{var e,s;o.startsWith("-")&&(e=Object.keys(app.regex.flags).find(e=>app.regex.flags[e].test(o)),s=Object.keys(app.regex.infoCmds).find(e=>app.regex.infoCmds[e].test(o)),e?app.config[e]=!0:s||(console.error(`
|
|
8
|
+
${r.br}${app.msgs.prefix_error}: Arg [${o}] ${app.msgs.error_notRecognized}.`+r.nc),console.info(`
|
|
9
|
+
${r.by}${app.msgs.info_validArgs}.`+r.nc),m(["paramOptions","infoCmds"]),process.exit(1)))}),process.argv.some(e=>app.regex.infoCmds.help.test(e)))m();else if(process.argv.some(e=>app.regex.infoCmds.version.test(e))){n=s(`npm view ${JSON.stringify(app.name)} version`).toString().trim()||"none";let e,o=process.cwd();for(;"/"!=o;){var c=i.join(o,"package.json");if(p.existsSync(c)){c=require(c);e=(c.dependencies?.[app.name]||c.devDependencies?.[app.name])?.match(/^[~^>=]?\d+\.\d+\.\d+$/)?.[1]||"none";break}o=i.dirname(o)}console.info(`
|
|
10
|
+
${app.msgs.prefix_globalVer}: `+n),console.info(app.msgs.prefix_localVer+": "+e)}else{var g,t,l=[];for(g of process.argv.slice(2))g.startsWith("-")||(t=g.replace(/[[\]]/g,""),l.push(t));a=await o.locate(l,{verbose:!app.config.quietMode});a||process.exit(1),app.config.quietMode||1!=a.length||(console.info(`
|
|
11
|
+
IP: `+r.bw+a[0].ip+r.nc),console.info(`${app.msgs.geoLabel_country}: ${r.bw}${a[0].country}${r.nc}}`),console.info(`${app.msgs.geoLabel_region}: ${r.bw}${a[0].regionName}${r.nc}}`),console.info(`${app.msgs.geoLabel_city}: ${r.bw}${a[0].city}${r.nc}}`),console.info(`${app.msgs.geoLabel_zip}: ${r.bw}${a[0].zip}${r.nc}}`),console.info(`${app.msgs.geoLabel_lat}: ${r.bw}${a[0].lat}${r.nc}}`),console.info(`${app.msgs.geoLabel_lon}: ${r.bw}${a[0].lon}${r.nc}}`),console.info(app.msgs.geoLabel_timeZone+": "+r.bw+a[0].timezone.replace(/_/g," ").replace(/\//g," / ")+r.nc),console.info(`ISP: ${r.bw}${a[0].isp}${r.nc}}`)),s=`
|
|
12
|
+
${app.msgs.info_copying}...`,app.config.quietMode||console.info(s),e.writeSync(JSON.stringify(a,void 0,2))}function m(e=["header","usage","configOptions","infoCmds"]){app.prefix=`[106m[30m ${app.name.replace(/^@[^/]+\//,"")} ${r.nc} `;let o={header:[`
|
|
13
|
+
โ ${app.prefix}${app.msgs.appCopyright||`ยฉ ${app.copyrightYear} ${app.author} under the ${app.license} license`}.`,""+app.prefix+app.msgs.prefix_source+": "+app.urls.src],usage:[`
|
|
14
|
+
${r.bw}o ${app.msgs.helpSection_usage}:`+r.nc,` ${r.bw}ยป `+r.bg+app.cmdFormat+r.nc],configOptions:[`
|
|
15
|
+
${r.bw}o ${app.msgs.helpSection_configOptions}:`+r.nc,` -q, --quiet ${app.msgs.optionDesc_quiet}.`],infoCmds:[`
|
|
16
|
+
${r.bw}o ${app.msgs.helpSection_infoCmds}:`+r.nc," -h, --help "+app.msgs.optionDesc_help,` -v, --version ${app.msgs.optionDesc_version}.`]};e.forEach(i=>o[i]?.forEach(o=>{{var a=/header|usage/.test(i)?1:29;let s=process.stdout.columns||80,p=[],e=o.match(/\S+|\s+/g),n="";e.forEach(e=>{var o=s-(p.length?a:0);n.length+"| ".length+e.length>o&&(p.push(p.length?n.trimStart():n),n=""),n+=e}),p.push(p.length?n.trimStart():n),p.forEach((e,o)=>console.info("| "+(0==o?e:" ".repeat(a)+e)))}})),console.info(`
|
|
17
|
+
${app.msgs.info_moreHelp}, ${app.msgs.info_visit}: `+r.bw+app.urls.docs+r.nc)}})();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ยฉ 2024โ2026 Adam Lui under the MIT license.
|
|
3
|
+
* Source: https://code.geolocatejs.org
|
|
4
|
+
* Documentation: https://docs.geolocatejs.org
|
|
5
|
+
*/
|
|
6
|
+
module.exports={fetch(n){return new Promise((t,e)=>{var r=n.match(/^([^:]+):\/\//)[1];/^https?$/.test(r)||e(new Error(app.msgs.error_invalidURL+".")),require(r).get(n,e=>{let r="";e.on("data",e=>r+=e),e.on("end",()=>t({json:()=>JSON.parse(r)}))}).on("error",e)})},flatten(e,{key:r="message"}={}){var t,n={};for(t in e)n[t]="object"==typeof e[t]&&r in e[t]?e[t][r]:e[t];return n}};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ยฉ 2024โ2026 Adam Lui under the MIT license.
|
|
3
|
+
* Source: https://code.geolocatejs.org
|
|
4
|
+
* Documentation: https://docs.geolocatejs.org
|
|
5
|
+
*/
|
|
6
|
+
module.exports={async getMsgs(r="en"){var e=require(`./data${env.devMode?"":".min"}.js`);let t=e.flatten(require(`../../${env.devMode?"../_locales/en/":"data/"}messages.json`),{key:"message"});if(!r.startsWith("en")){var n=`${app.urls.jsdelivr}@${app.commitHashes.locales}/${app.name.split("/")[1]}/_locales/`;let s=n+`${r?r.replace("-","_"):"en"}/`+"messages.json",a=0;for(;a<3;)try{t=e.flatten(await(await e.fetch(s)).json(),{key:"message"});break}catch(e){if(3==++a)break;s=r.includes("-")&&1==a?s.replace(/([^_]*)_[^/]*(\/.*)/,"$1$2"):n+"en/messages.json"}}return t},getSysLang(){var e;if("win32"!=process.platform)return((e=process.env).LANG||e.LANGUAGE||e.LC_ALL||e.LC_MESSAGES||e.LC_NAME||"en").split(".")[0];try{return require("child_process").execSync("(Get-Culture).TwoLetterISOLanguageName",{shell:"powershell",encoding:"utf-8"}).trim()}catch(e){return console.error("ERROR loading system language:",e.message),"en"}}};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adamlui/geolocate",
|
|
3
|
+
"author": "Adam Lui & contributors",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"copyrightYear": "2024โ2026",
|
|
6
|
+
"cmdFormat": "geolocate [ip1] [ip2] [...] [options|commands]",
|
|
7
|
+
"urls": {
|
|
8
|
+
"docs": "https://github.com/adamlui/js-utils/tree/main/geolocate/docs",
|
|
9
|
+
"github": "https://github.com/adamlui/js-utils",
|
|
10
|
+
"jsdelivr": "https://cdn.jsdelivr.net/gh/adamlui/js-utils",
|
|
11
|
+
"npm": "https://www.npmjs.com/package/@adamlui/geolocate",
|
|
12
|
+
"src": "https://github.com/adamlui/js-utils/tree/main/geolocate/src"
|
|
13
|
+
},
|
|
14
|
+
"commitHashes": {
|
|
15
|
+
"locales": "0e30af1"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"appName": { "message": "geolocate" },
|
|
3
|
+
"appCopyright": { "message": "ยฉ 2024โ2026 Adam Lui under the MIT license" },
|
|
4
|
+
"prefix_error": { "message": "ERROR" },
|
|
5
|
+
"prefix_globalVer": { "message": "Global version" },
|
|
6
|
+
"prefix_localVer": { "message": "Local version" },
|
|
7
|
+
"prefix_source": { "message": "Source" },
|
|
8
|
+
"error_notRecognized": { "message": "not recognized" },
|
|
9
|
+
"error_invalidURL": { "message": "Invalid URL" },
|
|
10
|
+
"info_validArgs": { "message": "Valid arguments are below" },
|
|
11
|
+
"info_copying": { "message": "Copying to clipboard" },
|
|
12
|
+
"info_moreHelp": { "message": "For more help" },
|
|
13
|
+
"info_visit": { "message": "visit" },
|
|
14
|
+
"geoLabel_country": { "message": "Country" },
|
|
15
|
+
"geoLabel_region": { "message": "Region" },
|
|
16
|
+
"geoLabel_city": { "message": "City" },
|
|
17
|
+
"geoLabel_zip": { "message": "Zip" },
|
|
18
|
+
"geoLabel_lat": { "message": "Latitude" },
|
|
19
|
+
"geoLabel_lon": { "message": "Longitude" },
|
|
20
|
+
"geoLabel_timeZone": { "message": "Time zone" },
|
|
21
|
+
"helpSection_usage": { "message": "Usage" },
|
|
22
|
+
"helpSection_configOptions": { "message": "Config options" },
|
|
23
|
+
"helpSection_infoCmds": { "message": "Info commands" },
|
|
24
|
+
"optionDesc_quiet": { "message": "Suppress all logging except errors" },
|
|
25
|
+
"optionDesc_help": { "message": "Display help screen" },
|
|
26
|
+
"optionDesc_version": { "message": "Show version number" }
|
|
27
|
+
}
|
package/docs/README.md
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
<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>
|
|
9
9
|
<a href="#%EF%B8%8F-mit-license">
|
|
10
10
|
<img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
11
|
-
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.0.
|
|
12
|
-
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.0.
|
|
11
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.0.15">
|
|
12
|
+
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.0.15-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
13
13
|
<a href="https://www.npmjs.com/package/@adamlui/geolocate?activeTab=code">
|
|
14
14
|
<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>
|
|
15
|
-
<a href="https://github.com/adamlui/js-utils/blob/geolocate-2.0.
|
|
16
|
-
<img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/geolocate/dist/geolocate.min.js?branch=geolocate-2.0.
|
|
15
|
+
<a href="https://github.com/adamlui/js-utils/blob/geolocate-2.0.15/geolocate/dist/geolocate.min.js">
|
|
16
|
+
<img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/geolocate/dist/geolocate.min.js?branch=geolocate-2.0.15&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
17
17
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:geolocate/src/geolocate.js">
|
|
18
18
|
<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>
|
|
19
19
|
<a href="https://github.com/toolleeo/cli-apps#networking">
|
|
@@ -103,14 +103,14 @@ const geo = require('@adamlui/geolocate')
|
|
|
103
103
|
#### <> HTML script tag:
|
|
104
104
|
|
|
105
105
|
```html
|
|
106
|
-
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
106
|
+
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.15/dist/geolocate.min.js"></script>
|
|
107
107
|
```
|
|
108
108
|
|
|
109
109
|
#### ES6:
|
|
110
110
|
|
|
111
111
|
```js
|
|
112
112
|
(async () => {
|
|
113
|
-
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
113
|
+
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.15/dist/geolocate.min.js')
|
|
114
114
|
// Your code here...
|
|
115
115
|
})()
|
|
116
116
|
```
|
|
@@ -119,7 +119,7 @@ const geo = require('@adamlui/geolocate')
|
|
|
119
119
|
|
|
120
120
|
```js
|
|
121
121
|
...
|
|
122
|
-
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
122
|
+
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.15/dist/geolocate.min.js
|
|
123
123
|
// ==/UserScript==
|
|
124
124
|
|
|
125
125
|
// Your code here...
|
|
@@ -127,7 +127,7 @@ const geo = require('@adamlui/geolocate')
|
|
|
127
127
|
|
|
128
128
|
<br>
|
|
129
129
|
|
|
130
|
-
**๐ Note:** To always import the latest version (not recommended in production!) remove the `@2.0.
|
|
130
|
+
**๐ Note:** To always import the latest version (not recommended in production!) remove the `@2.0.15` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
|
|
131
131
|
|
|
132
132
|
<br>
|
|
133
133
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamlui/geolocate",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.15",
|
|
4
4
|
"description": "Fetch IP geolocation data from the CLI.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Adam Lui",
|
|
@@ -29,10 +29,11 @@
|
|
|
29
29
|
],
|
|
30
30
|
"main": "dist/geolocate.min.js",
|
|
31
31
|
"files": [
|
|
32
|
+
"dist/",
|
|
32
33
|
"docs/"
|
|
33
34
|
],
|
|
34
35
|
"bin": {
|
|
35
|
-
"geolocate": "dist/cli.min.js"
|
|
36
|
+
"geolocate": "dist/cli/index.min.js"
|
|
36
37
|
},
|
|
37
38
|
"directories": {
|
|
38
39
|
"lib": "./dist",
|
|
@@ -60,9 +61,10 @@
|
|
|
60
61
|
"url": "https://github.com/adamlui/js-utils/issues"
|
|
61
62
|
},
|
|
62
63
|
"dependencies": {
|
|
63
|
-
"generate-ip": "^2.4.7"
|
|
64
|
+
"generate-ip": "^2.4.7",
|
|
65
|
+
"node-clipboardy": "^1.0.3"
|
|
64
66
|
},
|
|
65
67
|
"devDependencies": {
|
|
66
|
-
"@adamlui/minify.js": "^2.1.
|
|
68
|
+
"@adamlui/minify.js": "^2.1.3"
|
|
67
69
|
}
|
|
68
70
|
}
|
package/dist/cli.min.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
/**
|
|
4
|
-
* ยฉ 2023โ2026 Adam Lui & contributors under the MIT license.
|
|
5
|
-
* Source: https://code.minify-js.org/node.js
|
|
6
|
-
* Documentation: https://docs.minify-js.org/node.js
|
|
7
|
-
*/
|
|
8
|
-
* ยฉ 2024โ2026 Adam Lui under the MIT license.
|
|
9
|
-
* Source: https://code.geolocatejs.org
|
|
10
|
-
* Documentation: https://docs.geolocatejs.org
|
|
11
|
-
*/
|
|
12
|
-
let 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="0e30af1";(async()=>{let e=require(__dirname.match(/src/)?"./geolocate":"./geolocate.min"),n=require("fs"),s=require("path"),{execSync:i,execFileSync:o}=require("child_process"),r="[0m",t="[1;97m",l="en";if("win32"==process.platform)try{l=i("(Get-Culture).TwoLetterISOLanguageName",{shell:"powershell",encoding:"utf-8"}).trim()}catch(e){console.error("ERROR loading system language:",e.message)}else{var a=process.env;l=(a.LANG||a.LANGUAGE||a.LC_ALL||a.LC_MESSAGES||a.LC_NAME||"en").split(".")[0]}let c={};var p,g,a=new Promise((i,r)=>{let t=`https://cdn.jsdelivr.net/gh/adamlui/js-utils@dcec59086231fca1628052cb45339829b112c5ff/geolocate/_locales/`,e=`${l?l.replace("-","_"):"en"}/`,a=t+e+"messages.json",c=0;v(a).then(async function o(n){try{let e=await n.json(),o={};for(var s in e)"object"==typeof e[s]&&"message"in e[s]&&(o[s]=e[s].message);i(o)}catch(e){if(3==++c)return i({});v(a=l.includes("-")&&1==c?a.replace(/([^_]*)_[^/]*(\/.*)/,"$1$2"):t+"en/messages.json").then(o).catch(r)}}).catch(r)});try{c=await a}catch(e){console.error("ERROR fetching messages: "+e.message)}let 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(`
|
|
13
|
-
${"[1;91m"+(c.prefix_error||"ERROR")}: `+`Arg [${o}] ${c.error_notRecognized||"not recognized"}.[0m`),console.info(`
|
|
14
|
-
${"[1;33m"+(c.info_validArgs||"Valid arguments are below")}.[0m`),_(["configOptions","infoCmds"]),process.exit(1)))}),process.argv.some(e=>f.infoCmds.help.test(e)))_();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(`
|
|
15
|
-
${c.prefix_globalVer||"Global version"}: `+a),console.info(`${c.prefix_localVer||"Local version"}: `+e)}else{var $,h,u=[];for($ of process.argv.slice(2))$.startsWith("-")||(h=$.replace(/[[\]]/g,""),u.push(h));a=await e.locate(u,{verbose:!m.quietMode});a||process.exit(1),m.quietMode||1!=a.length||(console.info(`
|
|
16
|
-
IP: ${t}${a[0].ip}[0m`),console.info(`${c.geoLabel_country||"Country"}: ${t}${a[0].country}${r}}`),console.info(`${c.geoLabel_region||"Region"}: ${t}${a[0].regionName}${r}}`),console.info(`${c.geoLabel_city||"City"}: ${t}${a[0].city}${r}}`),console.info(`${c.geoLabel_zip||"Zip"}: ${t}${a[0].zip}${r}}`),console.info(`${c.geoLabel_lat||"Latitude"}: ${t}${a[0].lat}${r}}`),console.info(`${c.geoLabel_lon||"Longitude"}: ${t}${a[0].lon}${r}}`),console.info(`${c.geoLabel_timeZone||"Time zone"}: ${t}${a[0].timezone.replace(/_/g," ").replace(/\//g," / ")}${r}`),console.info(`ISP: ${t}${a[0].isp}[0m}`)),g=`
|
|
17
|
-
${c.info_copying||"Copying to clipboard"}...`,m.quietMode||console.info(g),g=(g=JSON.stringify(a,void 0,2)).replace(/"/g,'""'),p={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(p[process.platform]),{input:g})}function v(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 _(e=["header","usage","configOptions","infoCmds"]){var o=`[106m[30m ${pkgName.replace(/^@[^/]+\//,"")} [0m `;let n={header:[`
|
|
18
|
-
โ `+o+(c.appCopyright||copyright),o+(c.prefix_source||"Source")+": "+srcURL],usage:[`
|
|
19
|
-
${t}o ${c.helpSection_usage||"Usage"}:[0m`,` ${t}ยป [1;92m${cmdFormat}[0m`],configOptions:[`
|
|
20
|
-
${t}o ${c.helpSection_configOptions||"Config options"}:[0m`,` -q, --quiet ${c.optionDesc_quiet||"Suppress all logging except errors"}.`],infoCmds:[`
|
|
21
|
-
${t}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(t=>n[t]?.forEach(o=>{{var r=/header|usage/.test(t)?1:29;let n=process.stdout.columns||80,s=[],e=o.match(/\S+|\s+/g),i="";e.forEach(e=>{var o=n-(s.length?r:0);i.length+"| ".length+e.length>o&&(s.push(s.length?i.trimStart():i),i=""),i+=e}),s.push(s.length?i.trimStart():i),s.forEach((e,o)=>console.info("| "+(0==o?e:" ".repeat(r)+e)))}})),console.info(`
|
|
22
|
-
${c.info_moreHelp||"For more help"}, ${c.info_visit||"visit"}: ${t}${docURL}[0m`)}})();
|