@adamlui/geolocate 2.2.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 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.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>
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.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>
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">
@@ -124,14 +124,14 @@ const geo = require('@adamlui/geolocate')
124
124
  #### <> HTML script tag:
125
125
 
126
126
  ```html
127
- <script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.0/dist/geolocate.min.js"></script>
127
+ <script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.1/dist/geolocate.min.js"></script>
128
128
  ```
129
129
 
130
130
  #### ES6:
131
131
 
132
132
  ```js
133
133
  (async () => {
134
- await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.0/dist/geolocate.min.js')
134
+ await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.1/dist/geolocate.min.js')
135
135
  // Your code here...
136
136
  })()
137
137
  ```
@@ -140,7 +140,7 @@ const geo = require('@adamlui/geolocate')
140
140
 
141
141
  ```js
142
142
  ...
143
- // @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.0/dist/geolocate.min.js
143
+ // @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.1/dist/geolocate.min.js
144
144
  // ==/UserScript==
145
145
 
146
146
  // Your code here...
@@ -148,7 +148,7 @@ const geo = require('@adamlui/geolocate')
148
148
 
149
149
  <br>
150
150
 
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`
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`
152
152
 
153
153
  <br>
154
154
 
@@ -4,4 +4,4 @@
4
4
  * Documentation: https://github.com/adamlui/js-utils/tree/main/geolocate/docs
5
5
  */
6
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"}}};
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)}};
@@ -3,5 +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("./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}};
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]()}}};
@@ -7,6 +7,8 @@
7
7
  "error_readingLocalPkgVer": { "message": "Error reading local package version" },
8
8
  "error_notRecognized": { "message": "not recognized" },
9
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" },
10
12
  "error_invalidURL": { "message": "Invalid URL" },
11
13
  "error_invalidConfigFile": { "message": "Config file must export an object" },
12
14
  "error_configFileNotFound": { "message": "Config file not found" },
@@ -13,6 +13,6 @@
13
13
  "src": "https://github.com/adamlui/js-utils/tree/main/geolocate/src"
14
14
  },
15
15
  "commitHashes": {
16
- "locales": "c20c989"
16
+ "locales": "69618f8"
17
17
  }
18
18
  }
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.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>
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.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>
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">
@@ -124,14 +124,14 @@ const geo = require('@adamlui/geolocate')
124
124
  #### <> HTML script tag:
125
125
 
126
126
  ```html
127
- <script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.0/dist/geolocate.min.js"></script>
127
+ <script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.1/dist/geolocate.min.js"></script>
128
128
  ```
129
129
 
130
130
  #### ES6:
131
131
 
132
132
  ```js
133
133
  (async () => {
134
- await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.0/dist/geolocate.min.js')
134
+ await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.1/dist/geolocate.min.js')
135
135
  // Your code here...
136
136
  })()
137
137
  ```
@@ -140,7 +140,7 @@ const geo = require('@adamlui/geolocate')
140
140
 
141
141
  ```js
142
142
  ...
143
- // @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.0/dist/geolocate.min.js
143
+ // @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.2.1/dist/geolocate.min.js
144
144
  // ==/UserScript==
145
145
 
146
146
  // Your code here...
@@ -148,7 +148,7 @@ const geo = require('@adamlui/geolocate')
148
148
 
149
149
  <br>
150
150
 
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`
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`
152
152
 
153
153
  <br>
154
154
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/geolocate",
3
- "version": "2.2.0",
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": "py utils/translate-en-messages.py",
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"
@@ -72,7 +72,7 @@
72
72
  "node-clipboardy": "^1.0.3"
73
73
  },
74
74
  "devDependencies": {
75
- "@adamlui/minify.js": "^2.2.1",
76
- "generate-ip": "^2.5.0"
75
+ "@adamlui/minify.js": "^2.3.0",
76
+ "generate-ip": "^2.6.0"
77
77
  }
78
78
  }