generate-ip 2.4.9 โ 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -10
- package/dist/cli/index.min.js +5 -9
- package/dist/cli/lib/data.min.js +4 -4
- package/dist/cli/lib/language.min.js +5 -4
- package/dist/cli/lib/log.min.js +22 -0
- package/dist/cli/lib/pkg.min.js +6 -0
- package/dist/cli/lib/settings.min.js +7 -0
- package/dist/data/generate-ip.config.mjs +16 -0
- package/dist/data/messages.json +22 -7
- package/dist/data/{app.json โ package-data.json} +2 -1
- package/dist/generate-ip.min.js +4 -4
- package/docs/README.md +32 -10
- package/package.json +8 -3
- package/dist/cli/lib/print.min.js +0 -16
package/README.md
CHANGED
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
<a href="#%EF%B8%8F-mit-license">
|
|
12
12
|
<img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
13
|
-
<a href="https://github.com/adamlui/js-utils/releases/tag/generate-ip-2.
|
|
14
|
-
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.
|
|
13
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/generate-ip-2.6.0">
|
|
14
|
+
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.6.0-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
15
15
|
<a href="https://www.npmjs.com/package/generate-ip?activeTab=code">
|
|
16
16
|
<img height=31 src="https://img.shields.io/npm/unpacked-size/generate-ip?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
|
|
17
|
-
<a href="https://github.com/adamlui/js-utils/blob/generate-ip-2.
|
|
18
|
-
<img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/generate-ip/dist/generate-ip.min.js?branch=generate-ip-2.
|
|
17
|
+
<a href="https://github.com/adamlui/js-utils/blob/generate-ip-2.6.0/generate-ip/dist/generate-ip.min.js">
|
|
18
|
+
<img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/generate-ip/dist/generate-ip.min.js?branch=generate-ip-2.6.0&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
19
19
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:generate-ip/src/generate-ip.js">
|
|
20
20
|
<img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Agenerate-ip%2Fsrc%2Fgenerate-ip.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
|
|
21
21
|
<a href="https://github.com/toolleeo/cli-apps#networking">
|
|
@@ -71,7 +71,7 @@ $ npm install generate-ip
|
|
|
71
71
|
#### ECMAScript*:
|
|
72
72
|
|
|
73
73
|
```js
|
|
74
|
-
import { ipv4, ipv6, mac } from 'generate-ip'
|
|
74
|
+
import { ipv4, ipv6, mac } from 'generate-ip'
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
#### CommonJS:
|
|
@@ -87,14 +87,14 @@ const { ipv4, ipv6, mac } = require('generate-ip')
|
|
|
87
87
|
#### <> HTML script tag:
|
|
88
88
|
|
|
89
89
|
```html
|
|
90
|
-
<script src="https://cdn.jsdelivr.net/npm/generate-ip@2.
|
|
90
|
+
<script src="https://cdn.jsdelivr.net/npm/generate-ip@2.6.0/dist/generate-ip.min.js"></script>
|
|
91
91
|
```
|
|
92
92
|
|
|
93
93
|
#### ES6:
|
|
94
94
|
|
|
95
95
|
```js
|
|
96
96
|
(async () => {
|
|
97
|
-
await import('https://cdn.jsdelivr.net/npm/generate-ip@2.
|
|
97
|
+
await import('https://cdn.jsdelivr.net/npm/generate-ip@2.6.0/dist/generate-ip.min.js')
|
|
98
98
|
// Your code here...
|
|
99
99
|
})()
|
|
100
100
|
```
|
|
@@ -103,7 +103,7 @@ const { ipv4, ipv6, mac } = require('generate-ip')
|
|
|
103
103
|
|
|
104
104
|
```js
|
|
105
105
|
...
|
|
106
|
-
// @require https://cdn.jsdelivr.net/npm/generate-ip@2.
|
|
106
|
+
// @require https://cdn.jsdelivr.net/npm/generate-ip@2.6.0/dist/generate-ip.min.js
|
|
107
107
|
// ==/UserScript==
|
|
108
108
|
|
|
109
109
|
// Your code here...
|
|
@@ -111,7 +111,7 @@ const { ipv4, ipv6, mac } = require('generate-ip')
|
|
|
111
111
|
|
|
112
112
|
<br>
|
|
113
113
|
|
|
114
|
-
๐ **Note:** To always import the latest version (not recommended in production!) remove the `@2.
|
|
114
|
+
๐ **Note:** To always import the latest version (not recommended in production!) remove the `@2.6.0` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/generate-ip/dist/generate-ip.min.js`
|
|
115
115
|
|
|
116
116
|
<br>
|
|
117
117
|
|
|
@@ -369,17 +369,39 @@ Sample output:
|
|
|
369
369
|
```
|
|
370
370
|
Parameter options:
|
|
371
371
|
--qty=n Generate n IP address(es).
|
|
372
|
+
--ui-lang="code" ISO 639-1 code of language to display UI in.
|
|
373
|
+
--config="path/to/file" Load custom config file.
|
|
372
374
|
|
|
373
375
|
Boolean options:
|
|
374
376
|
-6, --ipv6 Generate IPv6 address.
|
|
375
377
|
-m, --mac Generate MAC address.
|
|
376
378
|
-q, --quiet Suppress all logging except errors.
|
|
377
379
|
|
|
378
|
-
|
|
380
|
+
Commands:
|
|
381
|
+
-i, --init Create config file (in project root).
|
|
379
382
|
-h, --help Display help screen.
|
|
380
383
|
-v, --version Show version number.
|
|
381
384
|
```
|
|
382
385
|
|
|
386
|
+
#
|
|
387
|
+
|
|
388
|
+
### Configuration file
|
|
389
|
+
|
|
390
|
+
**generate-ip** can be customized using a `generate-ip.config.mjs` or `generate-ip.config.js` placed in your project root.
|
|
391
|
+
|
|
392
|
+
Example defaults:
|
|
393
|
+
|
|
394
|
+
```js
|
|
395
|
+
export default {
|
|
396
|
+
qty: 5, // # of IPs to generate
|
|
397
|
+
ipv6mode: false, // Generate IPv6 address(es)
|
|
398
|
+
macMode: false, // Generate MAC address(es)
|
|
399
|
+
quietMode: true // Suppress all logging except errors
|
|
400
|
+
}
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
๐ก Run `generate-ip init` to generate a template `generate-ip.config.mjs` in your project root.
|
|
404
|
+
|
|
383
405
|
<br>
|
|
384
406
|
|
|
385
407
|
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
package/dist/cli/index.min.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* ยฉ 2024โ2026 Adam Lui & contributors under the MIT license.
|
|
4
|
+
* Source: https://github.com/adamlui/js-utils/tree/main/generate-ip/src
|
|
5
|
+
* Documentation: https://github.com/adamlui/js-utils/tree/main/generate-ip/docs
|
|
6
6
|
*/
|
|
7
|
-
(async()=>{globalThis.env={
|
|
8
|
-
${
|
|
9
|
-
${app.colors.br}${app.msgs.prefix_error}: Arg [${p}] ${app.msgs.error_notRecognized}.`+app.colors.nc),console.info(`
|
|
10
|
-
${app.colors.by}${app.msgs.info_validArgs}.`+app.colors.nc),i.help(["paramOptions","flags","infoCmds"]),process.exit(1)))}),app.config.qty&&(isNaN(app.config.qty)||app.config.qty<1)&&(console.error(`
|
|
11
|
-
${app.colors.br}${app.msgs.prefix_error}: [qty] ${app.msgs.error_nonPositiveNum}.`+app.colors.nc),i.helpCmdAndDocURL(),process.exit(1)),process.argv.some(e=>app.regex.infoCmds.help.test(e))?i.help():process.argv.some(e=>app.regex.infoCmds.version.test(e))?i.version():(n={qty:app.config.qty||1,verbose:!app.config.quietMode},n=(app.config.ipv6mode?s:app.config.macMode?a:r).generate(n),i.ifNotQuiet(`
|
|
12
|
-
${app.msgs.info_copying}...`),e.writeSync([].concat(n).join("\n")))})();
|
|
7
|
+
(async()=>{globalThis.env={args:process.argv.slice(2),devMode:/[\\/]src(?:[\\/]|$)/i.test(__dirname)},env.debugMode=env.args.some(e=>/^--?debug(?:-?mode)?$/.test(e));var e,i=require("node-clipboardy"),{ipv4:n,ipv6:o,mac:s}=require(`../generate-ip${env.devMode?"":".min"}.js`),r=require(`./lib/language${env.devMode?"":".min"}.js`),g=require(`./lib/log${env.devMode?"":".min"}.js`),a=require(`./lib/settings${env.devMode?"":".min"}.js`);Object.assign(globalThis.cli??={},require(`../${env.devMode?"../":"data/"}package-data.json`)),a.load("uiLang"),env.sysLang=cli.config.uiLang||(env.debugMode?r.generateRandomLang({excludes:["en"]}):r.getSysLang()),cli.msgs=await r.getMsgs(env.sysLang),cli.urls.docs+="/#-command-line-usage";for(e of env.args){if(a.controls.init.regex.test(e))return a.initConfigFile();if(a.controls.help.regex.test(e))return g.help();if(a.controls.version.regex.test(e))return g.version()}a.load();r={qty:cli.config.qty,verbose:!cli.config.quietMode},n={ipv4:n,ipv6:o,mac:s}[cli.config.mode||"ipv4"].generate(r);g.ifNotQuiet(`
|
|
8
|
+
${cli.msgs.info_copyingToClip}...`),i.writeSync([].concat(n).join("\n"))})();
|
package/dist/cli/lib/data.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* ยฉ 2024โ2026 Adam Lui & contributors under the MIT license.
|
|
3
|
+
* Source: https://github.com/adamlui/js-utils/tree/main/generate-ip/src
|
|
4
|
+
* Documentation: https://github.com/adamlui/js-utils/tree/main/generate-ip/docs
|
|
5
5
|
*/
|
|
6
|
-
module.exports={fetch(n){return new Promise((t,e)=>{var r=n.match(/^([^:]+):\/\//)[1];/^https?$/.test(r)||e(new Error(
|
|
6
|
+
module.exports={atomicWrite(e,r,t="utf8"){var n=require("fs"),a=require("path"),a=a.join(a.dirname(e),`.${a.basename(e)}.tmp`);n.writeFileSync(a,r,t),n.renameSync(a,e)},fetch(n){return"undefined"==typeof fetch?new Promise((t,e)=>{var r=n.match(/^([^:]+):\/\//)[1];/^https?$/.test(r)||e(new Error(cli.msgs.error_invalidURL+".")),require(r).get(n,e=>{let r="";e.on("data",e=>r+=e),e.on("end",()=>t({json:()=>JSON.parse(r)}))}).on("error",e)}):fetch(n)},flatten(e,{key:r="message"}={}){var t,n={};for(t in e)n[t]="object"==typeof e[t]&&r in e[t]?e[t][r]:e[t];return n}};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* ยฉ 2024โ2026 Adam Lui & contributors under the MIT license.
|
|
3
|
+
* Source: https://github.com/adamlui/js-utils/tree/main/generate-ip/src
|
|
4
|
+
* Documentation: https://github.com/adamlui/js-utils/tree/main/generate-ip/docs
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
let data=require(`./data${env.devMode?"":".min"}.js`),log=require(`./log${env.devMode?"":".min"}.js`);module.exports={formatCode(e){return e.replace(/([a-z]{2,8})[-_]([a-z]{2})/i,(e,r,a)=>r.toLowerCase()+"_"+a.toUpperCase())},generateRandomLang({includes:e=[],excludes:r=[]}={}){let t=require("fs"),s=require("path"),a=e.length?e:(()=>{var e=s.join(__dirname,"..",".cache"),r=s.join(e,"locales.json");if(t.existsSync(r))try{return JSON.parse(t.readFileSync(r,"utf8"))}catch(e){}var a=s.resolve(process.cwd(),"_locales");return t.existsSync(a)?(a=t.readdirSync(a,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name).filter(e=>/^\w{2}[-_]?\w{0,2}$/.test(e)),t.mkdirSync(e,{recursive:!0}),data.atomicWrite(r,JSON.stringify(a,null,2)),a):["en"]})(),n=new Set(r),l="en";return(a=a.filter(e=>!n.has(e))).length&&(l=a[Math.floor(Math.random()*a.length)]),log.debug(`Random language: ${l}
|
|
7
|
+
`),l},async getMsgs(t="en"){t=module.exports.formatCode(t);let e=data.flatten(require(`../../${env.devMode?"../_locales/en/":"data/"}messages.json`));if(!t.startsWith("en")){var s=`${cli.urls.jsdelivr}@${cli.commitHashes.locales}/${cli.name}/_locales/`;let r=s+t+"/messages.json",a=0;for(;a<3;)try{e=data.flatten(await(await data.fetch(r)).json());break}catch(e){if(3<=++a)break;log.debug(r=t.includes("-")&&1==a?r.replace(/([^_]*)_[^/]*(\/.*)/,"$1$2"):s+"en/messages.json")}}return e},getSysLang(){try{var e;return"win32"==process.platform?require("child_process").execSync("(Get-Culture).TwoLetterISOLanguageName",{shell:"powershell",encoding:"utf-8"}).trim():((e=process.env).LANG||e.LANGUAGE||e.LC_ALL||e.LC_MESSAGES||e.LC_NAME).split(".")[0]}catch(e){return log.error(cli.msgs.error_failedToFetchSysLang+":",e.message),"en"}}};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ยฉ 2024โ2026 Adam Lui & contributors under the MIT license.
|
|
3
|
+
* Source: https://github.com/adamlui/js-utils/tree/main/generate-ip/src
|
|
4
|
+
* Documentation: https://github.com/adamlui/js-utils/tree/main/generate-ip/docs
|
|
5
|
+
*/
|
|
6
|
+
module.exports={colors:{nc:"[0m",br:"[1;91m",by:"[1;33m",bo:"[38;5;214m",bg:"[1;92m",bw:"[1;97m",blk:"[30m",tlBG:"[106m"},configURL(){this.info(`
|
|
7
|
+
${cli.msgs.info_exampleValidConfigFile}: `+cli.urls.config)},configURLandExit(...o){this.error(...o),this.configURL(),process.exit(1)},data(o){console.log(`
|
|
8
|
+
`+this.colors.bw+o+this.colors.nc)},debug(o){env.debugMode&&console.debug(`
|
|
9
|
+
${this.colors.bo}DEBUG:`,o,this.colors.nc,"\n")},error(...o){console.error(`
|
|
10
|
+
${this.colors.br}ERROR:`,...o,this.colors.nc)},errorAndExit(...o){this.error(...o),this.helpCmdAndDocURL(),process.exit(1)},ifNotQuiet(o){cli.config.quietMode||console.info(o)},info(o){console.info(`
|
|
11
|
+
`+this.colors.by+o+this.colors.nc)},tip(o){console.info(this.colors.by+"TIP: "+o+this.colors.nc)},success(o){console.log(`
|
|
12
|
+
`+this.colors.bg+o+this.colors.nc)},warn(...o){console.warn(`
|
|
13
|
+
${this.colors.bo}WARNING:`,...o,this.colors.nc)},help(o=["header","usage","params","flags","cmds"]){cli.prefix=""+this.colors.tlBG+this.colors.blk+`[30m ${cli.name} ${this.colors.nc} `;let s={header:[`
|
|
14
|
+
โ ${cli.prefix}${cli.msgs.appCopyright}.`,""+cli.prefix+cli.msgs.prefix_source+": "+cli.urls.src],usage:[`
|
|
15
|
+
${this.colors.bw}o ${cli.msgs.helpSection_usage}:`+this.colors.nc,` ${this.colors.bw}ยป `+this.colors.bg+cli.cmdFormat+this.colors.nc],params:[`
|
|
16
|
+
${this.colors.bw}o ${cli.msgs.helpSection_params}:`+this.colors.nc,` --qty=n ${cli.msgs.optionDesc_qty}.`,` --ui-lang="code" ${cli.msgs.optionDesc_uiLang}.`,` --config="path/to/file" ${cli.msgs.optionDesc_config}.`],flags:[`
|
|
17
|
+
${this.colors.bw}o ${cli.msgs.helpSection_flags}:`+this.colors.nc,` -6, --ipv6 ${cli.msgs.optionDesc_ipv6}.`,` -m, --mac ${cli.msgs.optionDesc_mac}.`,` -q, --quiet ${cli.msgs.optionDesc_quiet}.`],cmds:[`
|
|
18
|
+
${this.colors.bw}o ${cli.msgs.helpSection_cmds}:`+this.colors.nc,` -i, --init ${cli.msgs.optionDesc_init}.`,` -h, --help ${cli.msgs.optionDesc_help}.`,` -v, --version ${cli.msgs.optionDesc_version}.`]};o.forEach(r=>s[r]?.forEach(s=>{{var e=/header|usage/.test(r)?1:29;let i=process.stdout.columns||80,o=s.match(/\S+|\s+/g),c=[],l="";o.forEach(o=>{var s=i-(c.length?e:0);l.length+"| ".length+o.length>s&&(c.push(c.length?l.trimStart():l),l=""),l+=o}),c.push(c.length?l.trimStart():l),c.forEach((o,s)=>console.info("| "+(0==s?o:" ".repeat(e)+o)))}})),console.info(`
|
|
19
|
+
${cli.msgs.info_moreHelp}, ${cli.msgs.info_visit}: `+this.colors.bw+cli.urls.docs+this.colors.nc)},helpCmdAndDocURL(){console.info(`
|
|
20
|
+
${cli.msgs.info_moreHelp}, ${cli.msgs.info_type} ${cli.name} --help' ${cli.msgs.info_or} ${cli.msgs.info_visit}
|
|
21
|
+
`+this.colors.bw+cli.urls.docs+this.colors.nc)},version(){var o=require(`./pkg${env.devMode?"":".min"}.js`).getVer;this.info(cli.name),this.data(`${cli.msgs.prefix_globalVer}: ${o("global")||"none"}
|
|
22
|
+
${cli.msgs.prefix_localVer}: `+(o("local")||"none"))}};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ยฉ 2024โ2026 Adam Lui & contributors under the MIT license.
|
|
3
|
+
* Source: https://github.com/adamlui/js-utils/tree/main/generate-ip/src
|
|
4
|
+
* Documentation: https://github.com/adamlui/js-utils/tree/main/generate-ip/docs
|
|
5
|
+
*/
|
|
6
|
+
let log=require(`./log${env.devMode?"":".min"}.js`);module.exports={getVer(e="any"){let r;if("global"!=e)try{var l=require("path").resolve(process.cwd(),"node_modules",cli.name,"package.json");r=require(l).version}catch(e){log.debug(cli.msgs.error_readingLocalPkgVer+": "+e.message)}if("global"==e||"all"==e&&!r)try{r=require("child_process").execSync(`npm view ${JSON.stringify(cli.name)} version`).toString().trim()}catch(e){log.debug(cli.msgs.error_failedToFetchGlobalVer+": "+e.message)}return r}};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ยฉ 2024โ2026 Adam Lui & contributors under the MIT license.
|
|
3
|
+
* Source: https://github.com/adamlui/js-utils/tree/main/generate-ip/src
|
|
4
|
+
* Documentation: https://github.com/adamlui/js-utils/tree/main/generate-ip/docs
|
|
5
|
+
*/
|
|
6
|
+
let fs=require("fs"),log=require(`./log${env.devMode?"":".min"}.js`),path=require("path");(globalThis.cli??={}).config={},module.exports={configFilename:"generate-ip.config.mjs",controls:{qty:{type:"param",defaultVal:1,regex:/^--?qu?a?n?ti?t?y(?:=.*|$)/,parser:e=>parseInt(e,10)},uiLang:{type:"param",regex:/^--?ui-?lang(?:=.*|$)/},config:{type:"param",regex:/^--?config(?:=.*|$)/},ipv6mode:{type:"flag",mode:!0,regex:/^--?(?:ip)?v?6(?:-?mode)?$/},macMode:{type:"flag",mode:!0,regex:/^--?m(?:ac)?(?:-?mode)?$/},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?$/}},async initConfigFile(e=this.configFilename){var i={target:path.resolve(process.cwd(),e)};if(fs.existsSync(i.target))return log.warn(cli.msgs.warn_configFileExists+":",i.target);if(fs.existsSync(i.src=path.resolve(__dirname,"../../"+(env.devMode?"../":"data/")+e)))fs.copyFileSync(i.src,i.target);else{cli.version??=require(`./pkg${env.devMode?"":".min"}.js`).getVer("local");var t=require(`./data${env.devMode?"":".min"}.js`),o=cli.version?cli.name+"-"+cli.version:"latest",o=cli.urls.jsdelivr+`@${o}/${cli.name}/`+e;log.data(cli.msgs.info_fetchingRemoteConfigFrom+` ${o}...`);try{var r=await t.fetch(o);if(!r.ok)return log.warn(`${cli.msgs.warn_remoteConfigNotFound}: ${o} (${r.status})`);t.atomicWrite(i.target,await r.text())}catch(e){return log.warn(cli.msgs.warn_remoteConfigFailed+`: ${o} `+e.message)}}log.success(`${cli.msgs.info_configFileCreated}: ${i.target}\n`),log.tip(cli.msgs.tip_editToSetDefaults+"."),log.tip(cli.msgs.tip_cliArgsPrioritized+".")},load(e=Object.keys(this.controls)){let r=[].concat(e);if(arguments.length||cli.defaultsSet||(r.forEach(e=>{var i=this.controls[e];i.mode||"cmd"==i.type||(cli.config[e]??=i.defaultVal??("flag"!=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),t=e?.default??e;t&&"object"==typeof t||log.configURLandExit(cli.msgs.error_invalidConfigFile+"."),Object.assign(cli.config,arguments.length?r.reduce((e,i)=>t[i]?{...e,[i]:t[i]}:e,{}):t)}catch(e){log.configURLandExit(cli.msgs.error_failedToLoadConfigFile+":",cli.configPath,`
|
|
7
|
+
`+e.message)}return env.args.forEach(i=>{if(!/^[^-]|--?(?:config|debug)/.test(i)){var t=Object.keys(this.controls).find(e=>this.controls[e]?.regex?.test(i));if(t||arguments.length||log.errorAndExit(`[${i}] ${cli.msgs.error_notRecognized}.`),r.includes(t)){var o=this.controls[t];if("cmd"!=o.type){let e="param"!=o.type||i.split("=")[1]?.trim();o.mode?cli.config.mode=t.replace(/mode$/i,"").toLowerCase():((o=o.parser)&&(e=o(e),isNaN(e)||e<1)&&log.errorAndExit(`[${t}] ${cli.msgs.error_nonPositiveNum}.`),cli.config[t]=e)}}}}),cli.config}};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* generate-ip.config.mjs
|
|
3
|
+
*
|
|
4
|
+
* Optional config file for the generate-ip CLI.
|
|
5
|
+
* Copy this file to your project root to set default options.
|
|
6
|
+
* CLI arguments always override these values.
|
|
7
|
+
*
|
|
8
|
+
* Docs: https://github.com/adamlui/js-utils/tree/main/generate-ip/#-command-line-usage
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
mode: 'ipv4', // <ipv4|ipv6|mac> type of address to generate
|
|
13
|
+
qty: 1, // # of IPs to generate
|
|
14
|
+
quietMode: false, // suppress all logging except errors
|
|
15
|
+
uiLang: '' // ISO 639-1 code of language to display UI in
|
|
16
|
+
}
|
package/dist/data/messages.json
CHANGED
|
@@ -1,28 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"appName": { "message": "generate-ip" },
|
|
3
3
|
"appCopyright": { "message": "ยฉ 2024โ2026 Adam Lui & contributors under the MIT license" },
|
|
4
|
-
"prefix_error": { "message": "ERROR" },
|
|
5
4
|
"prefix_globalVer": { "message": "Global version" },
|
|
6
5
|
"prefix_localVer": { "message": "Local version" },
|
|
7
6
|
"prefix_source": { "message": "Source" },
|
|
8
|
-
"
|
|
7
|
+
"error_readingLocalPkgVer": { "message": "Error reading local package version" },
|
|
9
8
|
"error_notRecognized": { "message": "not recognized" },
|
|
10
9
|
"error_nonPositiveNum": { "message": "argument can only be > 0" },
|
|
11
10
|
"error_invalidURL": { "message": "Invalid URL" },
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
11
|
+
"error_invalidConfigFile": { "message": "Config file must export an object" },
|
|
12
|
+
"error_configFileNotFound": { "message": "Config file not found" },
|
|
13
|
+
"error_failedToLoadConfigFile": { "message": "Failed to load config file" },
|
|
14
|
+
"error_failedToFetchGlobalVer": { "message": "Failed to fetch global version" },
|
|
15
|
+
"error_failedToFetchSysLang": { "message": "Failed to fetch system language" },
|
|
16
|
+
"error_mustIncludePath": { "message": "must include =path" },
|
|
17
|
+
"warn_configFileExists": { "message": "Config file already exists" },
|
|
18
|
+
"warn_remoteConfigNotFound": { "message": "Remote config file not found" },
|
|
19
|
+
"warn_remoteConfigFailed": { "message": "Failed to fetch remote config file" },
|
|
20
|
+
"info_exampleValidConfigFile": { "message": "Example valid config file" },
|
|
21
|
+
"info_copyingToClip": { "message": "Copying to clipboard" },
|
|
22
|
+
"info_moreHelp": { "message": "For more help" },
|
|
15
23
|
"info_type": { "message": "type" },
|
|
16
24
|
"info_or": { "message": "or" },
|
|
17
25
|
"info_visit": { "message": "visit" },
|
|
26
|
+
"info_configFileCreated": { "message": "Config file created" },
|
|
27
|
+
"info_fetchingRemoteConfigFrom": { "message": "Fetching remote config file from" },
|
|
28
|
+
"tip_editToSetDefaults": { "message": "Edit this file to customize defaults" },
|
|
29
|
+
"tip_cliArgsPrioritized": { "message": "CLI arguments always override these values" },
|
|
18
30
|
"helpSection_usage": { "message": "Usage" },
|
|
19
|
-
"
|
|
31
|
+
"helpSection_params": { "message": "Parameter options" },
|
|
20
32
|
"helpSection_flags": { "message": "Boolean options" },
|
|
21
|
-
"
|
|
33
|
+
"helpSection_cmds": { "message": "Commands" },
|
|
34
|
+
"optionDesc_uiLang": { "message": "ISO 639-1 code of language to display UI in" },
|
|
22
35
|
"optionDesc_qty": { "message": "Generate n IP address(es)" },
|
|
36
|
+
"optionDesc_config": { "message": "Load custom config file" },
|
|
23
37
|
"optionDesc_ipv6": { "message": "Generate IPv6 address" },
|
|
24
38
|
"optionDesc_mac": { "message": "Generate MAC address" },
|
|
25
39
|
"optionDesc_quiet": { "message": "Suppress all logging except errors" },
|
|
40
|
+
"optionDesc_init": { "message": "Create config file (in project root)" },
|
|
26
41
|
"optionDesc_help": { "message": "Display help screen" },
|
|
27
42
|
"optionDesc_version": { "message": "Show version number" }
|
|
28
43
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"copyrightYear": "2024โ2026",
|
|
6
6
|
"cmdFormat": "generate-[ip|ipv6|mac] [options|commands]",
|
|
7
7
|
"urls": {
|
|
8
|
+
"config": "https://github.com/adamlui/js-utils/blob/main/generate-ip/generate-ip.config.mjs",
|
|
8
9
|
"docs": "https://github.com/adamlui/js-utils/tree/main/generate-ip/docs",
|
|
9
10
|
"github": "https://github.com/adamlui/js-utils",
|
|
10
11
|
"jsdelivr": "https://cdn.jsdelivr.net/gh/adamlui/js-utils",
|
|
@@ -12,6 +13,6 @@
|
|
|
12
13
|
"src": "https://github.com/adamlui/js-utils/tree/main/generate-ip/src"
|
|
13
14
|
},
|
|
14
15
|
"commitHashes": {
|
|
15
|
-
"locales": "
|
|
16
|
+
"locales": "c20c989"
|
|
16
17
|
}
|
|
17
18
|
}
|
package/dist/generate-ip.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* ยฉ 2024โ2026 Adam Lui & contributors under the MIT license.
|
|
3
|
+
* Source: https://github.com/adamlui/js-utils/tree/main/generate-ip/src
|
|
4
|
+
* Documentation: https://github.com/adamlui/js-utils/tree/main/generate-ip/docs
|
|
5
5
|
*/
|
|
6
|
-
Object.assign(globalThis.
|
|
6
|
+
Object.assign(globalThis.api??={},{name:"generate-ip",aliases:{ipv4:["ipV4","IPv4","IPV4","Ipv4","IpV4","ip","IP","Ip"],ipv6:["ipV6","IPv6","IPV6","Ipv6","IpV6"],mac:["MAC","Mac","ethernet","Ethernet"]}});let ipv4={generate(t={}){var e={verbose:!0,qty:1};if(log.prefix="ipv4.generate()",validateOptions({options:t,defaultOptions:e,helpURL:"https://github.com/adamlui/js-utils/tree/main/generate-ip/docs/#ipv4generateoptions",exampleCall:"ipv4.generate({ verbose: false, qty: 3 })"})){(t={...e,...t}).verbose&&log.info(`Generating IPv4 address${1<t.qty?"es":""}...`);var o=[];if(1<t.qty)for(let e=0;e<t.qty;e++)o.push(this.generate({...t,qty:1,verbose:!1}));else{var i=[];for(let e=0;e<4;e++)i.push(random.int(0,256));o.push(i.join("."))}e=1<t.qty?o:o[0];return t.verbose&&(log.info(`IPv4 address${1<t.qty?"es":""} generated!`),log.info(1==t.qty?e:e.join(", "))),e}},validate(e,t={}){var o="https://github.com/adamlui/js-utils/tree/main/generate-ip/docs/#ipv4validateaddress-options",i={verbose:!0};return log.prefix="ipv4.validate()","string"!=typeof e?(log.error("1st arg <address> must be a string."),log.helpURL(o)):validateOptions({options:t,defaultOptions:i,helpURL:o,exampleCall:"ipv4.validate('0.0.255.255', { verbose: false })"})?((t={...i,...t}).verbose&&log.info(`Validating ${e}...`),i=!(4!=(o=e.split(".")).length||o.some(e=>!/^\d+$/.test(e)||parseInt(e,10)<0||255<parseInt(e,10))),t.verbose&&log.info(`IP is ${i?"":"in"}valid IPv4 address!`),i):void 0}},ipv6={generate(i={}){var e={verbose:!0,qty:1,leadingZeros:!1,doubleColon:!0};if(log.prefix="ipv6.generate()",validateOptions({options:i,defaultOptions:e,helpURL:"https://github.com/adamlui/js-utils/tree/main/generate-ip/docs/#ipv6generateoptions",exampleCall:"ipv6.generate({ leadingZeros: true, qty: 5 })"})){(i={...e,...i}).verbose&&log.info(`Generating IPv6 address${1<i.qty?"es":""}...`);var r=[];if(1<i.qty)for(let e=0;e<i.qty;e++)r.push(this.generate({...i,qty:1,verbose:!1}));else{let t=[],{qty:e,...o}=i;for(let e=0;e<8;e++)t.push(random.hex(4));r.push(this.format(t.join(":"),{...o,verbose:!1}))}e=1<i.qty?r:r[0];return i.verbose&&(log.info(`IPv6 address${1<i.qty?"es":""} generated!`),log.info(1==i.qty?e:e.join(", "))),e}},format(t,o={}){var i="https://github.com/adamlui/js-utils/tree/main/generate-ip/docs/#ipv6formatipv6address-options",r={verbose:!0,leadingZeros:!1,doubleColon:!0};if(log.prefix="ipv6.format()","string"!=typeof t)return log.error("1st arg <ipv6address> must be a string."),log.helpURL(i);if(!this.validate(t,{verbose:!1}))return log.error(t+" is not a valid IPv6 address."),log.helpURL(i);if(validateOptions({options:o,defaultOptions:r,helpURL:i,exampleCall:"ipv6.format('0d::ffff:192.1.56.10/96', { leadingZeros: true, doubleColon: false })"})){o={...r,...o};let e=t;if(e=o.doubleColon?(o.verbose&&log.info("Replacing zero series w/ '::'..."),e.replace(/:(?:0+:)+/,"::")):(o.verbose&&log.info("Expanding '::' into zero series..."),i=e.split(":").filter(Boolean).length,r=o.leadingZeros?"0000":"0",i=Array(8-i).fill(r).join(":"),e.replace("::",`:${i}:`)),o.leadingZeros){o.verbose&&log.info("Adding leading zeros...");var a=e.split(":");for(let e=0;e<a.length;e++)for(;a[e].length<4;)a[e]="0"+a[e];e=a.join(":")}else o.verbose&&log.info("Stripping leading zeros..."),e=t.replace(/(^|(?<=:))0+(?!:)/g,"$1");return o.verbose&&(e!=t?log.info("IP formatted successfully!"):log.info("IP already formatted to specs."),log.info(e)),e}},validate(o,i={}){var r="https://github.com/adamlui/js-utils/tree/main/generate-ip/docs/#ipv6validateaddress-options",a={verbose:!0};if(log.prefix="ipv6.validate()","string"!=typeof o)return log.error("1st arg <address> must be a string."),log.helpURL(r);if(validateOptions({options:i,defaultOptions:a,helpURL:r,exampleCall:"ipv6.validate('0:0:0:0:0:ffff:192.1.56.10/96', { verbose: false })"})){(i={...a,...i}).verbose&&log.info(`Validating ${o}...`);let e=o.split(/::?/),t=e[e.length-1];r=!(o.includes("::")&&2<o.split("::").length||/:{3,}/.test(o)||e.length<2||8<e.length||e.some(e=>!(/^[\da-f]{1,4}$/i.test(e)||e==t&&ipv4.validate(t.replace(/\/(?:12[0-8]|[1-9]?\d)$/,""),{verbose:!1}))));return i.verbose&&log.info(`IP is ${r?"":"in"}valid IPv6 address!`),r}}},mac={generate(t={}){var e={verbose:!0,qty:1};if(log.prefix="mac.generate()",validateOptions({options:t,defaultOptions:e,helpURL:"https://github.com/adamlui/js-utils/tree/main/generate-ip/docs/#macgenerateoptions",exampleCall:"mac.generate({ verbose: false, qty: 2 })"})){(t={...e,...t}).verbose&&log.info(`Generating MAC address${1<t.qty?"es":""}...`);var o=[];if(1<t.qty)for(let e=0;e<t.qty;e++)o.push(this.generate({...t,qty:1,verbose:!1}));else{var[e,i]=Array.from({length:2},()=>{var t=[];for(let e=0;e<3;e++)t.push(random.hex(2));return t.join(":")});o.push(e+":"+i)}e=1<t.qty?o:o[0];return t.verbose&&(log.info(`MAC address${1<t.qty?"es":""} generated!`),log.info(1==t.qty?e:e.join(", "))),e}},validate(e,t={}){var o="https://github.com/adamlui/js-utils/tree/main/generate-ip/docs/#macvalidateaddress-options",i={verbose:!0};return log.prefix="mac.validate()","string"!=typeof e?(log.error("1st arg <address> must be a string."),log.helpURL(o)):validateOptions({options:t,defaultOptions:i,helpURL:o,exampleCall:"mac.validate('00:1A:2B:3C:4D:5E', { verbose: false })"})?((t={...i,...t}).verbose&&log.info(`Validating ${e}...`),o=/^(?:[\da-f]{2}[:-]){5}[\da-f]{2}$/i.test(e),t.verbose&&log.info(`Address is ${o?"":"in"}valid MAC address!`),o):void 0}};function validateOptions({options:e,defaultOptions:t,helpURL:o,exampleCall:i}){var r,a,s=Object.keys(t).filter(e=>"boolean"==typeof t[e]),l=Object.keys(t).filter(e=>Number.isInteger(t[e]));if("object"!=typeof e)return r=i.split(",").findIndex(e=>e.trim().startsWith("{"))+1,r+=["st","nd","rd"][r-1]||"th",log.error(`${"0th"==r?"[O":r+" arg [o"}ptions] can only be an object of key/vals.`),log.info("Example valid call:",i),log.validOptions(t),log.helpURL(o),!1;for(a in e){if(!Object.prototype.hasOwnProperty.call(t,a))return log.error(`\`${a}\` is an invalid option.`),log.validOptions(t),log.helpURL(o),!1;if(s.includes(a)&&"boolean"!=typeof e[a])return log.error(`[${a}] option can only be \`true\` or \`false\`.`),log.helpURL(o),!1;if(l.includes(a)&&(e[a]=parseInt(e[a],10),isNaN(e[a])||e[a]<1))return log.error(`[${a}] option can only be an integer > 0.`),log.helpURL(o),!1}return!0}let random={int(e,t){var o;return"undefined"==typeof require?(o=(window.crypto||window.msCrypto)?.getRandomValues(new Uint32Array(1))[0]/4294967295||Math.random(),Math.floor(o*(t-e))+e):require("crypto").randomInt(e,t)},hex(t){let o="";for(let e=0;e<t;e++)o+=random.int(0,16).toString(16);return o}},log={prefix:api.name,error(...e){console.error(this.prefix+" ยป ERROR:",...e)},helpURL(e=api.urls?.docs){this.info("For more help, please visit",e)},info(...e){console.info(this.prefix+" ยป",...e)},validOptions(e){var t=Object.keys(e).join(", "),e=JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," ");this.info(`Valid options: [${t}]`),this.info("If omitted, default settings are: "+e)}};api.exports={ipv4:ipv4,ipv6:ipv6,mac:mac};try{module.exports={...api.exports}}catch(e){}try{Object.assign(window,api.exports)}catch(e){}for(let t in api.aliases)api.aliases[t].forEach(e=>{try{module.exports[e]??=module.exports[t]}catch(e){}try{window[e]??=window[t]}catch(e){}});
|
package/docs/README.md
CHANGED
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
<a href="#%EF%B8%8F-mit-license">
|
|
12
12
|
<img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
13
|
-
<a href="https://github.com/adamlui/js-utils/releases/tag/generate-ip-2.
|
|
14
|
-
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.
|
|
13
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/generate-ip-2.6.0">
|
|
14
|
+
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.6.0-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
15
15
|
<a href="https://www.npmjs.com/package/generate-ip?activeTab=code">
|
|
16
16
|
<img height=31 src="https://img.shields.io/npm/unpacked-size/generate-ip?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
|
|
17
|
-
<a href="https://github.com/adamlui/js-utils/blob/generate-ip-2.
|
|
18
|
-
<img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/generate-ip/dist/generate-ip.min.js?branch=generate-ip-2.
|
|
17
|
+
<a href="https://github.com/adamlui/js-utils/blob/generate-ip-2.6.0/generate-ip/dist/generate-ip.min.js">
|
|
18
|
+
<img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/generate-ip/dist/generate-ip.min.js?branch=generate-ip-2.6.0&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
19
19
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:generate-ip/src/generate-ip.js">
|
|
20
20
|
<img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Agenerate-ip%2Fsrc%2Fgenerate-ip.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
|
|
21
21
|
<a href="https://github.com/toolleeo/cli-apps#networking">
|
|
@@ -71,7 +71,7 @@ $ npm install generate-ip
|
|
|
71
71
|
#### ECMAScript*:
|
|
72
72
|
|
|
73
73
|
```js
|
|
74
|
-
import { ipv4, ipv6, mac } from 'generate-ip'
|
|
74
|
+
import { ipv4, ipv6, mac } from 'generate-ip'
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
#### CommonJS:
|
|
@@ -87,14 +87,14 @@ const { ipv4, ipv6, mac } = require('generate-ip')
|
|
|
87
87
|
#### <> HTML script tag:
|
|
88
88
|
|
|
89
89
|
```html
|
|
90
|
-
<script src="https://cdn.jsdelivr.net/npm/generate-ip@2.
|
|
90
|
+
<script src="https://cdn.jsdelivr.net/npm/generate-ip@2.6.0/dist/generate-ip.min.js"></script>
|
|
91
91
|
```
|
|
92
92
|
|
|
93
93
|
#### ES6:
|
|
94
94
|
|
|
95
95
|
```js
|
|
96
96
|
(async () => {
|
|
97
|
-
await import('https://cdn.jsdelivr.net/npm/generate-ip@2.
|
|
97
|
+
await import('https://cdn.jsdelivr.net/npm/generate-ip@2.6.0/dist/generate-ip.min.js')
|
|
98
98
|
// Your code here...
|
|
99
99
|
})()
|
|
100
100
|
```
|
|
@@ -103,7 +103,7 @@ const { ipv4, ipv6, mac } = require('generate-ip')
|
|
|
103
103
|
|
|
104
104
|
```js
|
|
105
105
|
...
|
|
106
|
-
// @require https://cdn.jsdelivr.net/npm/generate-ip@2.
|
|
106
|
+
// @require https://cdn.jsdelivr.net/npm/generate-ip@2.6.0/dist/generate-ip.min.js
|
|
107
107
|
// ==/UserScript==
|
|
108
108
|
|
|
109
109
|
// Your code here...
|
|
@@ -111,7 +111,7 @@ const { ipv4, ipv6, mac } = require('generate-ip')
|
|
|
111
111
|
|
|
112
112
|
<br>
|
|
113
113
|
|
|
114
|
-
๐ **Note:** To always import the latest version (not recommended in production!) remove the `@2.
|
|
114
|
+
๐ **Note:** To always import the latest version (not recommended in production!) remove the `@2.6.0` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/generate-ip/dist/generate-ip.min.js`
|
|
115
115
|
|
|
116
116
|
<br>
|
|
117
117
|
|
|
@@ -369,17 +369,39 @@ Sample output:
|
|
|
369
369
|
```
|
|
370
370
|
Parameter options:
|
|
371
371
|
--qty=n Generate n IP address(es).
|
|
372
|
+
--ui-lang="code" ISO 639-1 code of language to display UI in.
|
|
373
|
+
--config="path/to/file" Load custom config file.
|
|
372
374
|
|
|
373
375
|
Boolean options:
|
|
374
376
|
-6, --ipv6 Generate IPv6 address.
|
|
375
377
|
-m, --mac Generate MAC address.
|
|
376
378
|
-q, --quiet Suppress all logging except errors.
|
|
377
379
|
|
|
378
|
-
|
|
380
|
+
Commands:
|
|
381
|
+
-i, --init Create config file (in project root).
|
|
379
382
|
-h, --help Display help screen.
|
|
380
383
|
-v, --version Show version number.
|
|
381
384
|
```
|
|
382
385
|
|
|
386
|
+
#
|
|
387
|
+
|
|
388
|
+
### Configuration file
|
|
389
|
+
|
|
390
|
+
**generate-ip** can be customized using `generate-ip.config.mjs` or `generate-ip.config.js` placed in your project root.
|
|
391
|
+
|
|
392
|
+
Example defaults:
|
|
393
|
+
|
|
394
|
+
```js
|
|
395
|
+
export default {
|
|
396
|
+
qty: 5, // # of IPs to generate
|
|
397
|
+
ipv6mode: false, // Generate IPv6 address(es)
|
|
398
|
+
macMode: false, // Generate MAC address(es)
|
|
399
|
+
quietMode: true // Suppress all logging except errors
|
|
400
|
+
}
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
๐ก Use the `--init` command to generate a template `generate-ip.config.mjs` in your project root.
|
|
404
|
+
|
|
383
405
|
<br>
|
|
384
406
|
|
|
385
407
|
<img height=6px width="100%" src="https://assets.js-utils.org/images/separators/aqua-gradient.png?v=0d36e26">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generate-ip",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Randomly generate, format, and validate IPv4 + IPv6 + MAC addresses.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Adam Lui",
|
|
@@ -38,7 +38,12 @@
|
|
|
38
38
|
"doc": "./docs"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build": "
|
|
41
|
+
"build": "node utils/build",
|
|
42
|
+
"build:js": "node utils/build --js",
|
|
43
|
+
"build:data": "node utils/build --data",
|
|
44
|
+
"build:json": "node utils/build --json",
|
|
45
|
+
"debug": "node src/cli --debug",
|
|
46
|
+
"translate": "py utils/translate-en-messages.py",
|
|
42
47
|
"bump:patch": "bash utils/bump.sh patch",
|
|
43
48
|
"bump:minor": "bash utils/bump.sh minor",
|
|
44
49
|
"bump:major": "bash utils/bump.sh major"
|
|
@@ -66,6 +71,6 @@
|
|
|
66
71
|
"node-clipboardy": "^1.0.3"
|
|
67
72
|
},
|
|
68
73
|
"devDependencies": {
|
|
69
|
-
"@adamlui/minify.js": "^2.1
|
|
74
|
+
"@adamlui/minify.js": "^2.2.1"
|
|
70
75
|
}
|
|
71
76
|
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ยฉ 2024โ2026 Adam Lui & contributors under the MIT license.
|
|
3
|
-
* Source: https://github.com/adamlui/js-utils/tree/main/generate-ip/src
|
|
4
|
-
* Documentation: https://github.com/adamlui/js-utils/tree/main/generate-ip/docs
|
|
5
|
-
*/
|
|
6
|
-
module.exports={helpCmdAndDocURL(){console.info(`
|
|
7
|
-
${app.msgs.info_moreHelp}, ${app.msgs.info_type} ${app.name} --help' ${app.msgs.info_or} ${app.msgs.info_visit}
|
|
8
|
-
`+app.colors.bw+app.urls.docs+app.colors.nc)},help(p=["header","usage","paramOptions","flags","infoCmds"]){app.prefix=""+app.colors.tlBG+app.colors.blk+`[30m ${app.name} ${app.colors.nc} `;let o={header:[`
|
|
9
|
-
โ ${app.prefix}${app.msgs.appCopyright||`ยฉ ${app.copyrightYear} ${app.author} under the ${app.license} license`}.`,""+app.prefix+app.msgs.prefix_source+": "+app.urls.src],usage:[`
|
|
10
|
-
${app.colors.bw}o ${app.msgs.helpSection_usage}:`+app.colors.nc,` ${app.colors.bw}ยป `+app.colors.bg+app.cmdFormat+app.colors.nc],paramOptions:[`
|
|
11
|
-
${app.colors.bw}o ${app.msgs.helpSection_paramOptions}:`+app.colors.nc,` --qty=n ${app.msgs.optionDesc_qty}.`],flags:[`
|
|
12
|
-
${app.colors.bw}o ${app.msgs.helpSection_flags}:`+app.colors.nc,` -6, --ipv6 ${app.msgs.optionDesc_ipv6}.`,` -m, --mac ${app.msgs.optionDesc_mac}.`,` -q, --quiet ${app.msgs.optionDesc_quiet}.`],infoCmds:[`
|
|
13
|
-
${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=>o[n]?.forEach(o=>{{var r=/header|usage/.test(n)?1:29;let s=process.stdout.columns||80,e=[],p=o.match(/\S+|\s+/g),a="";p.forEach(p=>{var o=s-(e.length?r:0);a.length+"| ".length+p.length>o&&(e.push(e.length?a.trimStart():a),a=""),a+=p}),e.push(e.length?a.trimStart():a),e.forEach((p,o)=>console.info("| "+(0==o?p:" ".repeat(r)+p)))}})),console.info(`
|
|
14
|
-
${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"),o=require("child_process").execSync(`npm view ${JSON.stringify(app.name)} version`).toString().trim()||"none";let s,e=process.cwd();for(;"/"!=e;){var a=p.join(e,"package.json");if(require("fs").existsSync(a)){a=require(a);s=(a.dependencies?.[app.name]||a.devDependencies?.[app.name])?.match(/^[~^>=]?\d+\.\d+\.\d+$/)?.[1]||"none";break}e=p.dirname(e)}console.info(`
|
|
15
|
-
${app.msgs.prefix_globalVer}: ${o}
|
|
16
|
-
${app.msgs.prefix_localVer}: `+s)}};
|