@adamlui/geolocate 2.0.16 โ†’ 2.2.0

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 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.16">
12
- <img height=31 src="https://img.shields.io/badge/Latest_Build-2.0.16-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
11
+ <a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.2.0">
12
+ <img height=31 src="https://img.shields.io/badge/Latest_Build-2.2.0-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/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.16&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
15
+ <a href="https://github.com/adamlui/js-utils/blob/geolocate-2.2.0/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.0&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">
@@ -66,14 +66,35 @@ Sample output:
66
66
  ### Command line options
67
67
 
68
68
  ```
69
+ Parameter options:
70
+ --ui-lang="code" ISO 639-1 code of language to display UI in.
71
+ --config="path/to/file" Load custom config file.
72
+
69
73
  Boolean options:
70
74
  -q, --quiet Suppress all logging except errors.
71
75
 
72
- Info commands:
76
+ Commands:
77
+ -i, --init Create config file (in project root).
73
78
  -h, --help Display help screen.
74
79
  -v, --version Show version number.
75
80
  ```
76
81
 
82
+ #
83
+
84
+ ### Configuration file
85
+
86
+ **generate-ip** can be customized using a `geolocate.config.mjs` or `geolocate.config.js` placed in your project root.
87
+
88
+ Example defaults:
89
+
90
+ ```js
91
+ export default {
92
+ quietMode: false // suppress all logging except errors
93
+ }
94
+ ```
95
+
96
+ ๐Ÿ’ก Run `geolocate init` to generate a template `geolocate.config.mjs` in your project root.
97
+
77
98
  <br>
78
99
 
79
100
  <img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
@@ -87,7 +108,7 @@ You can also import **geolocate** into your app to use its main API method.
87
108
  #### ECMAScript*:
88
109
 
89
110
  ```js
90
- import geo from '@adamlui/geolocate';
111
+ import geo from '@adamlui/geolocate'
91
112
  ```
92
113
 
93
114
  #### CommonJS:
@@ -103,14 +124,14 @@ const geo = require('@adamlui/geolocate')
103
124
  #### <> HTML script tag:
104
125
 
105
126
  ```html
106
- <script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.16/dist/geolocate.min.js"></script>
127
+ <script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.0/dist/geolocate.min.js"></script>
107
128
  ```
108
129
 
109
130
  #### ES6:
110
131
 
111
132
  ```js
112
133
  (async () => {
113
- await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.16/dist/geolocate.min.js')
134
+ await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.0/dist/geolocate.min.js')
114
135
  // Your code here...
115
136
  })()
116
137
  ```
@@ -119,7 +140,7 @@ const geo = require('@adamlui/geolocate')
119
140
 
120
141
  ```js
121
142
  ...
122
- // @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.16/dist/geolocate.min.js
143
+ // @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.0/dist/geolocate.min.js
123
144
  // ==/UserScript==
124
145
 
125
146
  // Your code here...
@@ -127,7 +148,7 @@ const geo = require('@adamlui/geolocate')
127
148
 
128
149
  <br>
129
150
 
130
- **๐Ÿ“ Note:** To always import the latest version (not recommended in production!) remove the `@2.0.16` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
151
+ **๐Ÿ“ Note:** To always import the latest version (not recommended in production!) remove the `@2.2.0` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
131
152
 
132
153
  <br>
133
154
 
@@ -1,11 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * ยฉ 2024โ€“2026 Adam Lui under the MIT license.
4
- * Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
5
- * Documentation: github.com/adamlui/js-utils/tree/main/geolocate/docs
3
+ * ยฉ 2024โ€“2026 Adam Lui & contributors under the MIT license.
4
+ * Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
5
+ * Documentation: https://github.com/adamlui/js-utils/tree/main/geolocate/docs
6
6
  */
7
- (async()=>{globalThis.env={devMode:__dirname.match(/[\\/]src/)};let e=require("node-clipboardy"),o=require(`../geolocate${env.devMode?"":".min"}.js`),{getMsgs:p,getSysLang:s}=require(`./lib/language${env.devMode?"":".min"}.js`),a=require(`./lib/print${env.devMode?"":".min"}.js`);if(Object.assign(globalThis.app??={},require(`../${env.devMode?"../":"./data/"}app.json`)),app.urls.docs+="/#-command-line-usage",app.msgs=await p(s()),app.colors={nc:"",br:"",by:"",bg:"",bw:"",blk:"",tlBG:""},app.regex={flags:{quietMode:/^--?q(?:uiet)?(?:-?mode)?$/},infoCmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/},version:/^[~^>=]?\d+\.\d+\.\d+$/},app.config={},process.argv.forEach(o=>{var e,p;o.startsWith("-")&&(e=Object.keys(app.regex.flags).find(e=>app.regex.flags[e].test(o)),p=Object.keys(app.regex.infoCmds).find(e=>app.regex.infoCmds[e].test(o)),e?app.config[e]=!0:p||(console.error(`
8
- ${app.colors.br}${app.msgs.prefix_error}: Arg [${o}] ${app.msgs.error_notRecognized}.`+app.colors.nc),console.info(`
9
- ${app.colors.by}${app.msgs.info_validArgs}.`+app.colors.nc),a.help(["paramOptions","infoCmds"]),process.exit(1)))}),process.argv.some(e=>app.regex.infoCmds.help.test(e)))a.help();else if(process.argv.some(e=>app.regex.infoCmds.version.test(e)))a.version();else{var r,i,c=[];for(r of process.argv.slice(2))r.startsWith("-")||(i=r.replace(/[[\]]/g,""),c.push(i));var n,l=await o.locate(c,{verbose:!app.config.quietMode});l||process.exit(1),app.config.quietMode||1!=l.length||(n=l[0],console.info([`
10
- IP: `+app.colors.bw+n.ip+app.colors.nc,app.msgs.geoLabel_country+": "+app.colors.bw+n.country+app.colors.nc,app.msgs.geoLabel_region+": "+app.colors.bw+n.regionName+app.colors.nc,app.msgs.geoLabel_city+": "+app.colors.bw+n.city+app.colors.nc,app.msgs.geoLabel_zip+": "+app.colors.bw+n.zip+app.colors.nc,app.msgs.geoLabel_lat+": "+app.colors.bw+n.lat+app.colors.nc,app.msgs.geoLabel_lon+": "+app.colors.bw+n.lon+app.colors.nc,app.msgs.geoLabel_timeZone+": "+app.colors.bw+n.timezone.replace(/_/g," ").replace(/\//g," / ")+app.colors.nc,"ISP: "+app.colors.bw+n.isp+app.colors.nc].join("\n"))),a.ifNotQuiet(`
11
- ${app.msgs.info_copying}...`),e.writeSync(JSON.stringify(l,void 0,2))}})();
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))})();
@@ -1,6 +1,6 @@
1
1
  /**
2
- * ยฉ 2024โ€“2026 Adam Lui under the MIT license.
3
- * Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
4
- * Documentation: github.com/adamlui/js-utils/tree/main/geolocate/docs
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
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}};
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]}};
@@ -1,6 +1,7 @@
1
1
  /**
2
- * ยฉ 2024โ€“2026 Adam Lui under the MIT license.
3
- * Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
4
- * Documentation: github.com/adamlui/js-utils/tree/main/geolocate/docs
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
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"}}};
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"}}};
@@ -0,0 +1,23 @@
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={colors:{nc:"",br:"",by:"",bo:"",bg:"",bw:"",gry:"",blk:"",tlBG:""},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}};
@@ -0,0 +1,7 @@
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 fs=require("fs"),log=require("./log"+env.modExt),path=require("path");(globalThis.cli??={}).config={},module.exports={configFilename:"geolocate.config.mjs",controls:{uiLang:{type:"param",regex:/^--?ui-?lang(?:=.*|$)/},config:{type:"param",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 c=[].concat(e);if(arguments.length||cli.defaultsSet||(c.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?c.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=>{if(!/^[^-]|--?(?:config|debug)/.test(i)||"init"==i){var o=Object.keys(this.controls).find(e=>this.controls[e]?.regex?.test(i));if(!o&&cli.msgs&&log.errorAndExit(`[${i}] ${cli.msgs.error_notRecognized}.`),c.includes(o)){var t=this.controls[o];if(t.mode)cli.config.mode=o.replace(/mode$/i,"").toLowerCase();else{let e="param"!=t.type||i.split("=")[1]?.trim();t=t.parser;t&&(e=t(e),isNaN(e)||e<1)&&log.errorAndExit(`[${o}] ${cli.msgs.error_nonPositiveNum}.`),cli.config[o]=e}}}}),1==c.length?cli.config[c[0]]:cli.config}};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * geolocate.config.mjs
3
+ *
4
+ * Optional config file for the geolocate CLI.
5
+ * Copy this file to your project root to set default options.
6
+ * CLI arguments always override these values.
7
+ *
8
+ * Docs: https://github.com/adamlui/js-utils/tree/main/geolocate/#-command-line-usage
9
+ */
10
+
11
+ export default {
12
+ uiLang: '', // ISO 639-1 code of language to display UI in
13
+ quietMode: false // suppress all logging except errors
14
+ }
@@ -1,16 +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
4
  "prefix_globalVer": { "message": "Global version" },
6
5
  "prefix_localVer": { "message": "Local version" },
7
6
  "prefix_source": { "message": "Source" },
7
+ "error_readingLocalPkgVer": { "message": "Error reading local package version" },
8
8
  "error_notRecognized": { "message": "not recognized" },
9
+ "error_nonPositiveNum": { "message": "argument can only be > 0" },
9
10
  "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" },
11
+ "error_invalidConfigFile": { "message": "Config file must export an object" },
12
+ "error_configFileNotFound": { "message": "Config file not found" },
13
+ "error_failedToLoadConfigFile": { "message": "Failed to load config file" },
14
+ "error_failedToFetchGlobalVer": { "message": "Failed to fetch global version" },
15
+ "error_failedToFetchSysLang": { "message": "Failed to fetch system language" },
16
+ "error_mustIncludePath": { "message": "must include =path" },
17
+ "warn_configFileExists": { "message": "Config file already exists" },
18
+ "warn_remoteConfigNotFound": { "message": "Remote config file not found" },
19
+ "warn_remoteConfigFailed": { "message": "Failed to fetch remote config file" },
20
+ "info_exampleValidConfigFile": { "message": "Example valid config file" },
21
+ "info_copyingToClip": { "message": "Copying to clipboard" },
22
+ "info_moreHelp": { "message": "For more help" },
23
+ "info_type": { "message": "type" },
24
+ "info_or": { "message": "or" },
13
25
  "info_visit": { "message": "visit" },
26
+ "info_configFileCreated": { "message": "Config file created" },
27
+ "info_fetchingRemoteConfigFrom": { "message": "Fetching remote config file from" },
28
+ "tip_editToSetDefaults": { "message": "Edit this file to customize defaults" },
29
+ "tip_cliArgsPrioritized": { "message": "CLI arguments always override these values" },
14
30
  "geoLabel_country": { "message": "Country" },
15
31
  "geoLabel_region": { "message": "Region" },
16
32
  "geoLabel_city": { "message": "City" },
@@ -19,9 +35,13 @@
19
35
  "geoLabel_lon": { "message": "Longitude" },
20
36
  "geoLabel_timeZone": { "message": "Time zone" },
21
37
  "helpSection_usage": { "message": "Usage" },
22
- "helpSection_configOptions": { "message": "Config options" },
23
- "helpSection_infoCmds": { "message": "Info commands" },
38
+ "helpSection_params": { "message": "Parameter options" },
39
+ "helpSection_flags": { "message": "Config options" },
40
+ "helpSection_cmds": { "message": "Commands" },
41
+ "optionDesc_uiLang": { "message": "ISO 639-1 code of language to display UI in" },
42
+ "optionDesc_config": { "message": "Load custom config file" },
24
43
  "optionDesc_quiet": { "message": "Suppress all logging except errors" },
44
+ "optionDesc_init": { "message": "Create config file (in project root)" },
25
45
  "optionDesc_help": { "message": "Display help screen" },
26
46
  "optionDesc_version": { "message": "Show version number" }
27
47
  }
@@ -5,6 +5,7 @@
5
5
  "copyrightYear": "2024โ€“2026",
6
6
  "cmdFormat": "geolocate [ip1] [ip2] [...] [options|commands]",
7
7
  "urls": {
8
+ "config": "https://github.com/adamlui/js-utils/blob/main/geolocate/geolocate-ip.config.mjs",
8
9
  "docs": "https://github.com/adamlui/js-utils/tree/main/geolocate/docs",
9
10
  "github": "https://github.com/adamlui/js-utils",
10
11
  "jsdelivr": "https://cdn.jsdelivr.net/gh/adamlui/js-utils",
@@ -12,6 +13,6 @@
12
13
  "src": "https://github.com/adamlui/js-utils/tree/main/geolocate/src"
13
14
  },
14
15
  "commitHashes": {
15
- "locales": "0e30af1"
16
+ "locales": "c20c989"
16
17
  }
17
18
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
- * ยฉ 2024โ€“2026 Adam Lui under the MIT license.
3
- * Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
4
- * Documentation: github.com/adamlui/js-utils/tree/main/geolocate/docs
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
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/#-command-line-usage/#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 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?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.app??={},{name:"geolocate",aliases:{geolocate:["Geolocate","geoLocate","GeoLocate","locate","Locate"]}});let log={prefix:app.name,error(...e){console.error(this.prefix+" ยป ERROR:",...e)},helpURL(e=app.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,void 0,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 app.aliases){try{app.aliases[o].forEach(e=>module.exports[e]=module.exports[o])}catch(e){}try{app.aliases[o].forEach(e=>window.geo[e]=window.geo[o])}catch(e){}}
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.0.16">
12
- <img height=31 src="https://img.shields.io/badge/Latest_Build-2.0.16-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
11
+ <a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.2.0">
12
+ <img height=31 src="https://img.shields.io/badge/Latest_Build-2.2.0-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/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.16&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
15
+ <a href="https://github.com/adamlui/js-utils/blob/geolocate-2.2.0/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.0&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">
@@ -66,14 +66,35 @@ Sample output:
66
66
  ### Command line options
67
67
 
68
68
  ```
69
+ Parameter options:
70
+ --ui-lang="code" ISO 639-1 code of language to display UI in.
71
+ --config="path/to/file" Load custom config file.
72
+
69
73
  Boolean options:
70
74
  -q, --quiet Suppress all logging except errors.
71
75
 
72
- Info commands:
76
+ Commands:
77
+ -i, --init Create config file (in project root).
73
78
  -h, --help Display help screen.
74
79
  -v, --version Show version number.
75
80
  ```
76
81
 
82
+ #
83
+
84
+ ### Configuration file
85
+
86
+ **generate-ip** can be customized using a `geolocate.config.mjs` or `geolocate.config.js` placed in your project root.
87
+
88
+ Example defaults:
89
+
90
+ ```js
91
+ export default {
92
+ quietMode: false // suppress all logging except errors
93
+ }
94
+ ```
95
+
96
+ ๐Ÿ’ก Run `geolocate init` to generate a template `geolocate.config.mjs` in your project root.
97
+
77
98
  <br>
78
99
 
79
100
  <img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
@@ -87,7 +108,7 @@ You can also import **geolocate** into your app to use its main API method.
87
108
  #### ECMAScript*:
88
109
 
89
110
  ```js
90
- import geo from '@adamlui/geolocate';
111
+ import geo from '@adamlui/geolocate'
91
112
  ```
92
113
 
93
114
  #### CommonJS:
@@ -103,14 +124,14 @@ const geo = require('@adamlui/geolocate')
103
124
  #### <> HTML script tag:
104
125
 
105
126
  ```html
106
- <script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.16/dist/geolocate.min.js"></script>
127
+ <script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.0/dist/geolocate.min.js"></script>
107
128
  ```
108
129
 
109
130
  #### ES6:
110
131
 
111
132
  ```js
112
133
  (async () => {
113
- await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.16/dist/geolocate.min.js')
134
+ await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.0/dist/geolocate.min.js')
114
135
  // Your code here...
115
136
  })()
116
137
  ```
@@ -119,7 +140,7 @@ const geo = require('@adamlui/geolocate')
119
140
 
120
141
  ```js
121
142
  ...
122
- // @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.16/dist/geolocate.min.js
143
+ // @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.0/dist/geolocate.min.js
123
144
  // ==/UserScript==
124
145
 
125
146
  // Your code here...
@@ -127,7 +148,7 @@ const geo = require('@adamlui/geolocate')
127
148
 
128
149
  <br>
129
150
 
130
- **๐Ÿ“ Note:** To always import the latest version (not recommended in production!) remove the `@2.0.16` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
151
+ **๐Ÿ“ Note:** To always import the latest version (not recommended in production!) remove the `@2.2.0` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
131
152
 
132
153
  <br>
133
154
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/geolocate",
3
- "version": "2.0.16",
3
+ "version": "2.2.0",
4
4
  "description": "Fetch IP geolocation data from the CLI.",
5
5
  "author": {
6
6
  "name": "Adam Lui",
@@ -40,7 +40,12 @@
40
40
  "doc": "./docs"
41
41
  },
42
42
  "scripts": {
43
- "build": "bash utils/build.sh",
43
+ "build": "node utils/build",
44
+ "build:js": "node utils/build --js",
45
+ "build:data": "node utils/build --data",
46
+ "build:json": "node utils/build --json",
47
+ "debug": "node src/cli --debug",
48
+ "translate": "py utils/translate-en-messages.py",
44
49
  "bump:patch": "bash utils/bump.sh patch",
45
50
  "bump:minor": "bash utils/bump.sh minor",
46
51
  "bump:major": "bash utils/bump.sh major"
@@ -50,12 +55,15 @@
50
55
  "url": "git+https://github.com/adamlui/js-utils.git"
51
56
  },
52
57
  "keywords": [
58
+ "api",
59
+ "cli",
60
+ "data",
53
61
  "geolocate",
54
62
  "geolocation",
55
63
  "ip",
56
64
  "networking",
57
- "api",
58
- "cli"
65
+ "sluething",
66
+ "utility"
59
67
  ],
60
68
  "bugs": {
61
69
  "url": "https://github.com/adamlui/js-utils/issues"
@@ -64,7 +72,7 @@
64
72
  "node-clipboardy": "^1.0.3"
65
73
  },
66
74
  "devDependencies": {
67
- "@adamlui/minify.js": "^2.1.4",
68
- "generate-ip": "^2.4.9"
75
+ "@adamlui/minify.js": "^2.2.1",
76
+ "generate-ip": "^2.5.0"
69
77
  }
70
78
  }
@@ -1,13 +0,0 @@
1
- /**
2
- * ยฉ 2024โ€“2026 Adam Lui under the MIT license.
3
- * Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
4
- * Documentation: github.com/adamlui/js-utils/tree/main/geolocate/docs
5
- */
6
- module.exports={help(p=["header","usage","configOptions","infoCmds"]){app.prefix=""+app.colors.tlBG+app.colors.blk+` ${app.name.replace(/^@[^/]+\//,"")} ${app.colors.nc} `;let e={header:[`
7
- โ”œ ${app.prefix}${app.msgs.appCopyright||`ยฉ ${app.copyrightYear} ${app.author} under the ${app.license} license`}.`,""+app.prefix+app.msgs.prefix_source+": "+app.urls.src],usage:[`
8
- ${app.colors.bw}o ${app.msgs.helpSection_usage}:`+app.colors.nc,` ${app.colors.bw}ยป `+app.colors.bg+app.cmdFormat+app.colors.nc],configOptions:[`
9
- ${app.colors.bw}o ${app.msgs.helpSection_configOptions}:`+app.colors.nc,` -q, --quiet ${app.msgs.optionDesc_quiet}.`],infoCmds:[`
10
- ${app.colors.bw}o ${app.msgs.helpSection_infoCmds}:`+app.colors.nc," -h, --help "+app.msgs.optionDesc_help,` -v, --version ${app.msgs.optionDesc_version}.`]};p.forEach(n=>e[n]?.forEach(e=>{{var r=/header|usage/.test(n)?1:29;let o=process.stdout.columns||80,s=[],p=e.match(/\S+|\s+/g),a="";p.forEach(p=>{var e=o-(s.length?r:0);a.length+"| ".length+p.length>e&&(s.push(s.length?a.trimStart():a),a=""),a+=p}),s.push(s.length?a.trimStart():a),s.forEach((p,e)=>console.info("| "+(0==e?p:" ".repeat(r)+p)))}})),console.info(`
11
- ${app.msgs.info_moreHelp}, ${app.msgs.info_visit}: `+app.colors.bw+app.urls.docs+app.colors.nc)},ifNotQuiet(p){app.config.quietMode||console.info(p)},version(){var p=require("path"),e=require("child_process").execSync(`npm view ${JSON.stringify(app.name)} version`).toString().trim()||"none";let o,s=process.cwd();for(;"/"!=s;){var a=p.join(s,"package.json");if(require("fs").existsSync(a)){a=require(a);o=(a.dependencies?.[app.name]||a.devDependencies?.[app.name])?.match(/^[~^>=]?\d+\.\d+\.\d+$/)?.[1]||"none";break}s=p.dirname(s)}console.info(`
12
- ${app.msgs.prefix_globalVer}: ${e}
13
- ${app.msgs.prefix_localVer}: `+o)}};