@adamlui/geolocate 2.0.15 → 2.0.16

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.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>
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>
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.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>
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>
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.15/dist/geolocate.min.js"></script>
106
+ <script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.16/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.15/dist/geolocate.min.js')
113
+ await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.16/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.15/dist/geolocate.min.js
122
+ // @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.16/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.15` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
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`
131
131
 
132
132
  <br>
133
133
 
@@ -1,17 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
3
  * © 2024–2026 Adam Lui under the MIT license.
4
- * Source: https://code.geolocatejs.org
5
- * Documentation: https://docs.geolocatejs.org
4
+ * Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
5
+ * Documentation: github.com/adamlui/js-utils/tree/main/geolocate/docs
6
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:"",br:"",by:"",bg:"",bw:""};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=` ${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)}})();
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))}})();
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * © 2024–2026 Adam Lui under the MIT license.
3
- * Source: https://code.geolocatejs.org
4
- * Documentation: https://docs.geolocatejs.org
3
+ * Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
4
+ * Documentation: github.com/adamlui/js-utils/tree/main/geolocate/docs
5
5
  */
6
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}};
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * © 2024–2026 Adam Lui under the MIT license.
3
- * Source: https://code.geolocatejs.org
4
- * Documentation: https://docs.geolocatejs.org
3
+ * Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
4
+ * Documentation: github.com/adamlui/js-utils/tree/main/geolocate/docs
5
5
  */
6
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,13 @@
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)}};
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * © 2024–2026 Adam Lui under the MIT license.
3
- * Source: https://code.geolocatejs.org
4
- * Documentation: https://docs.geolocatejs.org
3
+ * Source: https://github.com/adamlui/js-utils/tree/main/geolocate/src
4
+ * Documentation: github.com/adamlui/js-utils/tree/main/geolocate/docs
5
5
  */
6
- async function geolocate(e,n={}){let o={verbose:!0},i="geolocate() » ";(e=Array.isArray(e)?e:[e])[0]||=await fetch("https://ifconfig.me/ip").then(e=>e.text()).catch(()=>fetch("http://ip-api.com/json/").then(e=>e.json()).then(e=>e.query)).catch(async()=>{try{var e=require("child_process").exec,o=require("util").promisify,{stdout:t,stderr:r}=await o(e)("curl -s ifconfig.me");return r?console.error(i,r):t.trim()}catch(e){console.error(i,e)}});for(var t of e){n.verbose&&console.info(i+`Validating ${t}...`);let o;try{o=require("generate-ip").ipv4.validate}catch(e){await import("https://cdn.jsdelivr.net/npm/generate-ip/dist/generate-ip.min.js"),o=ipv4.validate}if(o&&!o(t,{verbose:!1}))return console.error(i+`ERROR: ${t} is not a valid IPv4 address.`)}if(validateOptions(n,o,"https://docs.geolocatejs.org/#locateips-options","geolocate('8.8.8.8', { verbose: false })")){n={...o,...n};try{var s,c=[];for(s of e){n.verbose&&console.info(i+`Fetching geolocation data for ${s}...`);let{status:e,org:o,as:t,query:r,...a}=await(await fetchData("http://ip-api.com/json/"+s)).json();a={ip:s,...a},c.push(a)}return n.verbose&&"undefined"!=typeof window&&console.info("${logPrefix}Success! Check returned array."),c}catch(e){console.error(i+"ERROR:",e.message)}}}function fetchData(r){return"undefined"==typeof fetch?new Promise((t,o)=>{try{var e=r.match(/^([^:]+):\/\//)[1];/^https?$/.test(e)||o(new Error("Invalid fetchData() URL.")),require(e).get(r,e=>{let o="";e.on("data",e=>o+=e),e.on("end",()=>t({json:()=>JSON.parse(o)}))}).on("error",e=>o(new Error(e.message)))}catch(e){o(new Error("Environment not supported."))}}):fetch(r)}function validateOptions(e,o,t,r){let a=JSON.stringify(o,void 0,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),n=Object.keys(o).join(", "),i=Object.keys(o).filter(e=>"boolean"==typeof o[e]),s=`${validateOptions.caller?.name||"validateOptions"}() » `;var c,l=r.split(",").findIndex(e=>e.trim().startsWith("{"))+1;function f(){console.info(s+`Valid options: [ ${n} ]`),console.info(s+"If omitted, default settings are: "+a)}function p(){console.info(s+"For more help, please visit "+t)}if(l+=["st","nd","rd"][l-1]||"th","object"!=typeof e)return console.error(s+`ERROR: ${"0th"==l?"[O":l+" arg [o"}ptions] can only be an object of key/values.`),console.info(s+"Example valid call: "+r),f(),p(),!1;for(c in e){if(!Object.prototype.hasOwnProperty.call(o,c))return console.error(s+`ERROR: \`${c}\` is an invalid option.`),f(),p(),!1;if(i.includes(c)&&"boolean"!=typeof e[c])return console.error(s+`ERROR: [${c}] option can only be \`true\` or \`false\`.`),p(),!1}return!0}let geoAliases={geolocate:["Geolocate","geoLocate","GeoLocate","locate","Locate"]};try{module.exports={geolocate:geolocate}}catch(e){}try{window.geo={geolocate:geolocate}}catch(e){}for(let o in geoAliases){try{geoAliases[o].forEach(e=>module.exports[e]=module.exports[o])}catch(e){}try{geoAliases[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/#-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){}}
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.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>
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>
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.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>
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>
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.15/dist/geolocate.min.js"></script>
106
+ <script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.16/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.15/dist/geolocate.min.js')
113
+ await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.16/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.15/dist/geolocate.min.js
122
+ // @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.16/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.15` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
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`
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.15",
3
+ "version": "2.0.16",
4
4
  "description": "Fetch IP geolocation data from the CLI.",
5
5
  "author": {
6
6
  "name": "Adam Lui",
@@ -61,10 +61,10 @@
61
61
  "url": "https://github.com/adamlui/js-utils/issues"
62
62
  },
63
63
  "dependencies": {
64
- "generate-ip": "^2.4.7",
65
64
  "node-clipboardy": "^1.0.3"
66
65
  },
67
66
  "devDependencies": {
68
- "@adamlui/minify.js": "^2.1.3"
67
+ "@adamlui/minify.js": "^2.1.4",
68
+ "generate-ip": "^2.4.9"
69
69
  }
70
70
  }