@tushardev01/farm-password 1.0.4 → 1.0.6
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 +94 -94
- package/app.js +23 -18
- package/index.d.ts +52 -27
- package/package.json +36 -32
- package/utility.js +60 -39
package/README.md
CHANGED
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
# farm-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 @tushardev01/farm-password
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
# Usage (JavaScript / ESM)
|
|
25
|
-
```bash
|
|
26
|
-
import { genPassword, shuffleMax, genLowerLetters, genUpperLetters, genNumbers, genSymbols } from '@tushardev01/farm-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
|
-
|
|
56
|
-
```bash
|
|
57
|
-
genPassword(charLength?: number): string
|
|
58
|
-
Generates a password using default arrays
|
|
59
|
-
charLength – optional, default is 25
|
|
60
|
-
|
|
61
|
-
shuffleMax(charLength?: number, lists: string[][]): string[]
|
|
62
|
-
Randomly picks characters from multiple character arrays
|
|
63
|
-
charLength – optional, default 25
|
|
64
|
-
lists – array of string arrays, e.g., [genLowerLetters(), genNumbers()]
|
|
65
|
-
|
|
66
|
-
genLowerLetters(): string[]
|
|
67
|
-
Returns lowercase letters: ['a','b',...,'z']
|
|
68
|
-
|
|
69
|
-
genUpperLetters(): string[]
|
|
70
|
-
Returns uppercase letters: ['A','B',...,'Z']
|
|
71
|
-
|
|
72
|
-
genNumbers(): string[]
|
|
73
|
-
Returns numbers: ['0','1',...,'9']
|
|
74
|
-
|
|
75
|
-
genSymbols(): string[]
|
|
76
|
-
Returns symbols: ['!','@','#','$','%','^','&','*','(',')']
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### TypeScript Support
|
|
80
|
-
```bash
|
|
81
|
-
import { genPassword, shuffleMax } from 'gen-password';
|
|
82
|
-
|
|
83
|
-
const password: string = genPassword(16);
|
|
84
|
-
const chars: string[] = shuffleMax(12, [
|
|
85
|
-
genLowerLetters(),
|
|
86
|
-
genNumbers(),
|
|
87
|
-
]);
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Types are included automatically via index.d.ts.
|
|
91
|
-
|
|
92
|
-
### License
|
|
93
|
-
|
|
94
|
-
ISC © Tushar Kumar
|
|
1
|
+
# farm-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 @tushardev01/farm-password
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
# Usage (JavaScript / ESM)
|
|
25
|
+
```bash
|
|
26
|
+
import { genPassword, shuffleMax, genLowerLetters, genUpperLetters, genNumbers, genSymbols } from '@tushardev01/farm-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
|
+
|
|
56
|
+
```bash
|
|
57
|
+
genPassword(charLength?: number): string
|
|
58
|
+
Generates a password using default arrays
|
|
59
|
+
charLength – optional, default is 25
|
|
60
|
+
|
|
61
|
+
shuffleMax(charLength?: number, lists: string[][]): string[]
|
|
62
|
+
Randomly picks characters from multiple character arrays
|
|
63
|
+
charLength – optional, default 25
|
|
64
|
+
lists – array of string arrays, e.g., [genLowerLetters(), genNumbers()]
|
|
65
|
+
|
|
66
|
+
genLowerLetters(): string[]
|
|
67
|
+
Returns lowercase letters: ['a','b',...,'z']
|
|
68
|
+
|
|
69
|
+
genUpperLetters(): string[]
|
|
70
|
+
Returns uppercase letters: ['A','B',...,'Z']
|
|
71
|
+
|
|
72
|
+
genNumbers(): string[]
|
|
73
|
+
Returns numbers: ['0','1',...,'9']
|
|
74
|
+
|
|
75
|
+
genSymbols(): string[]
|
|
76
|
+
Returns symbols: ['!','@','#','$','%','^','&','*','(',')']
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### TypeScript Support
|
|
80
|
+
```bash
|
|
81
|
+
import { genPassword, shuffleMax } from 'gen-password';
|
|
82
|
+
|
|
83
|
+
const password: string = genPassword(16);
|
|
84
|
+
const chars: string[] = shuffleMax(12, [
|
|
85
|
+
genLowerLetters(),
|
|
86
|
+
genNumbers(),
|
|
87
|
+
]);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Types are included automatically via index.d.ts.
|
|
91
|
+
|
|
92
|
+
### License
|
|
93
|
+
|
|
94
|
+
ISC © Tushar Kumar
|
package/app.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import {genLowerLetters,
|
|
4
|
-
genUpperLetters,
|
|
5
|
-
genNumbers,
|
|
6
|
-
genSymbols,
|
|
7
|
-
shuffleMax,
|
|
8
|
-
genPassword
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import {genLowerLetters,
|
|
4
|
+
genUpperLetters,
|
|
5
|
+
genNumbers,
|
|
6
|
+
genSymbols,
|
|
7
|
+
shuffleMax,
|
|
8
|
+
genPassword,
|
|
9
|
+
randomNumIn,
|
|
10
|
+
shuffle,
|
|
11
|
+
} from './utility.js';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export{
|
|
15
|
+
genLowerLetters,
|
|
16
|
+
genUpperLetters,
|
|
17
|
+
genNumbers,
|
|
18
|
+
genSymbols,
|
|
19
|
+
shuffleMax,
|
|
20
|
+
genPassword,
|
|
21
|
+
randomNumIn,
|
|
22
|
+
shuffle
|
|
23
|
+
};
|
package/index.d.ts
CHANGED
|
@@ -1,27 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* @
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Generates an array of lowercase letters
|
|
3
|
+
*/
|
|
4
|
+
export function genLowerLetters(): string[];
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generates an array of uppercase letters
|
|
8
|
+
*/
|
|
9
|
+
export function genUpperLetters(): string[];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Generates an array of numeric characters
|
|
13
|
+
*/
|
|
14
|
+
export function genNumbers(): string[];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Generates an array of symbol characters
|
|
18
|
+
*/
|
|
19
|
+
export function genSymbols(): string[];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Generates a random number within a specified range (inclusive)
|
|
23
|
+
* @param x Lower bound
|
|
24
|
+
* @param y Upper bound
|
|
25
|
+
*/
|
|
26
|
+
export const randomNumIn: (x: number, y: number) => number;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Shuffles an array, with option for in-place modification
|
|
30
|
+
* @param arr Array to shuffle
|
|
31
|
+
* @param inPlace Whether to modify the original array
|
|
32
|
+
*/
|
|
33
|
+
export const shuffle: <T>(arr: T[], inPlace?: boolean) => T[];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Randomly picks characters from multiple character lists
|
|
37
|
+
* @param charLength Length of the resulting character array
|
|
38
|
+
* @param lists Array of character arrays
|
|
39
|
+
*/
|
|
40
|
+
export function shuffleMax(
|
|
41
|
+
charLength?: number,
|
|
42
|
+
lists?: string[][]
|
|
43
|
+
): string[];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Generate a password using default character lists
|
|
47
|
+
* @param charLength Length of the password
|
|
48
|
+
*/
|
|
49
|
+
export function genPassword(
|
|
50
|
+
charLength?: number
|
|
51
|
+
): string;
|
|
52
|
+
|
package/package.json
CHANGED
|
@@ -1,32 +1,36 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@tushardev01/farm-password",
|
|
3
|
-
"version": "1.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
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@tushardev01/farm-password",
|
|
3
|
+
"version": "1.0.6",
|
|
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
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/TusharKumar1007/farm-password"
|
|
32
|
+
},
|
|
33
|
+
"author": "Tushar Kumar",
|
|
34
|
+
"license": "ISC",
|
|
35
|
+
"description": "Generates passwords and provides handy character arrays."
|
|
36
|
+
}
|
package/utility.js
CHANGED
|
@@ -1,39 +1,60 @@
|
|
|
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
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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 randomNumIn=(x,y)=>{
|
|
22
|
+
return x+Math.round(Math.random()*(y-x));
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const shuffle=(arr,inPlace=false)=>{
|
|
27
|
+
const arrLength=arr.length;
|
|
28
|
+
if(!inPlace){
|
|
29
|
+
const protoArr=[...arr];
|
|
30
|
+
arr=protoArr;
|
|
31
|
+
}
|
|
32
|
+
for(let i=arrLength-1;i>=0;i--){
|
|
33
|
+
const j=randomNumIn(0,i);
|
|
34
|
+
[arr[i],arr[j]]=[arr[j],arr[i]];
|
|
35
|
+
}
|
|
36
|
+
if(!inPlace){
|
|
37
|
+
return arr;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
export const shuffleMax=(charLength=25,lists)=>{
|
|
43
|
+
const arr=[];
|
|
44
|
+
for (let i=0;i<charLength;i++){
|
|
45
|
+
const randomListNumber=Math.floor(Math.random()*lists.length);
|
|
46
|
+
const randomLst=lists[randomListNumber];
|
|
47
|
+
|
|
48
|
+
const randomNumber=Math.floor(Math.random()*randomLst.length);
|
|
49
|
+
arr.push(randomLst[randomNumber]);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return arr;
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const passLists=[genLowerLetters(),genNumbers(),genSymbols(),genUpperLetters()];
|
|
57
|
+
export const genPassword=(charLength=25)=>{
|
|
58
|
+
const password=shuffle(shuffleMax(charLength,passLists)).join('');
|
|
59
|
+
return password;
|
|
60
|
+
}
|