@adamlui/geolocate 2.3.1 → 2.4.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 +24 -26
- package/dist/cli/index.js +5 -9
- package/dist/cli/lib/init.js +13 -5
- package/dist/cli/lib/jsdelivr.js +2 -2
- package/dist/cli/lib/language.js +19 -12
- package/dist/cli/lib/log.js +4 -4
- package/dist/cli/lib/settings.js +6 -4
- package/dist/data/package-data.json +2 -1
- package/docs/README.md +24 -26
- package/docs/SECURITY.md +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
<a id="top"></a>
|
|
2
2
|
|
|
3
|
-
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
3
|
+
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d3424a/geolocate/assets/images/icons/wire-globe/white/icon32.png"><img height=28 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d3424a/geolocate/assets/images/icons/wire-globe/black/icon32.png"></picture> geolocate
|
|
4
4
|
|
|
5
5
|
### Fetch IP geolocation data from the CLI.
|
|
6
6
|
|
|
7
|
-
<a href="https://
|
|
7
|
+
<a href="https://npmstar.com/compare/@adamlui%2Fgeolocate">
|
|
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.
|
|
12
|
-
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.
|
|
11
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.4.1">
|
|
12
|
+
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.4.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="#">
|
|
16
|
-
<img height=31 src="https://img.shields.io/bundlejs/size/%40adamlui%2Fgeolocate%402.2.1?label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
17
15
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:geolocate/src/geolocate.js">
|
|
18
16
|
<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
|
-
<a href="https://github.com/toolleeo/cli-apps
|
|
17
|
+
<a href="https://github.com/toolleeo/cli-apps/#networking">
|
|
20
18
|
<img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-ff69b4?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
21
19
|
|
|
22
20
|
<br>
|
|
23
21
|
|
|
24
|
-
<img height=6px width="100%" src="https://
|
|
22
|
+
<img height=6px width="100%" src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/separators/aqua-gradient.png">
|
|
25
23
|
|
|
26
24
|
## ⚡ Installation
|
|
27
25
|
|
|
@@ -45,9 +43,9 @@ $ npm install @adamlui/geolocate
|
|
|
45
43
|
|
|
46
44
|
<br>
|
|
47
45
|
|
|
48
|
-
<a href="https://github.com/sponsors/adamlui"><img src="https://
|
|
46
|
+
<a href="https://github.com/sponsors/adamlui"><img src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/banners/sponsor/$10/banner1660x260.png"></a>
|
|
49
47
|
|
|
50
|
-
<img height=6px width="100%" src="https://
|
|
48
|
+
<img height=6px width="100%" src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/separators/aqua-gradient.png">
|
|
51
49
|
|
|
52
50
|
## 💻 Command line usage
|
|
53
51
|
|
|
@@ -59,7 +57,7 @@ $ geolocate [ip1] [ip2] [...]
|
|
|
59
57
|
|
|
60
58
|
Sample output:
|
|
61
59
|
|
|
62
|
-
<img src="https://
|
|
60
|
+
<img src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d3424a/geolocate/assets/images/screenshots/cli/geolocate-8.8.8.8-cmd-output.png">
|
|
63
61
|
|
|
64
62
|
**📝 Note:** If no IPv4 address is passed, your own one will be used.
|
|
65
63
|
|
|
@@ -99,13 +97,13 @@ export default {
|
|
|
99
97
|
|
|
100
98
|
<br>
|
|
101
99
|
|
|
102
|
-
<img height=6px width="100%" src="https://
|
|
100
|
+
<img height=6px width="100%" src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/separators/aqua-gradient.png">
|
|
103
101
|
|
|
104
102
|
## 🔌 Importing the API
|
|
105
103
|
|
|
106
104
|
You can also import **geolocate** into your app to use its main API method.
|
|
107
105
|
|
|
108
|
-
### <img height=18 src="https://
|
|
106
|
+
### <img height=18 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/icons/platforms/node.js/icon25x28.png"> Node.js
|
|
109
107
|
|
|
110
108
|
#### ECMAScript*:
|
|
111
109
|
|
|
@@ -121,28 +119,28 @@ const geo = require('@adamlui/geolocate')
|
|
|
121
119
|
|
|
122
120
|
###### _*Node.js version 14 or higher required_
|
|
123
121
|
|
|
124
|
-
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
122
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/icons/platforms/web/light/icon25.png"><img width=16 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/icons/platforms/web/dark/icon25.png"></picture> Web
|
|
125
123
|
|
|
126
124
|
#### <> HTML script tag:
|
|
127
125
|
|
|
128
126
|
```html
|
|
129
|
-
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.
|
|
127
|
+
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.4.1/dist/geolocate.min.js"></script>
|
|
130
128
|
```
|
|
131
129
|
|
|
132
130
|
#### ES6:
|
|
133
131
|
|
|
134
132
|
```js
|
|
135
133
|
(async () => {
|
|
136
|
-
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.
|
|
134
|
+
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.4.1/dist/geolocate.min.js')
|
|
137
135
|
// Your code here...
|
|
138
136
|
})()
|
|
139
137
|
```
|
|
140
138
|
|
|
141
|
-
### <img height=17 src="https://
|
|
139
|
+
### <img height=17 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/icons/platforms/tampermonkey/icon28.png"><img height=17.5 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/icons/platforms/violentmonkey/icon25.png"> Greasemonkey
|
|
142
140
|
|
|
143
141
|
```js
|
|
144
142
|
...
|
|
145
|
-
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.
|
|
143
|
+
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.4.1/dist/geolocate.min.js
|
|
146
144
|
// ==/UserScript==
|
|
147
145
|
|
|
148
146
|
// Your code here...
|
|
@@ -150,11 +148,11 @@ const geo = require('@adamlui/geolocate')
|
|
|
150
148
|
|
|
151
149
|
<br>
|
|
152
150
|
|
|
153
|
-
**📝 Note:** To always import the latest version (not recommended in production!) remove the `@2.
|
|
151
|
+
**📝 Note:** To always import the latest version (not recommended in production!) remove the `@2.4.1` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
|
|
154
152
|
|
|
155
153
|
<br>
|
|
156
154
|
|
|
157
|
-
<img height=6px width="100%" src="https://
|
|
155
|
+
<img height=6px width="100%" src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/separators/aqua-gradient.png">
|
|
158
156
|
|
|
159
157
|
## 📋 API usage
|
|
160
158
|
|
|
@@ -205,7 +203,7 @@ Name | Type | Description | Default Value
|
|
|
205
203
|
|
|
206
204
|
<br>
|
|
207
205
|
|
|
208
|
-
<img height=6px width="100%" src="https://
|
|
206
|
+
<img height=6px width="100%" src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/separators/aqua-gradient.png">
|
|
209
207
|
|
|
210
208
|
## 🏛️ MIT License
|
|
211
209
|
|
|
@@ -219,11 +217,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
219
217
|
|
|
220
218
|
<br>
|
|
221
219
|
|
|
222
|
-
<img height=6px width="100%" src="https://
|
|
220
|
+
<img height=6px width="100%" src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/separators/aqua-gradient.png">
|
|
223
221
|
|
|
224
222
|
## 🛠️ Related utilities
|
|
225
223
|
|
|
226
|
-
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
224
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/adamlui/js-utils@5c34563/generate-ip/assets/images/icons/node-graph/white/icon55x49.png"><img height=21 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@5c34563/generate-ip/assets/images/icons/node-graph/black/icon55x49.png"></picture> [generate-ip](https://js-utils.org/generate-ip) <a href="https://github.com/toolleeo/cli-apps/#networking"><img height=18 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/badges/awesome/badge.svg"></a>
|
|
227
225
|
|
|
228
226
|
> Randomly generate, format, and validate IPv4 + IPv6 + MAC addresses.
|
|
229
227
|
<br>[Install](https://docs.generate-ip.org/#-installation) /
|
|
@@ -232,7 +230,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
232
230
|
[CLI usage](https://docs.generate-ip.org/#-command-line-usage) /
|
|
233
231
|
[Discuss](https://github.com/adamlui/js-utils/discussions)
|
|
234
232
|
|
|
235
|
-
### [🔒 generate-pw](../generate-pw) <a href="https://github.com/toolleeo/cli-apps
|
|
233
|
+
### [🔒 generate-pw](../generate-pw) <a href="https://github.com/toolleeo/cli-apps/#password-managers"><img height=18 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/badges/awesome/badge.svg"></a>
|
|
236
234
|
|
|
237
235
|
> Randomly generate, strengthen, and validate cryptographically-secure passwords.
|
|
238
236
|
<br>[Install](https://docs.generatepw.org/#-installation) /
|
|
@@ -243,8 +241,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
243
241
|
|
|
244
242
|
<br>
|
|
245
243
|
|
|
246
|
-
<img height=6px width="100%" src="https://
|
|
244
|
+
<img height=6px width="100%" src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/separators/aqua-gradient.png">
|
|
247
245
|
|
|
248
|
-
<picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
246
|
+
<picture><source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/icons/home/white/icon32x27.png"><img height=13 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/icons/home/dark-gray/icon32x27.png"></picture> <a href="https://js-utils.org">**More JavaScript utilities**</a> /
|
|
249
247
|
<a href="https://github.com/adamlui/js-utils/discussions">Discuss</a> /
|
|
250
248
|
<a href="#top">Back to top ↑</a>
|
package/dist/cli/index.js
CHANGED
|
@@ -3,18 +3,14 @@
|
|
|
3
3
|
(async () => {
|
|
4
4
|
'use strict'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
paths: { lib: './lib' }
|
|
10
|
-
}
|
|
11
|
-
env.modes.debug = env.args.some(arg => /^--?(?:V|debug(?:[-_]?mode)?)$/.test(arg))
|
|
6
|
+
// Init ENV
|
|
7
|
+
const init = require('./lib/init')
|
|
8
|
+
init.env()
|
|
12
9
|
|
|
13
10
|
// Import LIBS
|
|
14
|
-
globalThis.log = require(
|
|
11
|
+
globalThis.log = require('./lib/log')
|
|
15
12
|
const clipboardy = require('node-clipboardy'),
|
|
16
|
-
geo = require(`../geolocate${ env.modes.dev ? '' : '.min' }.js`)
|
|
17
|
-
init = require(`${env.paths.lib}/init`)
|
|
13
|
+
geo = require(`../geolocate${ env.modes.dev ? '' : '.min' }.js`)
|
|
18
14
|
|
|
19
15
|
await init.cli()
|
|
20
16
|
|
package/dist/cli/lib/init.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
const language = require('./language'),
|
|
2
2
|
settings = require('./settings')
|
|
3
3
|
|
|
4
|
-
const dataPath = `../../${ env.modes.dev ? '../' : 'data/' }`
|
|
5
|
-
|
|
6
4
|
module.exports = {
|
|
7
5
|
|
|
8
6
|
async cli() {
|
|
9
|
-
Object.assign(globalThis.cli ??= {}, require(`${
|
|
7
|
+
Object.assign(globalThis.cli ??= {}, require(`${env.paths.libData}/package-data.json`))
|
|
10
8
|
cli.msgs = await language.getMsgs('en')
|
|
11
9
|
cli.msgs = await language.getMsgs(cli.lang = settings.load('uiLang') || (
|
|
12
10
|
env.modes.debug ? language.generateRandomLang({ excludes: ['en'] }) : language.getSysLang() ))
|
|
@@ -21,11 +19,11 @@ module.exports = {
|
|
|
21
19
|
|
|
22
20
|
if (fs.existsSync(paths.target)) // use existing config file
|
|
23
21
|
return log.warn(`${cli.msgs.warn_configFileExists}:`, paths.target)
|
|
24
|
-
if (fs.existsSync(paths.src = path.resolve(__dirname, `${
|
|
22
|
+
if (fs.existsSync(paths.src = path.resolve(__dirname, `${env.paths.libData}/${filename}`)))
|
|
25
23
|
fs.copyFileSync(paths.src, paths.target) // use found template
|
|
26
24
|
|
|
27
25
|
else { // use jsDelivr copy
|
|
28
|
-
const jsdURL = `${require('./jsdelivr').
|
|
26
|
+
const jsdURL = `${require('./jsdelivr').getPkgVerURL()}/${filename}`
|
|
29
27
|
log.data(`${cli.msgs.info_fetchingRemoteConfigFrom} ${jsdURL}...`)
|
|
30
28
|
try {
|
|
31
29
|
const data = require('./data'),
|
|
@@ -39,5 +37,15 @@ module.exports = {
|
|
|
39
37
|
log.success(`${cli.msgs.info_configFileCreated}: ${paths.target}\n`)
|
|
40
38
|
log.tip(`${cli.msgs.tip_editToSetDefaults}.`)
|
|
41
39
|
log.tip(`${cli.msgs.tip_cliArgsPrioritized}.`)
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
env() {
|
|
43
|
+
Object.assign(globalThis.env ??= {}, {
|
|
44
|
+
args: process.argv.slice(2),
|
|
45
|
+
modes: { dev: /[\\/]src(?:[\\/]|$)/i.test(__dirname) },
|
|
46
|
+
supports: { unicode: require('is-unicode-supported').default() }
|
|
47
|
+
})
|
|
48
|
+
env.modes.debug = env.args.some(arg => /^--?(?:V|debug(?:[-_]?mode)?)$/.test(arg))
|
|
49
|
+
env.paths = { libData: `../../${ env.modes.dev ? '..' : 'data' }` }
|
|
42
50
|
}
|
|
43
51
|
}
|
package/dist/cli/lib/jsdelivr.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
getPkgVerURL(version) {
|
|
4
4
|
version ||= cli.version ||= require('./pkg').getVer('local') || 'none'
|
|
5
5
|
const pkgName = cli.name.split('/')[1],
|
|
6
6
|
verTag = !/^\d+\.\d+\.\d+$/.test(version) ? 'latest' : `${pkgName}-${version}`
|
|
7
7
|
return `${cli.urls.jsdelivr}@${verTag}/${pkgName}`
|
|
8
8
|
},
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
getCommitURL(hash = 'latest') { return `${cli.urls.jsdelivr}@${hash}/${cli.name.split('/')[1]}` }
|
|
11
11
|
}
|
package/dist/cli/lib/language.js
CHANGED
|
@@ -13,13 +13,13 @@ module.exports = {
|
|
|
13
13
|
let locales = includes.length ? includes : (() => {
|
|
14
14
|
|
|
15
15
|
// Read cache if found
|
|
16
|
-
const cacheDir = path.join(__dirname, '
|
|
16
|
+
const cacheDir = path.join(__dirname, '../../.cache'),
|
|
17
17
|
localeCache = path.join(cacheDir, 'locales.json')
|
|
18
18
|
if (fs.existsSync(localeCache))
|
|
19
19
|
try { return JSON.parse(fs.readFileSync(localeCache, 'utf8')) } catch (err) {}
|
|
20
20
|
|
|
21
21
|
// Discover pkg _locales
|
|
22
|
-
const localesDir = path.resolve(
|
|
22
|
+
const localesDir = path.resolve(__dirname, '../../../_locales')
|
|
23
23
|
if (!fs.existsSync(localesDir)) return ['en']
|
|
24
24
|
const locales = fs.readdirSync(localesDir, { withFileTypes: true })
|
|
25
25
|
.filter(entry => entry.isDirectory()).map(entry => entry.name)
|
|
@@ -37,9 +37,7 @@ module.exports = {
|
|
|
37
37
|
locales = locales.filter(locale => !excludeSet.has(locale))
|
|
38
38
|
|
|
39
39
|
// Get random language
|
|
40
|
-
|
|
41
|
-
if (locales.length)
|
|
42
|
-
randomLang = locales[Math.floor(Math.random() * locales.length)]
|
|
40
|
+
const randomLang = locales.length ? locales[Math.floor(Math.random() * locales.length)] : 'en'
|
|
43
41
|
log.debug(`Random language: ${randomLang}`)
|
|
44
42
|
|
|
45
43
|
return randomLang
|
|
@@ -50,20 +48,29 @@ module.exports = {
|
|
|
50
48
|
if (env.msgs && langCode == cli.lang) return env.msgs // don't re-fetch same msgs
|
|
51
49
|
|
|
52
50
|
let msgs = data.flatten( // local ones
|
|
53
|
-
require(`../../${ env.modes.dev ? '../_locales/en
|
|
51
|
+
require(`../../${ env.modes.dev ? '../_locales/en' : 'data' }/messages.json`))
|
|
54
52
|
|
|
55
53
|
if (!langCode.startsWith('en')) { // fetch non-English msgs from jsDelivr
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
try { // check if terminal supports non-Latin scripts
|
|
55
|
+
const nonLatinLocales = await (await data.fetch(
|
|
56
|
+
`${cli.urls.jsdelivr}@${cli.commitHashes.data}/assets/data/non-latin-locales.json`
|
|
57
|
+
)).json()
|
|
58
|
+
if (nonLatinLocales.includes(langCode.split('-')[0]) && !env.supports.unicode)
|
|
59
|
+
return msgs // en ones
|
|
60
|
+
} catch (err) {
|
|
61
|
+
log.debug(`Failed to fetch non-Latin locales: ${err}`)
|
|
62
|
+
}
|
|
63
|
+
const msgBaseURL = `${require('./jsdelivr').getCommitURL(cli.commitHashes.locales)}/_locales`
|
|
64
|
+
let msgURL = `${msgBaseURL}/${langCode}/messages.json`, msgFetchesTried = 0
|
|
58
65
|
while (msgFetchesTried < 3)
|
|
59
66
|
try { // fetch remote msgs
|
|
60
|
-
msgs = data.flatten(await (await data.fetch(
|
|
67
|
+
msgs = data.flatten(await (await data.fetch(msgURL)).json())
|
|
61
68
|
break
|
|
62
69
|
} catch (err) { // retry up to 2X (region-stripped + EN)
|
|
63
70
|
msgFetchesTried++ ; if (msgFetchesTried >= 3) break
|
|
64
|
-
log.debug(
|
|
65
|
-
|
|
66
|
-
: `${
|
|
71
|
+
log.debug(msgURL = langCode.includes('-') && msgFetchesTried == 1 ?
|
|
72
|
+
msgURL.replace(/([^_]*)_[^/]*(\/.*)/, '$1$2') // strip region before retrying
|
|
73
|
+
: `${msgBaseURL}/en/messages.json` // else use EN msgs
|
|
67
74
|
)
|
|
68
75
|
}
|
|
69
76
|
}
|
package/dist/cli/lib/log.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const colors = require('./color'),
|
|
2
2
|
{ getDownloads, getVer } = require('./pkg'),
|
|
3
|
+
settings = require('./settings'),
|
|
3
4
|
string = require('./string')
|
|
4
5
|
|
|
5
6
|
const nextMajVer = require('../../../package.json').version.replace(/^(\d+)\..*/, (_, major) => `${ +major +1 }.0.0`)
|
|
@@ -7,6 +8,7 @@ const nextMajVer = require('../../../package.json').version.replace(/^(\d+)\..*/
|
|
|
7
8
|
module.exports = {
|
|
8
9
|
colors,
|
|
9
10
|
|
|
11
|
+
break() { console.log() },
|
|
10
12
|
configURL() { this.info(`${cli.msgs.info_exampleValidConfigFile}: ${cli.urls.config}`) },
|
|
11
13
|
configURLandExit(...args) { this.error(...args); this.configURL(); process.exit(1) },
|
|
12
14
|
data(msg) { console.log(`\n${colors.bw}${msg}${colors.nc}`) },
|
|
@@ -15,9 +17,8 @@ module.exports = {
|
|
|
15
17
|
errorAndExit(...args) { this.error(...args); this.helpDocsCmdsDocsURL(); process.exit(1) },
|
|
16
18
|
ifNotQuiet(msg) { if (!cli.config.quietMode) this.info(msg) },
|
|
17
19
|
info(msg) { console.info(`\n${colors.schemes.default[0]}${msg}${colors.nc}`) },
|
|
18
|
-
break() { console.log() },
|
|
19
|
-
tip(msg) { console.info(`${colors.by}TIP: ${msg}${colors.nc}`) },
|
|
20
20
|
success(msg) { console.log(`\n${colors.bg}${msg}${colors.nc}`) },
|
|
21
|
+
tip(msg) { console.info(`${colors.by}TIP: ${msg}${colors.nc}`) },
|
|
21
22
|
warn(...args) { console.warn(`\n${colors.bo}WARNING:`, ...args, colors.nc) },
|
|
22
23
|
|
|
23
24
|
geoData(data) {
|
|
@@ -45,11 +46,10 @@ module.exports = {
|
|
|
45
46
|
this.warn(
|
|
46
47
|
`${cli.msgs.info_configFile} ${cli.msgs.warn_option.toLowerCase()} '${oldKey}: ${oldVal}' ${
|
|
47
48
|
cli.msgs.warn_hasBeenReplacedBy} '${
|
|
48
|
-
newKey}: ${ isNegKey(oldKey) != isNegKey(newKey) ? !oldVal : oldVal }' ${
|
|
49
|
+
newKey}: ${ settings.isNegKey(oldKey) != settings.isNegKey(newKey) ? !oldVal : oldVal }' ${
|
|
49
50
|
cli.msgs.warn_andWillBeRemoved} @ v${nextMajVer}`
|
|
50
51
|
)
|
|
51
52
|
this[`${oldKey}Warned`] = true
|
|
52
|
-
function isNegKey(key) { return /^(?:no|disable|exclude)[A-Z]/.test(key) }
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
|
package/dist/cli/lib/settings.js
CHANGED
|
@@ -16,12 +16,14 @@ module.exports = {
|
|
|
16
16
|
stats: { type: 'cmd', regex: /^--?stats?$/ }
|
|
17
17
|
},
|
|
18
18
|
|
|
19
|
+
isNegKey(key) { return /^(?:no|disable|exclude)[A-Z]/.test(key) },
|
|
20
|
+
|
|
19
21
|
load(ctrlKeys = Object.keys(this.controls)) {
|
|
20
22
|
const inputCtrlKeys = [].concat(ctrlKeys) // force array
|
|
21
23
|
|
|
22
24
|
if (!cli.defaultsSet && !arguments.length) { // init all defaults on arg-less load()
|
|
23
25
|
inputCtrlKeys.forEach(key => {
|
|
24
|
-
const ctrl = this.controls[key] ; if (ctrl.mode ||
|
|
26
|
+
const ctrl = this.controls[key] ; if (ctrl.mode || key.startsWith('legacy_')) return
|
|
25
27
|
cli.config[key] ??= ctrl.defaultVal ?? ( ctrl.type == 'param' ? '' : false )
|
|
26
28
|
})
|
|
27
29
|
cli.defaultsSet = true
|
|
@@ -60,8 +62,8 @@ module.exports = {
|
|
|
60
62
|
if (this.configFileKeyWhitelist && !this.configFileKeyWhitelist.includes(key))
|
|
61
63
|
log.invalidConfigKey(key)
|
|
62
64
|
return
|
|
63
|
-
} else if (
|
|
64
|
-
if (
|
|
65
|
+
} else if (key.startsWith('legacy_') && ctrl.replacedBy) {
|
|
66
|
+
if (this.isNegKey(key) != this.isNegKey(ctrl.replacedBy))
|
|
65
67
|
cli.config[ctrl.replacedBy] = !val // assign opposite val to current key
|
|
66
68
|
else // assign direct val to current key
|
|
67
69
|
cli.config[ctrl.replacedBy] = val
|
|
@@ -79,8 +81,8 @@ module.exports = {
|
|
|
79
81
|
const ctrlKey = Object.keys(this.controls).find(key => this.controls[key]?.regex?.test(arg))
|
|
80
82
|
if (!ctrlKey && cli.msgs) log.errorAndExit(`[${arg}] ${cli.msgs.error_notRecognized}.`)
|
|
81
83
|
if (!inputCtrlKeys.includes(ctrlKey)) return // don't process env.args when load() specific keys
|
|
84
|
+
if (ctrlKey.startsWith('legacy_')) { log.argDoesNothing(arg) ; continue }
|
|
82
85
|
const ctrl = this.controls[ctrlKey]
|
|
83
|
-
if (ctrl.type == 'legacy') { log.argDoesNothing(arg) ; continue }
|
|
84
86
|
if (ctrl.mode) // set cli.config.mode to mode name
|
|
85
87
|
cli.config.mode = ctrlKey.replace(/mode$/i, '').toLowerCase()
|
|
86
88
|
else { // init flag/param/cmd cli.config[ctrlKey] val
|
package/docs/README.md
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
<a id="top"></a>
|
|
2
2
|
|
|
3
|
-
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
3
|
+
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d3424a/geolocate/assets/images/icons/wire-globe/white/icon32.png"><img height=28 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d3424a/geolocate/assets/images/icons/wire-globe/black/icon32.png"></picture> geolocate
|
|
4
4
|
|
|
5
5
|
### Fetch IP geolocation data from the CLI.
|
|
6
6
|
|
|
7
|
-
<a href="https://
|
|
7
|
+
<a href="https://npmstar.com/compare/@adamlui%2Fgeolocate">
|
|
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.
|
|
12
|
-
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.
|
|
11
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/geolocate-2.4.1">
|
|
12
|
+
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.4.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="#">
|
|
16
|
-
<img height=31 src="https://img.shields.io/bundlejs/size/%40adamlui%2Fgeolocate%402.2.1?label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
17
15
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:geolocate/src/geolocate.js">
|
|
18
16
|
<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
|
-
<a href="https://github.com/toolleeo/cli-apps
|
|
17
|
+
<a href="https://github.com/toolleeo/cli-apps/#networking">
|
|
20
18
|
<img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-ff69b4?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
21
19
|
|
|
22
20
|
<br>
|
|
23
21
|
|
|
24
|
-
<img height=6px width="100%" src="https://
|
|
22
|
+
<img height=6px width="100%" src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/separators/aqua-gradient.png">
|
|
25
23
|
|
|
26
24
|
## ⚡ Installation
|
|
27
25
|
|
|
@@ -45,9 +43,9 @@ $ npm install @adamlui/geolocate
|
|
|
45
43
|
|
|
46
44
|
<br>
|
|
47
45
|
|
|
48
|
-
<a href="https://github.com/sponsors/adamlui"><img src="https://
|
|
46
|
+
<a href="https://github.com/sponsors/adamlui"><img src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/banners/sponsor/$10/banner1660x260.png"></a>
|
|
49
47
|
|
|
50
|
-
<img height=6px width="100%" src="https://
|
|
48
|
+
<img height=6px width="100%" src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/separators/aqua-gradient.png">
|
|
51
49
|
|
|
52
50
|
## 💻 Command line usage
|
|
53
51
|
|
|
@@ -59,7 +57,7 @@ $ geolocate [ip1] [ip2] [...]
|
|
|
59
57
|
|
|
60
58
|
Sample output:
|
|
61
59
|
|
|
62
|
-
<img src="https://
|
|
60
|
+
<img src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d3424a/geolocate/assets/images/screenshots/cli/geolocate-8.8.8.8-cmd-output.png">
|
|
63
61
|
|
|
64
62
|
**📝 Note:** If no IPv4 address is passed, your own one will be used.
|
|
65
63
|
|
|
@@ -99,13 +97,13 @@ export default {
|
|
|
99
97
|
|
|
100
98
|
<br>
|
|
101
99
|
|
|
102
|
-
<img height=6px width="100%" src="https://
|
|
100
|
+
<img height=6px width="100%" src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/separators/aqua-gradient.png">
|
|
103
101
|
|
|
104
102
|
## 🔌 Importing the API
|
|
105
103
|
|
|
106
104
|
You can also import **geolocate** into your app to use its main API method.
|
|
107
105
|
|
|
108
|
-
### <img height=18 src="https://
|
|
106
|
+
### <img height=18 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/icons/platforms/node.js/icon25x28.png"> Node.js
|
|
109
107
|
|
|
110
108
|
#### ECMAScript*:
|
|
111
109
|
|
|
@@ -121,28 +119,28 @@ const geo = require('@adamlui/geolocate')
|
|
|
121
119
|
|
|
122
120
|
###### _*Node.js version 14 or higher required_
|
|
123
121
|
|
|
124
|
-
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
122
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/icons/platforms/web/light/icon25.png"><img width=16 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/icons/platforms/web/dark/icon25.png"></picture> Web
|
|
125
123
|
|
|
126
124
|
#### <> HTML script tag:
|
|
127
125
|
|
|
128
126
|
```html
|
|
129
|
-
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.
|
|
127
|
+
<script src="https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.4.1/dist/geolocate.min.js"></script>
|
|
130
128
|
```
|
|
131
129
|
|
|
132
130
|
#### ES6:
|
|
133
131
|
|
|
134
132
|
```js
|
|
135
133
|
(async () => {
|
|
136
|
-
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.
|
|
134
|
+
await import('https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.4.1/dist/geolocate.min.js')
|
|
137
135
|
// Your code here...
|
|
138
136
|
})()
|
|
139
137
|
```
|
|
140
138
|
|
|
141
|
-
### <img height=17 src="https://
|
|
139
|
+
### <img height=17 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/icons/platforms/tampermonkey/icon28.png"><img height=17.5 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/icons/platforms/violentmonkey/icon25.png"> Greasemonkey
|
|
142
140
|
|
|
143
141
|
```js
|
|
144
142
|
...
|
|
145
|
-
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.
|
|
143
|
+
// @require https://cdn.jsdelivr.net/npm/@adamlui/geolocate@2.4.1/dist/geolocate.min.js
|
|
146
144
|
// ==/UserScript==
|
|
147
145
|
|
|
148
146
|
// Your code here...
|
|
@@ -150,11 +148,11 @@ const geo = require('@adamlui/geolocate')
|
|
|
150
148
|
|
|
151
149
|
<br>
|
|
152
150
|
|
|
153
|
-
**📝 Note:** To always import the latest version (not recommended in production!) remove the `@2.
|
|
151
|
+
**📝 Note:** To always import the latest version (not recommended in production!) remove the `@2.4.1` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/@adamlui/geolocate/dist/geolocate.min.js`
|
|
154
152
|
|
|
155
153
|
<br>
|
|
156
154
|
|
|
157
|
-
<img height=6px width="100%" src="https://
|
|
155
|
+
<img height=6px width="100%" src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/separators/aqua-gradient.png">
|
|
158
156
|
|
|
159
157
|
## 📋 API usage
|
|
160
158
|
|
|
@@ -205,7 +203,7 @@ Name | Type | Description | Default Value
|
|
|
205
203
|
|
|
206
204
|
<br>
|
|
207
205
|
|
|
208
|
-
<img height=6px width="100%" src="https://
|
|
206
|
+
<img height=6px width="100%" src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/separators/aqua-gradient.png">
|
|
209
207
|
|
|
210
208
|
## 🏛️ MIT License
|
|
211
209
|
|
|
@@ -219,11 +217,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
219
217
|
|
|
220
218
|
<br>
|
|
221
219
|
|
|
222
|
-
<img height=6px width="100%" src="https://
|
|
220
|
+
<img height=6px width="100%" src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/separators/aqua-gradient.png">
|
|
223
221
|
|
|
224
222
|
## 🛠️ Related utilities
|
|
225
223
|
|
|
226
|
-
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
224
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/adamlui/js-utils@5c34563/generate-ip/assets/images/icons/node-graph/white/icon55x49.png"><img height=21 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@5c34563/generate-ip/assets/images/icons/node-graph/black/icon55x49.png"></picture> [generate-ip](https://js-utils.org/generate-ip) <a href="https://github.com/toolleeo/cli-apps/#networking"><img height=18 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/badges/awesome/badge.svg"></a>
|
|
227
225
|
|
|
228
226
|
> Randomly generate, format, and validate IPv4 + IPv6 + MAC addresses.
|
|
229
227
|
<br>[Install](https://docs.generate-ip.org/#-installation) /
|
|
@@ -232,7 +230,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
232
230
|
[CLI usage](https://docs.generate-ip.org/#-command-line-usage) /
|
|
233
231
|
[Discuss](https://github.com/adamlui/js-utils/discussions)
|
|
234
232
|
|
|
235
|
-
### [🔒 generate-pw](../generate-pw) <a href="https://github.com/toolleeo/cli-apps
|
|
233
|
+
### [🔒 generate-pw](../generate-pw) <a href="https://github.com/toolleeo/cli-apps/#password-managers"><img height=18 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/badges/awesome/badge.svg"></a>
|
|
236
234
|
|
|
237
235
|
> Randomly generate, strengthen, and validate cryptographically-secure passwords.
|
|
238
236
|
<br>[Install](https://docs.generatepw.org/#-installation) /
|
|
@@ -243,8 +241,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
243
241
|
|
|
244
242
|
<br>
|
|
245
243
|
|
|
246
|
-
<img height=6px width="100%" src="https://
|
|
244
|
+
<img height=6px width="100%" src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/separators/aqua-gradient.png">
|
|
247
245
|
|
|
248
|
-
<picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
246
|
+
<picture><source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/icons/home/white/icon32x27.png"><img height=13 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils@0d36e26/assets/images/icons/home/dark-gray/icon32x27.png"></picture> <a href="https://js-utils.org">**More JavaScript utilities**</a> /
|
|
249
247
|
<a href="https://github.com/adamlui/js-utils/discussions">Discuss</a> /
|
|
250
248
|
<a href="#top">Back to top ↑</a>
|
package/docs/SECURITY.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamlui/geolocate",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "Fetch IP geolocation data from the CLI.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Adam Lui",
|
|
@@ -71,12 +71,13 @@
|
|
|
71
71
|
"url": "https://github.com/adamlui/js-utils/issues"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
+
"is-unicode-supported": "^2.1.0",
|
|
74
75
|
"node-clipboardy": "^1.0.3"
|
|
75
76
|
},
|
|
76
77
|
"devDependencies": {
|
|
77
|
-
"@adamlui/minify.js": "^2.
|
|
78
|
+
"@adamlui/minify.js": "^2.5.0",
|
|
78
79
|
"console-table-printer": "^2.15.0",
|
|
79
80
|
"copyfiles": "^2.4.1",
|
|
80
|
-
"generate-ip": "^2.
|
|
81
|
+
"generate-ip": "^2.9.0"
|
|
81
82
|
}
|
|
82
83
|
}
|