password-genie-cli 2.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/PUBLISH.md ADDED
@@ -0,0 +1,68 @@
1
+ # Publishing Guide
2
+
3
+ ## Prerequisites
4
+
5
+ - Node.js 14+
6
+ - npm account ([sign up](https://www.npmjs.com/signup))
7
+
8
+ ## Steps
9
+
10
+ ### 1. Log in to npm
11
+
12
+ ```sh
13
+ npm login
14
+ ```
15
+
16
+ Enter your username, password, and email when prompted.
17
+
18
+ ### 2. Update the version (optional)
19
+
20
+ ```sh
21
+ # Patch (bug fixes) — 1.0.0 → 1.0.1
22
+ npm version patch
23
+
24
+ # Minor (new features, backward-compatible) — 1.0.0 → 1.1.0
25
+ npm version minor
26
+
27
+ # Major (breaking changes) — 1.0.0 → 2.0.0
28
+ npm version major
29
+ ```
30
+
31
+ ### 3. Publish
32
+
33
+ ```sh
34
+ npm publish
35
+ ```
36
+
37
+ ### 4. Verify
38
+
39
+ Visit `https://www.npmjs.com/package/password-genie` or run:
40
+
41
+ ```sh
42
+ npm view password-genie
43
+ ```
44
+
45
+ ## Updating
46
+
47
+ Make changes, bump the version, then publish again:
48
+
49
+ ```sh
50
+ npm version patch
51
+ npm publish
52
+ ```
53
+
54
+ ## Scoped packages (optional)
55
+
56
+ If you want to publish under your username scope (e.g. `@yourusername/password-genie`):
57
+
58
+ 1. Change `name` in `package.json` to `@yourusername/password-genie`
59
+ 2. Run `npm publish --access public`
60
+
61
+ ## Useful commands
62
+
63
+ | Command | Description |
64
+ | ------------------------------ | -------------------------- |
65
+ | `npm whoami` | Check logged-in user |
66
+ | `npm logout` | Log out |
67
+ | `npm unpublish <pkg>@<ver>` | Remove a specific version |
68
+ | `npm deprecate <pkg>@<ver> <msg>` | Deprecate a version |
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # password-genie
2
+
3
+ A simple and secure password generator that creates random, unique passwords based on user-defined length and complexity requirements.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install password-genie
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ const passwordGenie = require('password-genie');
15
+
16
+ // Generate a password of length 12 with default complexity (lowercase only)
17
+ const password = passwordGenie.generate(12);
18
+ console.log(password); // e.g. "kqxjwmfobqje"
19
+
20
+ // Generate a password of length 16 with custom complexity
21
+ const complexPassword = passwordGenie.generate(16, {
22
+ uppercase: true,
23
+ numbers: true,
24
+ specialChars: true,
25
+ });
26
+ console.log(complexPassword); // e.g. "Y7$hL2#pQ9!mZ4&x"
27
+ ```
28
+
29
+ ## API
30
+
31
+ ### `generate(length, options)`
32
+
33
+ | Param | Type | Default | Description |
34
+ | --------- | ------ | ------- | --------------------------------- |
35
+ | `length` | number | — | Length of the password to generate |
36
+ | `options` | object | `{}` | Complexity options (see below) |
37
+
38
+ **Options**
39
+
40
+ | Property | Type | Default | Description |
41
+ | -------------- | ------- | ------- | -------------------------- |
42
+ | `uppercase` | boolean | `false` | Include uppercase letters |
43
+ | `numbers` | boolean | `false` | Include numbers |
44
+ | `specialChars` | boolean | `false` | Include special characters |
45
+
46
+ ## Security
47
+
48
+ Uses Node.js `crypto.randomInt` — a cryptographically secure pseudo-random number generator (CSPRNG). No modulo bias.
49
+
50
+ ## License
51
+
52
+ MIT
package/index.js ADDED
@@ -0,0 +1,39 @@
1
+ const crypto = require('crypto');
2
+
3
+ const LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';
4
+ const UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
5
+ const DIGITS = '0123456789';
6
+ const SPECIAL = '!@#$%^&*()_+~`|}{[]:;?><,./-=';
7
+
8
+ function getRandomChar(charSet) {
9
+ const index = crypto.randomInt(charSet.length);
10
+ return charSet[index];
11
+ }
12
+
13
+ function generate(length, options = {}) {
14
+ let charSet = LOWERCASE;
15
+ let password = '';
16
+
17
+ if (options.uppercase) {
18
+ password += getRandomChar(UPPERCASE);
19
+ charSet += UPPERCASE;
20
+ }
21
+
22
+ if (options.numbers) {
23
+ password += getRandomChar(DIGITS);
24
+ charSet += DIGITS;
25
+ }
26
+
27
+ if (options.specialChars) {
28
+ password += getRandomChar(SPECIAL);
29
+ charSet += SPECIAL;
30
+ }
31
+
32
+ for (let i = password.length; i < length; i++) {
33
+ password += getRandomChar(charSet);
34
+ }
35
+
36
+ return password;
37
+ }
38
+
39
+ module.exports = { generate };
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "password-genie-cli",
3
+ "version": "2.0.0",
4
+ "description": "A simple and secure password generator that creates random, unique passwords based on user-defined length and complexity requirements.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "jest"
8
+ },
9
+ "keywords": [
10
+ "password",
11
+ "generator",
12
+ "security",
13
+ "crypto"
14
+ ],
15
+ "license": "MIT",
16
+ "devDependencies": {
17
+ "jest": "^29.0.0"
18
+ }
19
+ }
package/test.js ADDED
@@ -0,0 +1,35 @@
1
+ const passwordGenie = require('./index');
2
+
3
+ describe('passwordGenie', () => {
4
+ it('generates a password of the specified length', () => {
5
+ const password = passwordGenie.generate(12);
6
+ expect(password.length).toBe(12);
7
+ });
8
+
9
+ it('includes uppercase letters when requested', () => {
10
+ const password = passwordGenie.generate(12, { uppercase: true });
11
+ expect(password).toEqual(expect.stringMatching(/[A-Z]/));
12
+ });
13
+
14
+ it('includes numbers when requested', () => {
15
+ const password = passwordGenie.generate(12, { numbers: true });
16
+ expect(password).toEqual(expect.stringMatching(/[0-9]/));
17
+ });
18
+
19
+ it('includes special characters when requested', () => {
20
+ const password = passwordGenie.generate(12, { specialChars: true });
21
+ expect(password).toEqual(expect.stringMatching(/[^a-zA-Z0-9]/));
22
+ });
23
+
24
+ it('includes all character types when all options enabled', () => {
25
+ const password = passwordGenie.generate(20, {
26
+ uppercase: true,
27
+ numbers: true,
28
+ specialChars: true,
29
+ });
30
+ expect(password.length).toBe(20);
31
+ expect(password).toEqual(expect.stringMatching(/[A-Z]/));
32
+ expect(password).toEqual(expect.stringMatching(/[0-9]/));
33
+ expect(password).toEqual(expect.stringMatching(/[^a-zA-Z0-9]/));
34
+ });
35
+ });