rkeygen 1.0.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/LICENSE +15 -0
- package/README.md +115 -0
- package/bin/rk.js +93 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Gideon Onyegbula
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# random_key_generator
|
|
2
|
+
|
|
3
|
+
`random_key_generator` is a small Node.js CLI for generating random values for local development, secrets, and quick one-off copies to the clipboard.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Generate random hexadecimal strings.
|
|
8
|
+
- Generate UUIDs.
|
|
9
|
+
- Generate passwords with a configurable length.
|
|
10
|
+
- Print a ready-to-use environment variable block.
|
|
11
|
+
- Copy generated values directly to the clipboard.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Install the package locally:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
If you want to use the CLI globally during development, link it:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm link
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
The CLI is exposed as `rk`.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
rk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Generate a hex string of a specific length:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
rk 32
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Generate a UUID:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
rk uuid
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Generate a password:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
rk pass
|
|
51
|
+
rk pass 24
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Print a sample environment block:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
rk env
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Copy a generated value to the clipboard:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
rk copy
|
|
64
|
+
rk copy pass
|
|
65
|
+
rk copy uuid
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Command Reference
|
|
69
|
+
|
|
70
|
+
| Command | Description |
|
|
71
|
+
| --- | --- |
|
|
72
|
+
| `rk` | Prints a random hexadecimal string with the default length. |
|
|
73
|
+
| `rk <number>` | Prints a hexadecimal string with the requested length. |
|
|
74
|
+
| `rk uuid` | Prints a random UUID. |
|
|
75
|
+
| `rk pass` | Prints a random password with the default length. |
|
|
76
|
+
| `rk pass <number>` | Prints a password with the requested length. |
|
|
77
|
+
| `rk env` | Prints a sample set of environment variables for app setup. |
|
|
78
|
+
| `rk copy` | Copies a default hex string to the clipboard. |
|
|
79
|
+
| `rk copy pass` | Copies a generated password to the clipboard. |
|
|
80
|
+
| `rk copy uuid` | Copies a generated UUID to the clipboard. |
|
|
81
|
+
|
|
82
|
+
## Examples
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
$ rk
|
|
86
|
+
488c319f0dca10ab0989447a021eb8b82dff76c6ecc4718448fbeda381d78f67
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
$ rk pass 12
|
|
91
|
+
Mq91c6cl6sP*
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
$ rk env
|
|
96
|
+
PORT=3000
|
|
97
|
+
JWT_SECRET=...
|
|
98
|
+
DB_PASSWORD=...
|
|
99
|
+
DB_NAME=mydatabase
|
|
100
|
+
SESSION_SECRET=...
|
|
101
|
+
COOKIE_SECRET=...
|
|
102
|
+
PASSWORD=...
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Project Structure
|
|
106
|
+
|
|
107
|
+
```text
|
|
108
|
+
package.json
|
|
109
|
+
bin/rk.js
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Notes
|
|
113
|
+
|
|
114
|
+
- The CLI uses Node's built-in `crypto` module for randomness.
|
|
115
|
+
- Clipboard support is provided by `clipboardy`.
|
package/bin/rk.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import crypto from "crypto";
|
|
4
|
+
import clipboard from "clipboardy";
|
|
5
|
+
const arg = process.argv[2];
|
|
6
|
+
const option = process.argv[3];
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
function randomHex(length = 64) {
|
|
11
|
+
return crypto
|
|
12
|
+
.randomBytes(Math.ceil(length / 2))
|
|
13
|
+
.toString("hex")
|
|
14
|
+
.slice(0, length);
|
|
15
|
+
}
|
|
16
|
+
function randomPassword(length = 16) {
|
|
17
|
+
const chars =
|
|
18
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
|
|
19
|
+
"abcdefghijklmnopqrstuvwxyz" +
|
|
20
|
+
"0123456789" +
|
|
21
|
+
"!@#$%^&*";
|
|
22
|
+
|
|
23
|
+
let password = "";
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < length; i++) {
|
|
26
|
+
const index = crypto.randomInt(0, chars.length);
|
|
27
|
+
password += chars[index];
|
|
28
|
+
}
|
|
29
|
+
return password;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
if (!arg) {
|
|
36
|
+
console.log(randomHex());
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
39
|
+
if (arg === "env") {
|
|
40
|
+
console.log(`PORT=3000`);
|
|
41
|
+
console.log(`JWT_SECRET=${randomHex(64)}`);
|
|
42
|
+
console.log(`DB_PASSWORD=${randomPassword(16)}`);
|
|
43
|
+
console.log(`DB_NAME=mydatabase`);
|
|
44
|
+
console.log(`SESSION_SECRET=${randomHex(64)}`);
|
|
45
|
+
console.log(`COOKIE_SECRET=${randomHex(64)}`);
|
|
46
|
+
console.log(`PASSWORD=${randomPassword(16)}`);
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
const length = Number(arg);
|
|
50
|
+
if (!Number.isNaN(length)) {
|
|
51
|
+
console.log(randomHex(length));
|
|
52
|
+
process.exit(0);
|
|
53
|
+
}
|
|
54
|
+
if (arg === "uuid") {
|
|
55
|
+
console.log(crypto.randomUUID());
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
if (arg === "pass" && option) {
|
|
59
|
+
const length = Number(option) || 16;
|
|
60
|
+
console.log(randomPassword(length));
|
|
61
|
+
process.exit(0);
|
|
62
|
+
}
|
|
63
|
+
if (arg === "pass") {
|
|
64
|
+
console.log(randomPassword());
|
|
65
|
+
process.exit(0);
|
|
66
|
+
}
|
|
67
|
+
if (arg === "copy") {
|
|
68
|
+
const target = process.argv[3];
|
|
69
|
+
|
|
70
|
+
let value;
|
|
71
|
+
|
|
72
|
+
switch (target) {
|
|
73
|
+
case "pass":
|
|
74
|
+
value = randomPassword();
|
|
75
|
+
break;
|
|
76
|
+
|
|
77
|
+
case "uuid":
|
|
78
|
+
value = crypto.randomUUID();
|
|
79
|
+
break;
|
|
80
|
+
|
|
81
|
+
default:
|
|
82
|
+
value = randomHex();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
await clipboard.write(value);
|
|
86
|
+
|
|
87
|
+
console.log("Copied to clipboard");
|
|
88
|
+
process.exit(0);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
console.error("Invalid argument");
|
|
93
|
+
process.exit(1);
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rkeygen",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "a simple random key generator built with nodejs",
|
|
5
|
+
"bin": {
|
|
6
|
+
"rk": "./bin/rk.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin"
|
|
10
|
+
],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=16"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
|
+
},
|
|
17
|
+
"keywords": ["random", "key", "generator", "password", "uuid", "nodejs", "cli", "clipboard"],
|
|
18
|
+
"author": "GFrosh",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/GFrosh/Key-Generator.git"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/GFrosh/Key-Generator#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/GFrosh/Key-Generator/issues"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"clipboardy": "^5.3.1"
|
|
31
|
+
}
|
|
32
|
+
}
|