@tushardev01/farm-password 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/README.md +100 -0
- package/app.js +18 -0
- package/index.d.ts +27 -0
- package/package.json +33 -0
- package/utility.js +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# gen-password
|
|
2
|
+
|
|
3
|
+
A simple password generator for Node.js with handy character arrays and CLI support.
|
|
4
|
+
Generates secure random passwords using lowercase, uppercase, numbers, and symbols.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- Generate passwords of custom length
|
|
11
|
+
- Built-in arrays: lowercase letters, uppercase letters, numbers, symbols
|
|
12
|
+
- Shuffle characters from multiple arrays
|
|
13
|
+
- CLI support (`genpass`)
|
|
14
|
+
- TypeScript typings included
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install gen-password
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
# Usage (JavaScript / ESM)
|
|
25
|
+
```bash
|
|
26
|
+
import { genPassword, shuffleMax, genLowerLetters, genUpperLetters, genNumbers, genSymbols } from 'gen-password';
|
|
27
|
+
|
|
28
|
+
// Generate a password with default character sets
|
|
29
|
+
const password1 = genPassword(16);
|
|
30
|
+
console.log(password1); // Example: 'aB3@fGh1$Jk2LmN4'
|
|
31
|
+
|
|
32
|
+
// Create a custom character array
|
|
33
|
+
const customChars = [
|
|
34
|
+
genLowerLetters(),
|
|
35
|
+
genUpperLetters(),
|
|
36
|
+
genNumbers(),
|
|
37
|
+
genSymbols()
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
// Shuffle and pick 12 characters
|
|
41
|
+
const shuffled = shuffleMax(12, customChars).join('');
|
|
42
|
+
console.log(shuffled); // Example: '@B3a1C$dEfG2'
|
|
43
|
+
```
|
|
44
|
+
# CLI Usage
|
|
45
|
+
|
|
46
|
+
After installing, you can run:
|
|
47
|
+
```bash
|
|
48
|
+
npx genpass
|
|
49
|
+
# or, if installed globally
|
|
50
|
+
genpass
|
|
51
|
+
```
|
|
52
|
+
This generates a password with default settings.
|
|
53
|
+
|
|
54
|
+
### Functions
|
|
55
|
+
genPassword(charLength?: number): string
|
|
56
|
+
|
|
57
|
+
Generates a password using default arrays
|
|
58
|
+
|
|
59
|
+
charLength – optional, default is 25
|
|
60
|
+
|
|
61
|
+
shuffleMax(charLength?: number, lists: string[][]): string[]
|
|
62
|
+
|
|
63
|
+
Randomly picks characters from multiple character arrays
|
|
64
|
+
|
|
65
|
+
charLength – optional, default 25
|
|
66
|
+
|
|
67
|
+
lists – array of string arrays, e.g., [genLowerLetters(), genNumbers()]
|
|
68
|
+
|
|
69
|
+
genLowerLetters(): string[]
|
|
70
|
+
|
|
71
|
+
Returns lowercase letters: ['a','b',...,'z']
|
|
72
|
+
|
|
73
|
+
genUpperLetters(): string[]
|
|
74
|
+
|
|
75
|
+
Returns uppercase letters: ['A','B',...,'Z']
|
|
76
|
+
|
|
77
|
+
genNumbers(): string[]
|
|
78
|
+
|
|
79
|
+
Returns numbers: ['0','1',...,'9']
|
|
80
|
+
|
|
81
|
+
genSymbols(): string[]
|
|
82
|
+
|
|
83
|
+
Returns symbols: ['!','@','#','$','%','^','&','*','(',')']
|
|
84
|
+
|
|
85
|
+
### TypeScript Support
|
|
86
|
+
```bash
|
|
87
|
+
import { genPassword, shuffleMax } from 'gen-password';
|
|
88
|
+
|
|
89
|
+
const password: string = genPassword(16);
|
|
90
|
+
const chars: string[] = shuffleMax(12, [
|
|
91
|
+
genLowerLetters(),
|
|
92
|
+
genNumbers(),
|
|
93
|
+
]);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Types are included automatically via index.d.ts.
|
|
97
|
+
|
|
98
|
+
### License
|
|
99
|
+
|
|
100
|
+
ISC © Tushar Kumar
|
package/app.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import {genLowerLetters,
|
|
4
|
+
genUpperLetters,
|
|
5
|
+
genNumbers,
|
|
6
|
+
genSymbols,
|
|
7
|
+
shuffleMax,
|
|
8
|
+
genPassword
|
|
9
|
+
} from './utility.js';
|
|
10
|
+
|
|
11
|
+
export{
|
|
12
|
+
genLowerLetters,
|
|
13
|
+
genUpperLetters,
|
|
14
|
+
genNumbers,
|
|
15
|
+
genSymbols,
|
|
16
|
+
shuffleMax,
|
|
17
|
+
genPassword
|
|
18
|
+
};
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function genLowerLetters(): string[];
|
|
2
|
+
export function genUpperLetters(): string[];
|
|
3
|
+
export function genNumbers(): string[];
|
|
4
|
+
export function genSymbols(): string[];
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Randomly picks characters from multiple character lists
|
|
8
|
+
*
|
|
9
|
+
* @param charLength Length of the resulting character array
|
|
10
|
+
* @param lists Array of character arrays
|
|
11
|
+
* @returns Array of randomly selected characters
|
|
12
|
+
*/
|
|
13
|
+
export function shuffleMax(
|
|
14
|
+
charLength?: number,
|
|
15
|
+
lists: string[][]
|
|
16
|
+
): string[];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generate a password using default character lists
|
|
20
|
+
* (lowercase, uppercase, numbers, symbols)
|
|
21
|
+
*
|
|
22
|
+
* @param charLength Length of the password
|
|
23
|
+
* @returns Generated password string
|
|
24
|
+
*/
|
|
25
|
+
export function genPassword(
|
|
26
|
+
charLength?: number
|
|
27
|
+
): string;
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tushardev01/farm-password",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./app.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./app.js"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"genpass": "./app.js"
|
|
11
|
+
},
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"app.js",
|
|
15
|
+
"utility.js",
|
|
16
|
+
"README.md",
|
|
17
|
+
"index.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"password",
|
|
24
|
+
"password-generator",
|
|
25
|
+
"cli",
|
|
26
|
+
"security",
|
|
27
|
+
"generator"
|
|
28
|
+
],
|
|
29
|
+
"author": "Tushar Kumar",
|
|
30
|
+
"license": "ISC",
|
|
31
|
+
"description": "Generates passwords and provides handy character arrays."
|
|
32
|
+
}
|
|
33
|
+
|
package/utility.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
export const genLowerLetters=()=>{
|
|
3
|
+
return Array.from({length:26},(_,i)=>String.fromCharCode(i+97));
|
|
4
|
+
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const genUpperLetters=()=>{
|
|
8
|
+
return Array.from({length:26},(_,i)=>String.fromCharCode(i+65));
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const genSymbols=()=>{
|
|
13
|
+
return Array.from({length:14},(_,i)=>String.fromCharCode(i+33));
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
export const genNumbers=()=>{
|
|
17
|
+
return Array(10).fill(10).map((_,i)=>i)
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const shuffleMax=(charLength=25,lists)=>{
|
|
22
|
+
const arr=[];
|
|
23
|
+
for (let i=0;i<charLength;i++){
|
|
24
|
+
const randomListNumber=Math.floor(Math.random()*lists.length);
|
|
25
|
+
const randomLst=lists[randomListNumber];
|
|
26
|
+
|
|
27
|
+
const randomNumber=Math.floor(Math.random()*randomLst.length);
|
|
28
|
+
arr.push(randomLst[randomNumber]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return arr;
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const passLists=[genLowerLetters(),genNumbers(),genSymbols(),genUpperLetters()];
|
|
36
|
+
export const genPassword=(charLength=25)=>{
|
|
37
|
+
const password=shuffleMax(charLength,passLists).join('');
|
|
38
|
+
return password;
|
|
39
|
+
}
|