@adamlui/geolocate 2.0.7 → 2.0.8
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 +6 -6
- package/dist/cli.min.js +1 -1
- package/dist/geolocate.min.js +1 -1
- package/docs/README.md +6 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
<a href="https://www.npmjs.com/package/@adamlui/geolocate"><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>
|
|
6
6
|
<a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
7
|
-
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.0.
|
|
7
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.0.8"><img height=31 src="https://img.shields.io/badge/Latest_Build-2.0.8-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
8
8
|
<a href="https://www.npmjs.com/package/@adamlui/geolocate?activeTab=code"><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>
|
|
9
|
-
<a href="https://github.com/adamlui/js-utils/blob/geolocate-2.0.
|
|
9
|
+
<a href="https://github.com/adamlui/js-utils/blob/geolocate-2.0.8/geolocate/dist/geolocate.min.js"><img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/geolocate/dist/geolocate.min.js?branch=geolocate-2.0.8&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
10
10
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:geolocate/src/geolocate.js"><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>
|
|
11
11
|
|
|
12
12
|
<br>
|
|
@@ -91,14 +91,14 @@ const geo = require('@adamlui/geolocate');
|
|
|
91
91
|
#### <> HTML script tag:
|
|
92
92
|
|
|
93
93
|
```html
|
|
94
|
-
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
94
|
+
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.8/dist/geolocate.min.js"></script>
|
|
95
95
|
```
|
|
96
96
|
|
|
97
97
|
#### ES6:
|
|
98
98
|
|
|
99
99
|
```js
|
|
100
100
|
(async () => {
|
|
101
|
-
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
101
|
+
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.8/dist/geolocate.min.js');
|
|
102
102
|
// Your code here...
|
|
103
103
|
})();
|
|
104
104
|
```
|
|
@@ -107,7 +107,7 @@ const geo = require('@adamlui/geolocate');
|
|
|
107
107
|
|
|
108
108
|
```js
|
|
109
109
|
...
|
|
110
|
-
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
110
|
+
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.8/dist/geolocate.min.js
|
|
111
111
|
// ==/UserScript==
|
|
112
112
|
|
|
113
113
|
// Your code here...
|
|
@@ -115,7 +115,7 @@ const geo = require('@adamlui/geolocate');
|
|
|
115
115
|
|
|
116
116
|
<br>
|
|
117
117
|
|
|
118
|
-
**📝 Note:** To always import the latest version (not recommended in production!) remove the `@2.0.
|
|
118
|
+
**📝 Note:** To always import the latest version (not recommended in production!) remove the `@2.0.8` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
|
|
119
119
|
|
|
120
120
|
<br>
|
|
121
121
|
|
package/dist/cli.min.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Source: https://code.geolocatejs.org
|
|
5
5
|
* Documentation: https://docs.geolocatejs.org
|
|
6
6
|
*/
|
|
7
|
-
const pkgName="@adamlui/geolocate",copyright="© 2024 Adam Lui under the MIT license.",cmdFormat="geolocate [ip1] [ip2] [...] [options|commands]",srcURL="https://code.geolocatejs.org",docURL="https://docs.geolocatejs.org/#-command-line-usage";(async()=>{const e=require(__dirname.match(/src/)?"./geolocate":"./geolocate.min"),n=require("fs"),s=require("path"),i=require("child_process")["execSync"],t="[0m",r="[1;97m";let p="en";if("win32"==process.platform)try{p=i("(Get-Culture).TwoLetterISOLanguageName",{shell:"powershell",encoding:"utf-8"}).trim()}catch(e){}else{var c=process.env;p=(c.LANG||c.LANGUAGE||c.LC_ALL||c.LC_MESSAGES||c.LC_NAME||"en").split(".")[0]}let a={};var o,c=new Promise((t,r)=>{const c="https://cdn.jsdelivr.net/gh/adamlui/js-utils@
|
|
7
|
+
const pkgName="@adamlui/geolocate",copyright="© 2024 Adam Lui under the MIT license.",cmdFormat="geolocate [ip1] [ip2] [...] [options|commands]",srcURL="https://code.geolocatejs.org",docURL="https://docs.geolocatejs.org/#-command-line-usage";(async()=>{const e=require(__dirname.match(/src/)?"./geolocate":"./geolocate.min"),n=require("fs"),s=require("path"),i=require("child_process")["execSync"],t="[0m",r="[1;97m";let p="en";if("win32"==process.platform)try{p=i("(Get-Culture).TwoLetterISOLanguageName",{shell:"powershell",encoding:"utf-8"}).trim()}catch(e){}else{var c=process.env;p=(c.LANG||c.LANGUAGE||c.LC_ALL||c.LC_MESSAGES||c.LC_NAME||"en").split(".")[0]}let a={};var o,c=new Promise((t,r)=>{const c="https://cdn.jsdelivr.net/gh/adamlui/js-utils@a5c8e2226bf51470166791e66238cb4e3ed0e2d8/geolocate/_locales/",e=(p?p.replace("-","_"):"en")+"/";let a=c+e+"messages.json",l=0;h(a).then(async function o(e){try{const n=await e.json(),s={};for(const i in n)"object"==typeof n[i]&&"message"in n[i]&&(s[i]=n[i].message);t(s)}catch(e){if(3==++l)return t({});h(a=p.includes("-")&&1==l?a.replace(/([^_]*)_[^/]*(\/.*)/,"$1$2"):c+"en/messages.json").then(o).catch(r)}}).catch(r)});try{a=await c}catch(e){}const l={},g={flags:{quietMode:/^--?q(?:uiet)?(?:-?mode)?$/},infoCmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/}};if(process.argv.forEach(o=>{var e,n;o.startsWith("-")&&(e=Object.keys(g.flags).find(e=>g.flags[e].test(o)),n=Object.keys(g.infoCmds).find(e=>g.infoCmds[e].test(o)),e?l[e]=!0:n||(console.error(`
|
|
8
8
|
${"[1;91m"+(a.prefix_error||"ERROR")}: `+`Arg [${o}] ${a.error_notRecognized||"not recognized"}.[0m`),console.info(`
|
|
9
9
|
${"[1;33m"+(a.info_validArgs||"Valid arguments are below")}.[0m`),u(["configOptions","infoCmds"]),process.exit(1)))}),process.argv.some(e=>g.infoCmds.help.test(e)))u();else if(process.argv.some(e=>g.infoCmds.version.test(e))){c=i(`npm view ${pkgName} version`).toString().trim()||"none";let e,o=process.cwd();for(;"/"!=o;){var m=s.join(o,"package.json");if(n.existsSync(m)){m=require(m);e=(m.dependencies?.[pkgName]||m.devDependencies?.[pkgName])?.match(/(\d+\.\d+\.\d+)/)[0]||"none";break}o=s.dirname(o)}console.info(`
|
|
10
10
|
${a.prefix_globalVer||"Global version"}: `+c),console.info(`${a.prefix_localVer||"Local version"}: `+e)}else{var f,d=[];for(const $ of process.argv.slice(2))$.startsWith("-")||(f=$.replace(/[[\]]/g,""),d.push(f));c=await e.locate(d,{verbose:!l.quietMode});c||process.exit(1),l.quietMode||1!=c.length||(console.info(`
|
package/dist/geolocate.min.js
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Source: https://code.geolocatejs.org
|
|
4
4
|
* Documentation: https://docs.geolocatejs.org
|
|
5
5
|
*/
|
|
6
|
-
async function geolocate(e,
|
|
6
|
+
async function geolocate(e,n={}){var o={verbose:!0};(e=Array.isArray(e)?e:[e])[0]=e[0]||await fetch("https://ifconfig.me/ip").then(e=>e.text()).catch(()=>fetch("http://ip-api.com/json/").then(e=>e.json()).then(e=>e.query)).catch(async()=>{try{var e=require("child_process")["exec"],o=require("util")["promisify"],{stdout:t,stderr:r}=await o(e)("curl -s ifconfig.me");return r?console.error("geolocate() »",r):t.trim()}catch(e){console.error("geolocate() »",e)}});for(const t of e){n.verbose&&console.info(`geolocate() » Validating ${t}...`);let o;try{o=require("generate-ip").ipv4.validate}catch(e){await import("https://cdn.jsdelivr.net/npm/generate-ip/dist/generate-ip.min.js"),o=ipv4.validate}if(o&&!o(t,{verbose:!1}))return console.error(`geolocate() » ERROR: ${t} is not a valid IPv4 address.`)}if(validateOptions(n,o,"https://docs.geolocatejs.org/#locateips-options","geolocate('8.8.8.8', { verbose: false })")){n={...o,...n};try{var c=[];for(const i of e){n.verbose&&console.info(`geolocate() » Fetching geolocation data for ${i}...`);let{status:e,org:o,as:t,query:r,...a}=await(await fetchData("http://ip-api.com/json/"+i)).json();a={ip:i,...a},c.push(a)}return!n.verbose||"undefined"!=typeof require&&/cli(?:\.min)?\.js$/.test(require.main.filename)||console.info("geolocate() » Success! Check returned array."),c}catch(e){console.error("geolocate() » ERROR:",e.message)}}}function fetchData(r){return"undefined"==typeof fetch?new Promise((t,o)=>{try{var e=r.match(/^([^:]+):\/\//)[1];/^https?$/.test(e)||o(new Error("Invalid fetchData() URL.")),require(e).get(r,e=>{let o="";e.on("data",e=>o+=e),e.on("end",()=>t({json:()=>JSON.parse(o)}))}).on("error",e=>o(new Error(e.message)))}catch(e){o(new Error("Environment not supported."))}}):fetch(r)}function validateOptions(e,o,t,r){const a=JSON.stringify(o,null,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),n=Object.keys(o).join(", "),c=Object.keys(o).filter(e=>"boolean"==typeof o[e]);let i="validateOptions() » ";try{i=validateOptions.caller?.name+"() » "}catch(e){}var s=r.split(",").findIndex(e=>e.trim().startsWith("{"))+1,l=(s+=["st","nd","rd"][s-1]||"th",()=>{console.info(`${i}Valid options: [ ${n} ]`),console.info(i+"If omitted, default settings are: "+a)}),f=()=>{console.info(i+"For more help, please visit "+t)};if("object"!=typeof e)return console.error(i+`ERROR: ${"0th"==s?"[O":s+" arg [o"}ptions] can only be an object of key/values.`),console.info(i+"Example valid call: "+r),l(),f(),!1;for(const p in e){if(!Object.prototype.hasOwnProperty.call(o,p))return console.error(`${i}ERROR: \`${p}\` is an invalid option.`),l(),f(),!1;if(c.includes(p)&&"boolean"!=typeof e[p])return console.error(`${i}ERROR: [${p}] option can only be \`true\` or \`false\`.`),f(),!1}return!0}const funcAliases={geolocate:["Geolocate","geoLocate","GeoLocate","locate","Locate"]};try{module.exports={geolocate:geolocate}}catch(e){}try{window.geo={geolocate:geolocate}}catch(e){}for(const _ in funcAliases){try{funcAliases[_].forEach(e=>module.exports[e]=module.exports[_])}catch(e){}try{funcAliases[_].forEach(e=>window.geo[e]=window.geo[_])}catch(e){}}
|
package/docs/README.md
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
<a href="https://www.npmjs.com/package/@adamlui/geolocate"><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>
|
|
6
6
|
<a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
7
|
-
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.0.
|
|
7
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.0.8"><img height=31 src="https://img.shields.io/badge/Latest_Build-2.0.8-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
8
8
|
<a href="https://www.npmjs.com/package/@adamlui/geolocate?activeTab=code"><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>
|
|
9
|
-
<a href="https://github.com/adamlui/js-utils/blob/geolocate-2.0.
|
|
9
|
+
<a href="https://github.com/adamlui/js-utils/blob/geolocate-2.0.8/geolocate/dist/geolocate.min.js"><img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/geolocate/dist/geolocate.min.js?branch=geolocate-2.0.8&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
10
10
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:geolocate/src/geolocate.js"><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>
|
|
11
11
|
|
|
12
12
|
<br>
|
|
@@ -91,14 +91,14 @@ const geo = require('@adamlui/geolocate');
|
|
|
91
91
|
#### <> HTML script tag:
|
|
92
92
|
|
|
93
93
|
```html
|
|
94
|
-
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
94
|
+
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.8/dist/geolocate.min.js"></script>
|
|
95
95
|
```
|
|
96
96
|
|
|
97
97
|
#### ES6:
|
|
98
98
|
|
|
99
99
|
```js
|
|
100
100
|
(async () => {
|
|
101
|
-
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
101
|
+
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.8/dist/geolocate.min.js');
|
|
102
102
|
// Your code here...
|
|
103
103
|
})();
|
|
104
104
|
```
|
|
@@ -107,7 +107,7 @@ const geo = require('@adamlui/geolocate');
|
|
|
107
107
|
|
|
108
108
|
```js
|
|
109
109
|
...
|
|
110
|
-
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.
|
|
110
|
+
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.0.8/dist/geolocate.min.js
|
|
111
111
|
// ==/UserScript==
|
|
112
112
|
|
|
113
113
|
// Your code here...
|
|
@@ -115,7 +115,7 @@ const geo = require('@adamlui/geolocate');
|
|
|
115
115
|
|
|
116
116
|
<br>
|
|
117
117
|
|
|
118
|
-
**📝 Note:** To always import the latest version (not recommended in production!) remove the `@2.0.
|
|
118
|
+
**📝 Note:** To always import the latest version (not recommended in production!) remove the `@2.0.8` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
|
|
119
119
|
|
|
120
120
|
<br>
|
|
121
121
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamlui/geolocate",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "Fetch IP geolocation data from the CLI.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Adam Lui",
|
|
@@ -50,6 +50,6 @@
|
|
|
50
50
|
"generate-ip": "^2.3.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@adamlui/minify.js": "^1.
|
|
53
|
+
"@adamlui/minify.js": "^1.6.1"
|
|
54
54
|
}
|
|
55
55
|
}
|