@code-coaching/random
Advanced tools
+13
-7
| #!/usr/bin/env node | ||
| import { readFile } from "fs/promises"; | ||
| import { randomID, randomUUID } from "../index.js"; | ||
| import { cli } from "./utils/cli.js"; | ||
| import { randomID, randomString, randomUUID } from "../index.js"; | ||
| import { cli, FLAGS } from "./utils/cli.js"; | ||
@@ -9,5 +9,2 @@ const pkg = JSON.parse(await readFile(new URL("../package.json", import.meta.url))); | ||
| switch (cli.input[0]) { | ||
| case "version": | ||
| console.log(pkg.version); | ||
| break; | ||
| case "uuid": | ||
@@ -17,8 +14,17 @@ console.log(randomUUID()); | ||
| case "id": | ||
| console.log(randomID(cli.flags.characters)); | ||
| console.log(randomID(cli.flags[FLAGS.CHARACTERS])); | ||
| break; | ||
| case "string": | ||
| console.log(randomString(cli.flags[FLAGS.CHARACTERS])); | ||
| break; | ||
| default: | ||
| cli.showHelp(0); | ||
| } | ||
| if (cli.flags.help) { | ||
| if (cli.flags[FLAGS.HELP]) { | ||
| cli.showHelp(0); | ||
| } | ||
| if (cli.flags[FLAGS.VERSION]) { | ||
| console.log(pkg.version); | ||
| } |
+29
-5
@@ -31,2 +31,17 @@ import chalk from "chalk"; | ||
| const helpTextString = ` | ||
| Description | ||
| Generate a random string. | ||
| Usage | ||
| ${green(`npx @code-coaching/random`)} ${cyan(`string`)} ${yellow(`[--option]`)} | ||
| Options | ||
| ${yellow(`-c`)}, ${yellow(`--characters`)} Amount of random characters to print ${dim(`(DEFAULT: 8)`)} | ||
| Examples | ||
| ${green(`npx @code-coaching/random string`)} | ||
| ${green(`npx @code-coaching/random string -c 4`)} | ||
| `; | ||
| const helpText = ` | ||
@@ -50,4 +65,13 @@ Usage | ||
| ${helpTextUUID} | ||
| ${helpTextString} | ||
| `; | ||
| const FLAGS = { | ||
| AD: "ad", | ||
| HELP: "help", | ||
| VERSION: "version", | ||
| CHARACTERS: "characters", | ||
| }; | ||
| const options = { | ||
@@ -58,7 +82,7 @@ inferType: true, | ||
| flags: { | ||
| ad: { | ||
| [FLAGS.AD]: { | ||
| type: "boolean", | ||
| default: true, | ||
| }, | ||
| help: { | ||
| [FLAGS.HELP]: { | ||
| type: "boolean", | ||
@@ -68,3 +92,3 @@ default: false, | ||
| }, | ||
| version: { | ||
| [FLAGS.VERSION]: { | ||
| type: "boolean", | ||
@@ -74,3 +98,3 @@ default: false, | ||
| }, | ||
| characters: { | ||
| [FLAGS.CHARACTERS]: { | ||
| type: "number", | ||
@@ -85,2 +109,2 @@ default: 8, | ||
| export { cli }; | ||
| export { cli, FLAGS }; |
+1
-1
| { | ||
| "name": "@code-coaching/random", | ||
| "version": "1.0.5", | ||
| "version": "1.1.0", | ||
| "description": "This package provides functions to generate random stuff (strings, numbers, uuid). It can be used as a dependency for other packages. It can be used as a CLI tool.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
6489
12.5%143
19.17%