@adamlui/geolocate 2.1.0 โ 2.2.1
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 +9 -8
- package/dist/cli/index.min.js +2 -2
- package/dist/cli/lib/data.min.js +1 -1
- package/dist/cli/lib/init.min.js +6 -0
- package/dist/cli/lib/jsdelivr.min.js +6 -0
- package/dist/cli/lib/language.min.js +2 -3
- package/dist/cli/lib/log.min.js +18 -18
- package/dist/cli/lib/pkg.min.js +6 -0
- package/dist/cli/lib/settings.min.js +2 -3
- package/dist/data/geolocate.config.mjs +1 -0
- package/dist/data/messages.json +10 -8
- package/dist/data/{app.json โ package-data.json} +1 -1
- package/dist/geolocate.min.js +1 -1
- package/docs/README.md +9 -8
- package/package.json +9 -6
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.1
|
|
12
|
-
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.1
|
|
11
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.2.1">
|
|
12
|
+
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.2.1-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.1
|
|
16
|
-
<img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/geolocate/dist/geolocate.min.js?branch=geolocate-2.1
|
|
15
|
+
<a href="https://github.com/adamlui/js-utils/blob/geolocate-2.2.1/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.2.1&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">
|
|
@@ -67,6 +67,7 @@ Sample output:
|
|
|
67
67
|
|
|
68
68
|
```
|
|
69
69
|
Parameter options:
|
|
70
|
+
--ui-lang="code" ISO 639-1 code of language to display UI in.
|
|
70
71
|
--config="path/to/file" Load custom config file.
|
|
71
72
|
|
|
72
73
|
Boolean options:
|
|
@@ -123,14 +124,14 @@ const geo = require('@adamlui/geolocate')
|
|
|
123
124
|
#### <> HTML script tag:
|
|
124
125
|
|
|
125
126
|
```html
|
|
126
|
-
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.1
|
|
127
|
+
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.1/dist/geolocate.min.js"></script>
|
|
127
128
|
```
|
|
128
129
|
|
|
129
130
|
#### ES6:
|
|
130
131
|
|
|
131
132
|
```js
|
|
132
133
|
(async () => {
|
|
133
|
-
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.1
|
|
134
|
+
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.1/dist/geolocate.min.js')
|
|
134
135
|
// Your code here...
|
|
135
136
|
})()
|
|
136
137
|
```
|
|
@@ -139,7 +140,7 @@ const geo = require('@adamlui/geolocate')
|
|
|
139
140
|
|
|
140
141
|
```js
|
|
141
142
|
...
|
|
142
|
-
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.1
|
|
143
|
+
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.1/dist/geolocate.min.js
|
|
143
144
|
// ==/UserScript==
|
|
144
145
|
|
|
145
146
|
// Your code here...
|
|
@@ -147,7 +148,7 @@ const geo = require('@adamlui/geolocate')
|
|
|
147
148
|
|
|
148
149
|
<br>
|
|
149
150
|
|
|
150
|
-
**๐ Note:** To always import the latest version (not recommended in production!) remove the `@2.1
|
|
151
|
+
**๐ Note:** To always import the latest version (not recommended in production!) remove the `@2.2.1` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
|
|
151
152
|
|
|
152
153
|
<br>
|
|
153
154
|
|
package/dist/cli/index.min.js
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
|
|
5
5
|
* Documentation: https://github.com/adamlui/js-utils/tree/main/geolocate/docs
|
|
6
6
|
*/
|
|
7
|
-
(async()=>{
|
|
8
|
-
${
|
|
7
|
+
(async()=>{globalThis.env={args:process.argv.slice(2),devMode:/[\\/]src(?:[\\/]|$)/i.test(__dirname)},env.debugMode=env.args.some(e=>/^--?debug(?:-?mode)?$/.test(e)),env.modExt=`${env.devMode?"":".min"}.js`;var e=require("node-clipboardy"),i=require("../geolocate"+env.modExt),o=require("./lib/init"+env.modExt),r=require("./lib/log"+env.modExt);if(await o.cli(),cli.config.init)return o.configFile();if(cli.config.help)return r.help();if(cli.config.version)return r.version();var n,t=[];for(n of env.args)n.startsWith("-")||t.push(n.replace(/[[\]]/g,""));o=await i.locate(t,{verbose:!cli.config.quietMode});o||process.exit(1),cli.config.quietMode||1!=o.length||r.geoData(o[0]),r.ifNotQuiet(`
|
|
8
|
+
${cli.msgs.info_copyingToClip}...`),e.writeSync(JSON.stringify(o,null,2))})();
|
package/dist/cli/lib/data.min.js
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
|
|
4
4
|
* Documentation: https://github.com/adamlui/js-utils/tree/main/geolocate/docs
|
|
5
5
|
*/
|
|
6
|
-
module.exports={atomicWrite(e,r,t="utf8"){var n=require("
|
|
6
|
+
module.exports={atomicWrite(e,r,t="utf8"){var n=require("fs"),a=require("path"),a=a.join(a.dirname(e),`.${a.basename(e)}.tmp`);n.writeFileSync(a,r,t),n.renameSync(a,e)},fetch(n){return"undefined"==typeof fetch?new Promise((t,e)=>{var r=n.match(/^([^:]+):\/\//)[1];/^https?$/.test(r)||e(new Error(cli.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)}):fetch(n)},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 & contributors under the MIT license.
|
|
3
|
+
* Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
|
|
4
|
+
* Documentation: https://github.com/adamlui/js-utils/tree/main/geolocate/docs
|
|
5
|
+
*/
|
|
6
|
+
let language=require("./language"+env.modExt),log=require("./log"+env.modExt),settings=require("./settings"+env.modExt),dataPath="../../"+(env.devMode?"../":"data/");module.exports={async cli(){Object.assign(globalThis.cli??={},require(dataPath+"package-data.json")),cli.lang=settings.load("uiLang")||(env.debugMode?language.generateRandomLang({excludes:["en"]}):language.getSysLang()),cli.msgs=await language.getMsgs(cli.lang),cli.urls.cliDocs||=cli.urls.docs+"/#-command-line-usage",settings.load()},async configFile(e=settings.configFilename){var t=require("fs"),a=require("path"),i={target:a.resolve(process.cwd(),e)};if(t.existsSync(i.target))return log.warn(cli.msgs.warn_configFileExists+":",i.target);if(t.existsSync(i.src=a.resolve(__dirname,""+dataPath+e)))t.copyFileSync(i.src,i.target);else{a=require("./jsdelivr"+env.modExt).pkgVerURL+`/${e}/`;log.data(cli.msgs.info_fetchingRemoteConfigFrom+` ${a}...`);try{var s=require("./data"+env.modExt),g=await s.fetch(a);if(!g.ok)return log.warn(`${cli.msgs.warn_remoteConfigNotFound}: ${a} (${g.status})`);s.atomicWrite(i.target,await g.text())}catch(e){return log.warn(cli.msgs.warn_remoteConfigFailed+`: ${a} `+e.message)}}log.success(`${cli.msgs.info_configFileCreated}: ${i.target}\n`),log.tip(cli.msgs.tip_editToSetDefaults+"."),log.tip(cli.msgs.tip_cliArgsPrioritized+".")}};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ยฉ 2024โ2026 Adam Lui & contributors under the MIT license.
|
|
3
|
+
* Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
|
|
4
|
+
* Documentation: https://github.com/adamlui/js-utils/tree/main/geolocate/docs
|
|
5
|
+
*/
|
|
6
|
+
module.exports={pkgVerURL(e){e||=cli.version||=require("./pkg"+env.modExt).getVer("local")||"none";var l=cli.name.split("/")[1],e=/^\d+\.\d+\.\d+$/.test(e)?l+"-"+e:"latest";return cli.urls.jsdelivr+`@${e}/`+l},commitURL(e="latest"){return cli.urls.jsdelivr+`@${e}/`+cli.name.split("/")[1]}};
|
|
@@ -3,6 +3,5 @@
|
|
|
3
3
|
* Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
|
|
4
4
|
* Documentation: https://github.com/adamlui/js-utils/tree/main/geolocate/docs
|
|
5
5
|
*/
|
|
6
|
-
let data=require(
|
|
7
|
-
|
|
8
|
-
`),l},async getMsgs(t="en"){let e=data.flatten(require(`../../${env.devMode?"../_locales/en/":"data/"}messages.json`),{key:"message"});if(!t.startsWith("en")){var s=`${app.urls.jsdelivr}@${app.commitHashes.locales}/${app.name.split("/")[1]}/_locales/`;let a=s+t.replace("-","_")+"/messages.json",r=0;for(;r<3;)try{log.debug(e=data.flatten(await(await data.fetch(a)).json(),{key:"message"}));break}catch(e){if(2<++r)break;a=t.includes("-")&&1==r?a.replace(/([^_]*)_[^/]*(\/.*)/,"$1$2"):s+"en/messages.json"}}return e},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 log.error("ERROR loading system language:",e.message),"en"}}};
|
|
6
|
+
let data=require("./data"+env.modExt),log=require("./log"+env.modExt);module.exports={formatCode(e){return e.replace(/([a-z]{2,8})[-_]([a-z]{2})/i,(e,r,t)=>r.toLowerCase()+"_"+t.toUpperCase())},generateRandomLang({includes:e=[],excludes:r=[]}={}){let a=require("fs"),s=require("path"),t=e.length?e:(()=>{var e=s.join(__dirname,"..",".cache"),r=s.join(e,"locales.json");if(a.existsSync(r))try{return JSON.parse(a.readFileSync(r,"utf8"))}catch(e){}var t=s.resolve(process.cwd(),"_locales");return a.existsSync(t)?(t=a.readdirSync(t,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name).filter(e=>/^\w{2}[-_]?\w{0,2}$/.test(e)),a.mkdirSync(e,{recursive:!0}),data.atomicWrite(r,JSON.stringify(t,null,2)),t):["en"]})(),n=new Set(r),l="en";return(t=t.filter(e=>!n.has(e))).length&&(l=t[Math.floor(Math.random()*t.length)]),log.debug(`Random language: ${l}
|
|
7
|
+
`),l},async getMsgs(a="en"){if(a=module.exports.formatCode(a),env.msgs&&a==cli.lang)return env.msgs;let e=data.flatten(require(`../../${env.devMode?"../_locales/en/":"data/"}messages.json`));if(!a.startsWith("en")){var s=require("./jsdelivr"+env.modExt).commitURL(cli.commitHashes.locales)+"/_locales/";let r=s+a+"/messages.json",t=0;for(;t<3;)try{e=data.flatten(await(await data.fetch(r)).json());break}catch(e){if(3<=++t)break;log.debug(r=a.includes("-")&&1==t?r.replace(/([^_]*)_[^/]*(\/.*)/,"$1$2"):s+"en/messages.json")}}return e},getSysLang(){try{var e;return"win32"==process.platform?require("child_process").execSync("(Get-Culture).TwoLetterISOLanguageName",{shell:"powershell",encoding:"utf-8"}).trim():((e=process.env).LANG||e.LANGUAGE||e.LC_ALL||e.LC_MESSAGES||e.LC_NAME).split(".")[0]}catch(e){return log.error(cli.msgs.error_failedToFetchSysLang+":",e.message),"en"}},validateLangCode(e){return"string"==typeof e&&/^[a-z]{2,8}(?:[-_][a-z]{2,3})?$/i.test(e)}};
|
package/dist/cli/lib/log.min.js
CHANGED
|
@@ -3,21 +3,21 @@
|
|
|
3
3
|
* Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
|
|
4
4
|
* Documentation: https://github.com/adamlui/js-utils/tree/main/geolocate/docs
|
|
5
5
|
*/
|
|
6
|
-
module.exports={colors:{nc:"[0m",br:"[1;91m",by:"[1;33m",bo:"[38;5;214m",bg:"[1;92m",bw:"[1;97m",blk:"[30m",tlBG:"[106m"},configURL(){this.info(`
|
|
7
|
-
${
|
|
8
|
-
`+this.colors.bw+
|
|
9
|
-
${this.colors.
|
|
10
|
-
|
|
11
|
-
`+this.colors.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
${
|
|
16
|
-
${this.colors.bw}o ${
|
|
17
|
-
${this.colors.bw}o ${
|
|
18
|
-
${this.colors.bw}o ${
|
|
19
|
-
${
|
|
20
|
-
${
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
${
|
|
6
|
+
module.exports={colors:{nc:"[0m",br:"[1;91m",by:"[1;33m",bo:"[38;5;214m",bg:"[1;92m",bw:"[1;97m",gry:"[90m",blk:"[30m",tlBG:"[106m"},configURL(){this.info(`
|
|
7
|
+
${cli.msgs.info_exampleValidConfigFile}: `+cli.urls.config)},configURLandExit(...o){this.error(...o),this.configURL(),process.exit(1)},data(o){console.log(`
|
|
8
|
+
`+this.colors.bw+o+this.colors.nc)},debug(o){env.debugMode&&console.debug(`
|
|
9
|
+
${this.colors.bo}DEBUG:`,o,this.colors.nc,"\n")},dim(o){console.log(""+this.colors.gry+o+this.colors.nc)},error(...o){console.error(`
|
|
10
|
+
${this.colors.br}ERROR:`,...o,this.colors.nc)},errorAndExit(...o){this.error(...o),this.helpCmdAndDocURL(),process.exit(1)},ifNotQuiet(o){cli.config.quietMode||console.info(o)},info(o){console.info(`
|
|
11
|
+
`+this.colors.by+o+this.colors.nc)},tip(o){console.info(this.colors.by+"TIP: "+o+this.colors.nc)},success(o){console.log(`
|
|
12
|
+
`+this.colors.bg+o+this.colors.nc)},warn(...o){console.warn(`
|
|
13
|
+
${this.colors.bo}WARNING:`,...o,this.colors.nc)},geoData(o){console.info([`
|
|
14
|
+
IP: `+this.colors.bw+o.ip+this.colors.nc,cli.msgs.geoLabel_country+": "+this.colors.bw+o.country+this.colors.nc,cli.msgs.geoLabel_region+": "+this.colors.bw+o.regionName+this.colors.nc,cli.msgs.geoLabel_city+": "+this.colors.bw+o.city+this.colors.nc,cli.msgs.geoLabel_zip+": "+this.colors.bw+o.zip+this.colors.nc,cli.msgs.geoLabel_lat+": "+this.colors.bw+o.lat+this.colors.nc,cli.msgs.geoLabel_lon+": "+this.colors.bw+o.lon+this.colors.nc,cli.msgs.geoLabel_timeZone+": "+this.colors.bw+o.timezone.replace(/_/g," ").replace(/\//g," / ")+this.colors.nc,"ISP: "+this.colors.bw+o.isp+this.colors.nc].join("\n"))},help(o=["header","usage","params","flags","cmds"]){cli.prefix=""+this.colors.tlBG+this.colors.blk+` ${cli.name.replace(/^@[^/]+\//,"")} ${this.colors.nc} `;let s={header:[`
|
|
15
|
+
โ ${cli.prefix}${cli.msgs.appCopyright}.`,""+cli.prefix+cli.msgs.prefix_source+": "+cli.urls.src],usage:[`
|
|
16
|
+
${this.colors.bw}o ${cli.msgs.helpSection_usage}:`+this.colors.nc,` ${this.colors.bw}ยป `+this.colors.bg+cli.cmdFormat+this.colors.nc],params:[`
|
|
17
|
+
${this.colors.bw}o ${cli.msgs.helpSection_params}:`+this.colors.nc,` --ui-lang="code" ${cli.msgs.optionDesc_uiLang}.`,` --config="path/to/file" ${cli.msgs.optionDesc_config}.`],flags:[`
|
|
18
|
+
${this.colors.bw}o ${cli.msgs.helpSection_flags}:`+this.colors.nc,` -q, --quiet ${cli.msgs.optionDesc_quiet}.`],cmds:[`
|
|
19
|
+
${this.colors.bw}o ${cli.msgs.helpSection_cmds}:`+this.colors.nc,` -i, --init ${cli.msgs.optionDesc_init}.`,` -h, --help ${cli.msgs.optionDesc_help}.`,` -v, --version ${cli.msgs.optionDesc_version}.`]};o.forEach(r=>s[r]?.forEach(s=>{{var e=/header|usage/.test(r)?1:29;let i=process.stdout.columns||80,o=s.match(/\S+|\s+/g),c=[],l="";o.forEach(o=>{var s=i-(c.length?e:0);l.length+"| ".length+o.length>s&&(c.push(c.length?l.trimStart():l),l=""),l+=o}),c.push(c.length?l.trimStart():l),c.forEach((o,s)=>console.info("| "+(0==s?o:" ".repeat(e)+o)))}})),console.info(`
|
|
20
|
+
${cli.msgs.info_moreHelp}, ${cli.msgs.info_visit}: `+this.colors.bw+cli.urls.cliDocs+this.colors.nc)},helpCmdAndDocURL(){console.info(`
|
|
21
|
+
${cli.msgs.info_moreHelp}, ${cli.msgs.info_type} ${cli.name.split("/")[1]} --help' ${cli.msgs.info_or} ${cli.msgs.info_visit}
|
|
22
|
+
`+this.colors.bw+cli.urls.docs+this.colors.nc)},version(){var o=require("./pkg"+env.modExt).getVer;this.info(cli.name),this.data(`${cli.msgs.prefix_globalVer}: ${o("global")||"none"}
|
|
23
|
+
${cli.msgs.prefix_localVer}: `+(o("local")||"none"))}};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ยฉ 2024โ2026 Adam Lui & contributors under the MIT license.
|
|
3
|
+
* Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
|
|
4
|
+
* Documentation: https://github.com/adamlui/js-utils/tree/main/geolocate/docs
|
|
5
|
+
*/
|
|
6
|
+
let log=require("./log"+env.modExt);module.exports={getVer(e="any"){let r;if("global"!=e)try{var l=require("path").resolve(process.cwd(),"node_modules",cli.name,"package.json");r=require(l).version}catch(e){log.debug(cli.msgs.error_readingLocalPkgVer+": "+e.message)}if("global"==e||"all"==e&&!r)try{r=require("child_process").execSync(`npm view ${JSON.stringify(cli.name)} version`).toString().trim()}catch(e){log.debug(cli.msgs.error_failedToFetchGlobalVer+": "+e.message)}return r}};
|
|
@@ -3,6 +3,5 @@
|
|
|
3
3
|
* Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
|
|
4
4
|
* Documentation: https://github.com/adamlui/js-utils/tree/main/geolocate/docs
|
|
5
5
|
*/
|
|
6
|
-
let fs=require("fs"),log=require(
|
|
7
|
-
|
|
8
|
-
`+e.message)}return e.forEach(o=>{if(!/^[^-]|--?(?:config|debug)/.test(o)){var i=r.find(e=>this.controls[e]?.regex?.test(o)),s=(i||log.errorAndExit(`[${o}] ${app.msgs.error_notRecognized}.`),this.controls[i]);if("cmd"!=s.type){let e="param"!=s.type||o.split("=")[1]?.trim();s.mode?app.config.mode=i.replace(/mode$/i,"").toLowerCase():((s=s.parser)&&(e=s(e),isNaN(e)||e<1)&&log.errorAndExit(`[${i}] ${app.msgs.error_nonPositiveNum}.`),app.config[i]=e)}}}),app.config}};
|
|
6
|
+
let fs=require("fs"),log=require("./log"+env.modExt),path=require("path");(globalThis.cli??={}).config={},module.exports={configFilename:"geolocate.config.mjs",controls:{uiLang:{type:"param",valType:"langCode",regex:/^--?ui-?lang(?:=.*|$)/},config:{type:"param",valType:"filepath",regex:/^--?config(?:=.*|$)/},quietMode:{type:"flag",regex:/^--?q(?:uiet)?(?:-?mode)?$/},init:{type:"cmd",regex:/^-{0,2}i(?:nit)?$/},help:{type:"cmd",regex:/^--?h(?:elp)?$/},version:{type:"cmd",regex:/^--?ve?r?s?i?o?n?$/}},load(e=Object.keys(this.controls)){let t=[].concat(e);if(cli.defaultsSet||arguments.length||(t.forEach(e=>{var i=this.controls[e];i.mode||(cli.config[e]??=i.defaultVal??("param"==i.type&&""))}),cli.defaultsSet=!0),!cli.configPathTried){e=env.args.find(e=>this.controls.config.regex.test(e));if(e){/=/.test(e)||log.errorAndExit(`[${e}] `+cli.msgs.error_mustIncludePath);e=e.split("=")[1];cli.configPath=path.isAbsolute(e)?e:path.resolve(process.cwd(),e),fs.existsSync(cli.configPath)||log.configURLandExit(cli.msgs.error_configFileNotFound+":",cli.configPath)}else for(var i of[".mjs",".cjs",".js"]){i=path.resolve(process.cwd(),this.configFilename.replace(/\.[^.]+$/,i));if(fs.existsSync(i)){cli.configPath=i;break}}cli.configPathTried=!0}if(cli.configPath)try{let e=require(cli.configPath),o=e?.default??e;o&&"object"==typeof o||log.configURLandExit(cli.msgs.error_invalidConfigFile+"."),Object.assign(cli.config,arguments.length?t.reduce((e,i)=>o[i]?{...e,[i]:o[i]}:e,{}):o)}catch(e){log.configURLandExit(cli.msgs.error_failedToLoadConfigFile+":",cli.configPath,`
|
|
7
|
+
`+e.message)}return env.args.forEach(i=>{var e,o;/^[^-]|--?(?:config|debug)/.test(i)&&"init"!=i||(!(e=Object.keys(this.controls).find(e=>this.controls[e]?.regex?.test(i)))&&cli.msgs&&log.errorAndExit(`[${i}] ${cli.msgs.error_notRecognized}.`),t.includes(e)&&((o=this.controls[e]).mode?cli.config.mode=e.replace(/mode$/i,"").toLowerCase():cli.config[e]="param"!=o.type||(i.split("=")[1]?.trim()??"")))}),this.parseValidateConfig(t),1==t.length?cli.config[t[0]]:cli.config},parseValidateConfig(e=Object.keys(this.controls)){let t=require("./language"+env.modExt);for(let o of[].concat(e)){let e=this.controls[o],i=cli.config[o];e.parser&&!e.parsed&&(cli.config[o]=e.parser(i),e.parsed=!0),e.valType&&{positiveInt(){var e=parseInt(i,10);(isNaN(e)||e<1)&&log.errorAndExit(`[${o}] ${cli.msgs.error_nonPositiveNum}: `+i),cli.config[o]=e},filepath(){i&&!fs.existsSync(i)&&log.errorAndExit(`[${o}] ${cli.msgs.error_invalidFilepath}: `+i)},langCode(){i&&!t.validateLangCode(i)&&log.errorAndExit(`[${o}] ${cli.msgs.error_invalidLangCode}: `+i)}}[e.valType]()}}};
|
package/dist/data/messages.json
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"appName": { "message": "geolocate" },
|
|
3
3
|
"appCopyright": { "message": "ยฉ 2024โ2026 Adam Lui under the MIT license" },
|
|
4
|
-
"prefix_error": { "message": "ERROR" },
|
|
5
|
-
"prefix_tip": { "message": "TIP" },
|
|
6
|
-
"prefix_warning": { "message": "WARNING" },
|
|
7
4
|
"prefix_globalVer": { "message": "Global version" },
|
|
8
5
|
"prefix_localVer": { "message": "Local version" },
|
|
9
6
|
"prefix_source": { "message": "Source" },
|
|
10
7
|
"error_readingLocalPkgVer": { "message": "Error reading local package version" },
|
|
11
8
|
"error_notRecognized": { "message": "not recognized" },
|
|
12
9
|
"error_nonPositiveNum": { "message": "argument can only be > 0" },
|
|
10
|
+
"error_invalidFilepath": { "message": "must be a valid existing file path. Got" },
|
|
11
|
+
"error_invalidLangCode": { "message": "is an invalid language code" },
|
|
13
12
|
"error_invalidURL": { "message": "Invalid URL" },
|
|
14
13
|
"error_invalidConfigFile": { "message": "Config file must export an object" },
|
|
15
14
|
"error_configFileNotFound": { "message": "Config file not found" },
|
|
16
15
|
"error_failedToLoadConfigFile": { "message": "Failed to load config file" },
|
|
16
|
+
"error_failedToFetchGlobalVer": { "message": "Failed to fetch global version" },
|
|
17
|
+
"error_failedToFetchSysLang": { "message": "Failed to fetch system language" },
|
|
17
18
|
"error_mustIncludePath": { "message": "must include =path" },
|
|
18
19
|
"warn_configFileExists": { "message": "Config file already exists" },
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
20
|
+
"warn_remoteConfigNotFound": { "message": "Remote config file not found" },
|
|
21
|
+
"warn_remoteConfigFailed": { "message": "Failed to fetch remote config file" },
|
|
22
|
+
"info_exampleValidConfigFile": { "message": "Example valid config file" },
|
|
23
|
+
"info_copyingToClip": { "message": "Copying to clipboard" },
|
|
24
|
+
"info_moreHelp": { "message": "For more help" },
|
|
22
25
|
"info_type": { "message": "type" },
|
|
23
26
|
"info_or": { "message": "or" },
|
|
24
27
|
"info_visit": { "message": "visit" },
|
|
25
28
|
"info_configFileCreated": { "message": "Config file created" },
|
|
26
29
|
"info_fetchingRemoteConfigFrom": { "message": "Fetching remote config file from" },
|
|
27
|
-
"warn_remoteConfigNotFound": { "message": "Remote config file not found" },
|
|
28
|
-
"warn_remoteConfigFailed": { "message": "Failed to fetch remote config file" },
|
|
29
30
|
"tip_editToSetDefaults": { "message": "Edit this file to customize defaults" },
|
|
30
31
|
"tip_cliArgsPrioritized": { "message": "CLI arguments always override these values" },
|
|
31
32
|
"geoLabel_country": { "message": "Country" },
|
|
@@ -39,6 +40,7 @@
|
|
|
39
40
|
"helpSection_params": { "message": "Parameter options" },
|
|
40
41
|
"helpSection_flags": { "message": "Config options" },
|
|
41
42
|
"helpSection_cmds": { "message": "Commands" },
|
|
43
|
+
"optionDesc_uiLang": { "message": "ISO 639-1 code of language to display UI in" },
|
|
42
44
|
"optionDesc_config": { "message": "Load custom config file" },
|
|
43
45
|
"optionDesc_quiet": { "message": "Suppress all logging except errors" },
|
|
44
46
|
"optionDesc_init": { "message": "Create config file (in project root)" },
|
package/dist/geolocate.min.js
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
|
|
4
4
|
* Documentation: https://github.com/adamlui/js-utils/tree/main/geolocate/docs
|
|
5
5
|
*/
|
|
6
|
-
async function geolocate(e,n={}){var t,o={verbose:!0};log.prefix="geolocate()",(e=[].concat(e))[0]||=await getOwnIP();for(t of e){n.verbose&&log.info(`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=window.ipv4.validate}if(o&&!o(t,{verbose:!1}))return log.error(t+" is not a valid IPv4 address.")}if(validateOptions({options:n,defaultOptions:o,helpURL:"https://github.com/adamlui/js-utils/tree/main/geolocate/docs/#locateips-options",exampleCall:"geolocate('8.8.8.8', { verbose: false })"})){n={...o,...n};try{var l,s=[];for(l of e){n.verbose&&log.info(`Fetching geolocation data for ${l}...`);let e=await fetchData("http://ip-api.com/json/"+l),{status:o,org:t,as:r,query:a,...i}=await e.json();s.push({ip:l,...i})}return n.verbose&&"undefined"!=typeof window&&log.info("Success!","Check returned array."),s}catch(e){log.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)}async function getOwnIP(){return fetchData("https://ifconfig.me/ip").then(e=>e.text()).catch(()=>fetchData("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?log.error(r):t.trim()}catch(e){log.error(e.message)}})}function validateOptions({options:e,defaultOptions:o,helpURL:t,exampleCall:r}){var a,i,n=Object.keys(o).filter(e=>"boolean"==typeof o[e]),l=Object.keys(o).filter(e=>Number.isInteger(o[e]));if("object"!=typeof e)return a=r.split(",").findIndex(e=>e.trim().startsWith("{"))+1,a+=["st","nd","rd"][a-1]||"th",log.error(`${"0th"==a?"[O":a+" arg [o"}ptions] can only be an object of key/vals.`),log.info("Example valid call:",r),log.validOptions(o),log.helpURL(t),!1;for(i in e){if(!Object.prototype.hasOwnProperty.call(o,i))return log.error(`\`${i}\` is an invalid option.`),log.validOptions(o),log.helpURL(t),!1;if(n.includes(i)&&"boolean"!=typeof e[i])return log.error(`[${i}] option can only be \`true\` or \`false\`.`),log.helpURL(t),!1;if(l.includes(i)&&(e[i]=parseInt(e[i],10),isNaN(e[i])||e[i]<1))return log.error(`[${i}] option can only be an integer > 0.`),log.helpURL(t),!1}return!0}Object.assign(globalThis.
|
|
6
|
+
async function geolocate(e,n={}){var t,o={verbose:!0};log.prefix="geolocate()",(e=[].concat(e))[0]||=await getOwnIP();for(t of e){n.verbose&&log.info(`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=window.ipv4.validate}if(o&&!o(t,{verbose:!1}))return log.error(t+" is not a valid IPv4 address.")}if(validateOptions({options:n,defaultOptions:o,helpURL:"https://github.com/adamlui/js-utils/tree/main/geolocate/docs/#locateips-options",exampleCall:"geolocate('8.8.8.8', { verbose: false })"})){n={...o,...n};try{var l,s=[];for(l of e){n.verbose&&log.info(`Fetching geolocation data for ${l}...`);let e=await fetchData("http://ip-api.com/json/"+l),{status:o,org:t,as:r,query:a,...i}=await e.json();s.push({ip:l,...i})}return n.verbose&&"undefined"!=typeof window&&log.info("Success!","Check returned array."),s}catch(e){log.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)}async function getOwnIP(){return fetchData("https://ifconfig.me/ip").then(e=>e.text()).catch(()=>fetchData("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?log.error(r):t.trim()}catch(e){log.error(e.message)}})}function validateOptions({options:e,defaultOptions:o,helpURL:t,exampleCall:r}){var a,i,n=Object.keys(o).filter(e=>"boolean"==typeof o[e]),l=Object.keys(o).filter(e=>Number.isInteger(o[e]));if("object"!=typeof e)return a=r.split(",").findIndex(e=>e.trim().startsWith("{"))+1,a+=["st","nd","rd"][a-1]||"th",log.error(`${"0th"==a?"[O":a+" arg [o"}ptions] can only be an object of key/vals.`),log.info("Example valid call:",r),log.validOptions(o),log.helpURL(t),!1;for(i in e){if(!Object.prototype.hasOwnProperty.call(o,i))return log.error(`\`${i}\` is an invalid option.`),log.validOptions(o),log.helpURL(t),!1;if(n.includes(i)&&"boolean"!=typeof e[i])return log.error(`[${i}] option can only be \`true\` or \`false\`.`),log.helpURL(t),!1;if(l.includes(i)&&(e[i]=parseInt(e[i],10),isNaN(e[i])||e[i]<1))return log.error(`[${i}] option can only be an integer > 0.`),log.helpURL(t),!1}return!0}Object.assign(globalThis.api??={},{name:"geolocate",aliases:{geolocate:["Geolocate","geoLocate","GeoLocate","locate","Locate"]}});let log={prefix:api.name,error(...e){console.error(this.prefix+" ยป ERROR:",...e)},helpURL(e=api.urls?.docs){this.info("For more help, please visit",e)},info(...e){console.info(this.prefix+" ยป",...e)},validOptions(e){var o=Object.keys(e).join(", "),e=JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," ");this.info(`Valid options: [${o}]`),this.info("If omitted, default settings are: "+e)}};try{module.exports={geolocate:geolocate}}catch(e){}try{window.geo={geolocate:geolocate}}catch(e){}for(let o in api.aliases){try{api.aliases[o].forEach(e=>module.exports[e]??=module.exports[o])}catch(e){}try{api.aliases[o].forEach(e=>window.geo[e]??=window.geo[o])}catch(e){}}
|
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.1
|
|
12
|
-
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.1
|
|
11
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.2.1">
|
|
12
|
+
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.2.1-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.1
|
|
16
|
-
<img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/geolocate/dist/geolocate.min.js?branch=geolocate-2.1
|
|
15
|
+
<a href="https://github.com/adamlui/js-utils/blob/geolocate-2.2.1/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.2.1&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">
|
|
@@ -67,6 +67,7 @@ Sample output:
|
|
|
67
67
|
|
|
68
68
|
```
|
|
69
69
|
Parameter options:
|
|
70
|
+
--ui-lang="code" ISO 639-1 code of language to display UI in.
|
|
70
71
|
--config="path/to/file" Load custom config file.
|
|
71
72
|
|
|
72
73
|
Boolean options:
|
|
@@ -123,14 +124,14 @@ const geo = require('@adamlui/geolocate')
|
|
|
123
124
|
#### <> HTML script tag:
|
|
124
125
|
|
|
125
126
|
```html
|
|
126
|
-
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.1
|
|
127
|
+
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.1/dist/geolocate.min.js"></script>
|
|
127
128
|
```
|
|
128
129
|
|
|
129
130
|
#### ES6:
|
|
130
131
|
|
|
131
132
|
```js
|
|
132
133
|
(async () => {
|
|
133
|
-
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.1
|
|
134
|
+
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.1/dist/geolocate.min.js')
|
|
134
135
|
// Your code here...
|
|
135
136
|
})()
|
|
136
137
|
```
|
|
@@ -139,7 +140,7 @@ const geo = require('@adamlui/geolocate')
|
|
|
139
140
|
|
|
140
141
|
```js
|
|
141
142
|
...
|
|
142
|
-
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.1
|
|
143
|
+
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.1/dist/geolocate.min.js
|
|
143
144
|
// ==/UserScript==
|
|
144
145
|
|
|
145
146
|
// Your code here...
|
|
@@ -147,7 +148,7 @@ const geo = require('@adamlui/geolocate')
|
|
|
147
148
|
|
|
148
149
|
<br>
|
|
149
150
|
|
|
150
|
-
**๐ Note:** To always import the latest version (not recommended in production!) remove the `@2.1
|
|
151
|
+
**๐ Note:** To always import the latest version (not recommended in production!) remove the `@2.2.1` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
|
|
151
152
|
|
|
152
153
|
<br>
|
|
153
154
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamlui/geolocate",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Fetch IP geolocation data from the CLI.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Adam Lui",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"build:data": "node utils/build --data",
|
|
46
46
|
"build:json": "node utils/build --json",
|
|
47
47
|
"debug": "node src/cli --debug",
|
|
48
|
-
"translate": "
|
|
48
|
+
"translate": "translate-messages",
|
|
49
49
|
"bump:patch": "bash utils/bump.sh patch",
|
|
50
50
|
"bump:minor": "bash utils/bump.sh minor",
|
|
51
51
|
"bump:major": "bash utils/bump.sh major"
|
|
@@ -55,12 +55,15 @@
|
|
|
55
55
|
"url": "git+https://github.com/adamlui/js-utils.git"
|
|
56
56
|
},
|
|
57
57
|
"keywords": [
|
|
58
|
+
"api",
|
|
59
|
+
"cli",
|
|
60
|
+
"data",
|
|
58
61
|
"geolocate",
|
|
59
62
|
"geolocation",
|
|
60
63
|
"ip",
|
|
61
64
|
"networking",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
65
|
+
"sluething",
|
|
66
|
+
"utility"
|
|
64
67
|
],
|
|
65
68
|
"bugs": {
|
|
66
69
|
"url": "https://github.com/adamlui/js-utils/issues"
|
|
@@ -69,7 +72,7 @@
|
|
|
69
72
|
"node-clipboardy": "^1.0.3"
|
|
70
73
|
},
|
|
71
74
|
"devDependencies": {
|
|
72
|
-
"@adamlui/minify.js": "^2.
|
|
73
|
-
"generate-ip": "^2.
|
|
75
|
+
"@adamlui/minify.js": "^2.3.0",
|
|
76
|
+
"generate-ip": "^2.6.0"
|
|
74
77
|
}
|
|
75
78
|
}
|