@tushardev01/farm-password 1.0.7 → 1.0.8

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.
Files changed (4) hide show
  1. package/README.md +105 -105
  2. package/index.d.ts +25 -17
  3. package/package.json +1 -1
  4. package/utility.js +86 -56
package/README.md CHANGED
@@ -1,105 +1,105 @@
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
- ## Package Information
7
-
8
- 🔗 **npm Package**: [https://www.npmjs.com/package/@tushardev01/farm-password](https://www.npmjs.com/package/@tushardev01/farm-password)
9
-
10
- ---
11
-
12
- ## Features
13
-
14
- - Generate passwords of custom length
15
- - Built-in arrays: lowercase letters, uppercase letters, numbers, symbols
16
- - Shuffle characters from multiple arrays
17
- - CLI support (`genpass`)
18
- - TypeScript typings included
19
-
20
- ---
21
-
22
- ## Installation
23
-
24
- ```bash
25
- npm install @tushardev01/farm-password
26
- ```
27
-
28
- # Usage (JavaScript / ESM)
29
- ```bash
30
- import { genPassword, shuffleMax, genLowerLetters, genUpperLetters, genNumbers, genSymbols, randomNumIn, shuffle } from '@tushardev01/farm-password';
31
-
32
- // Generate a password with default character sets
33
- const password1 = genPassword(16);
34
- console.log(password1); // Example: 'aB3@fGh1$Jk2LmN4'
35
-
36
- // Create a custom character array
37
- const customChars = [
38
- genLowerLetters(),
39
- genUpperLetters(),
40
- genNumbers(),
41
- genSymbols()
42
- ];
43
-
44
- // Shuffle and pick 12 characters
45
- const shuffled = shuffle(shuffleMax(12, customChars)).join('');
46
- console.log(shuffled); // Example: '@B3a1C$dEfG2'
47
- ```
48
- # CLI Usage
49
-
50
- After installing, you can run:
51
- ```bash
52
- npx genpass
53
- # or, if installed globally
54
- genpass
55
- ```
56
- This generates a password with default settings.
57
-
58
- ### Functions
59
-
60
- ```bash
61
- genPassword(charLength?: number): string
62
- Generates a password using default arrays
63
- charLength ΓÇô optional, default is 25
64
-
65
- shuffleMax(charLength?: number, lists: string[][]): string[]
66
- Randomly picks characters from multiple character arrays
67
- charLength ΓÇô optional, default 25
68
- lists ΓÇô array of string arrays, e.g., [genLowerLetters(), genNumbers()]
69
-
70
- genLowerLetters(): string[]
71
- Returns lowercase letters: ['a','b',...,'z']
72
-
73
- genUpperLetters(): string[]
74
- Returns uppercase letters: ['A','B',...,'Z']
75
-
76
- genNumbers(): string[]
77
- Returns numbers: ['0','1',...,'9']
78
-
79
- genSymbols(): string[]
80
- Returns symbols: ['!','@','#','$','%','^','&','*','(',')']
81
-
82
- randomNumIn(x,y): number
83
- Returns a random Number [x,y] i.e. including x,y and numbers in between
84
-
85
- shuffle(arr: any[],inPlace: boolean): any[]
86
- Returns a new array or the same one with items shuffled
87
- ```
88
-
89
- ### TypeScript Support
90
- ```bash
91
- import { genPassword, shuffleMax, shuffle, randomNumIn } from '@tushardev01/farm-password';
92
-
93
- const password: string = genPassword(16);
94
- const chars: string[] = shuffleMax(12, [
95
- genLowerLetters(),
96
- genNumbers(),
97
- ]);
98
- ```
99
-
100
- Types are included automatically via index.d.ts.
101
-
102
- ### License
103
-
104
- ISC © Tushar Kumar
105
-
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
+ ## Package Information
7
+
8
+ 🔗 **npm Package**: [https://www.npmjs.com/package/@tushardev01/farm-password](https://www.npmjs.com/package/@tushardev01/farm-password)
9
+
10
+ ---
11
+
12
+ ## Features
13
+
14
+ - Generate passwords of custom length
15
+ - Built-in arrays: lowercase letters, uppercase letters, numbers, symbols
16
+ - Shuffle characters from multiple arrays
17
+ - CLI support (`genpass`)
18
+ - TypeScript typings included
19
+
20
+ ---
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install @tushardev01/farm-password
26
+ ```
27
+
28
+ # Usage (JavaScript / ESM)
29
+ ```bash
30
+ import { genPassword, shuffleMax, genLowerLetters, genUpperLetters, genNumbers, genSymbols, randomNumIn, shuffle } from '@tushardev01/farm-password';
31
+
32
+ // Generate a password with default character sets
33
+ const password1 = genPassword(16);
34
+ console.log(password1); // Example: 'aB3@fGh1$Jk2LmN4'
35
+
36
+ // Create a custom character array
37
+ const customChars = [
38
+ genLowerLetters(),
39
+ genUpperLetters(),
40
+ genNumbers(),
41
+ genSymbols()
42
+ ];
43
+
44
+ // Shuffle and pick 12 characters
45
+ const shuffled = shuffle(shuffleMax(12, customChars)).join('');
46
+ console.log(shuffled); // Example: '@B3a1C$dEfG2'
47
+ ```
48
+ # CLI Usage
49
+
50
+ After installing, you can run:
51
+ ```bash
52
+ npx genpass
53
+ # or, if installed globally
54
+ genpass
55
+ ```
56
+ This generates a password with default settings.
57
+
58
+ ### Functions
59
+
60
+ ```bash
61
+ genPassword(charLength?: number): string
62
+ Generates a password using default arrays
63
+ charLength ΓÇô optional, default is 25
64
+
65
+ shuffleMax(charLength?: number, lists: string[][]): string[]
66
+ Randomly picks characters from multiple character arrays
67
+ charLength ΓÇô optional, default 25
68
+ lists ΓÇô array of string arrays, e.g., [genLowerLetters(), genNumbers()]
69
+
70
+ genLowerLetters(): string[]
71
+ Returns lowercase letters: ['a','b',...,'z']
72
+
73
+ genUpperLetters(): string[]
74
+ Returns uppercase letters: ['A','B',...,'Z']
75
+
76
+ genNumbers(): string[]
77
+ Returns numbers: ['0','1',...,'9']
78
+
79
+ genSymbols(): string[]
80
+ Returns symbols: ['!','@','#','$','%','^','&','*','(',')']
81
+
82
+ randomNumIn(x,y): number
83
+ Returns a random Number [x,y] i.e. including x,y and numbers in between
84
+
85
+ shuffle(arr: any[],inPlace: boolean): any[]
86
+ Returns a new array or the same one with items shuffled
87
+ ```
88
+
89
+ ### TypeScript Support
90
+ ```bash
91
+ import { genPassword, shuffleMax, shuffle, randomNumIn } from '@tushardev01/farm-password';
92
+
93
+ const password: string = genPassword(16);
94
+ const chars: string[] = shuffleMax(12, [
95
+ genLowerLetters(),
96
+ genNumbers(),
97
+ ]);
98
+ ```
99
+
100
+ Types are included automatically via index.d.ts.
101
+
102
+ ### License
103
+
104
+ ISC © Tushar Kumar
105
+
package/index.d.ts CHANGED
@@ -1,52 +1,60 @@
1
1
  /**
2
- * Generates an array of lowercase letters
2
+ * Generates an array of lowercase alphabetic characters ('a' to 'z').
3
+ * @returns {string[]} An array containing all lowercase letters.
3
4
  */
4
5
  export function genLowerLetters(): string[];
5
6
 
6
7
  /**
7
- * Generates an array of uppercase letters
8
+ * Generates an array of uppercase alphabetic characters ('A' to 'Z').
9
+ * @returns {string[]} An array containing all uppercase letters.
8
10
  */
9
11
  export function genUpperLetters(): string[];
10
12
 
11
13
  /**
12
- * Generates an array of numeric characters
14
+ * Generates an array of numeric characters ('0' to '9').
15
+ * @returns {string[]} An array containing all digits from 0 to 9.
13
16
  */
14
17
  export function genNumbers(): string[];
15
18
 
16
19
  /**
17
- * Generates an array of symbol characters
20
+ * Generates an array of common symbol characters (from ASCII code 33 to 46).
21
+ * @returns {string[]} An array containing common symbols like '!', '"', '#', etc.
18
22
  */
19
23
  export function genSymbols(): string[];
20
24
 
21
25
  /**
22
- * Generates a random number within a specified range (inclusive)
23
- * @param x Lower bound
24
- * @param y Upper bound
26
+ * Generates a random number between two given values, inclusive.
27
+ * @param {number} x The lower bound.
28
+ * @param {number} y The upper bound.
29
+ * @returns {number} A random number between x and y, inclusive.
25
30
  */
26
31
  export const randomNumIn: (x: number, y: number) => number;
27
32
 
28
33
  /**
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
34
+ * Shuffles an array, with option for in-place modification.
35
+ * @param {T[]} arr The array to shuffle.
36
+ * @param {boolean} [inPlace=false] Whether to modify the original array or return a new one. Default is false.
37
+ * @returns {T[]} The shuffled array. If `inPlace` is false, returns a new shuffled array. Otherwise, modifies the original array.
32
38
  */
33
39
  export const shuffle: <T>(arr: T[], inPlace?: boolean) => T[];
34
40
 
35
41
  /**
36
- * Randomly picks characters from multiple character lists
37
- * @param charLength Length of the resulting character array
38
- * @param lists Array of character arrays
42
+ * Randomly picks characters from multiple character lists and returns a shuffled array of characters.
43
+ * @param {number} [charLength=25] The number of characters to generate.
44
+ * @param {string[][]} lists An array of arrays containing character lists (e.g., letters, symbols, numbers).
45
+ * @returns {string[]} A shuffled array of randomly picked characters from the provided lists.
39
46
  */
40
47
  export function shuffleMax(
41
48
  charLength?: number,
42
- lists?: string[][]
49
+ lists?: string[][]
43
50
  ): string[];
44
51
 
45
52
  /**
46
- * Generate a password using default character lists
47
- * @param charLength Length of the password
53
+ * Generates a password by randomly selecting characters from predefined lists (lowercase, uppercase, symbols, numbers),
54
+ * then shuffling them to create a secure, random password.
55
+ * @param {number} [charLength=25] The length of the password to generate. Default is 25 characters.
56
+ * @returns {string} The generated random password.
48
57
  */
49
58
  export function genPassword(
50
59
  charLength?: number
51
60
  ): string;
52
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tushardev01/farm-password",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "type": "module",
5
5
  "main": "./app.js",
6
6
  "exports": {
package/utility.js CHANGED
@@ -1,60 +1,90 @@
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;
1
+ /**
2
+ * Generates an array of lowercase alphabetic characters ('a' to 'z').
3
+ * @returns {string[]} An array containing all lowercase letters.
4
+ */
5
+ export const genLowerLetters = () => {
6
+ return Array.from({ length: 26 }, (_, i) => String.fromCharCode(i + 97));
7
+ };
8
+
9
+ /**
10
+ * Generates an array of uppercase alphabetic characters ('A' to 'Z').
11
+ * @returns {string[]} An array containing all uppercase letters.
12
+ */
13
+ export const genUpperLetters = () => {
14
+ return Array.from({ length: 26 }, (_, i) => String.fromCharCode(i + 65));
15
+ };
16
+
17
+ /**
18
+ * Generates an array of common symbol characters (from ASCII code 33 to 46).
19
+ * @returns {string[]} An array containing common symbols like '!', '"', '#', etc.
20
+ */
21
+ export const genSymbols = () => {
22
+ return Array.from({ length: 14 }, (_, i) => String.fromCharCode(i + 33));
23
+ };
24
+
25
+ /**
26
+ * Generates an array of numeric characters ('0' to '9').
27
+ * @returns {number[]} An array containing all digits from 0 to 9.
28
+ */
29
+ export const genNumbers = () => {
30
+ return Array(10).fill(10).map((_, i) => i);
31
+ };
32
+
33
+ /**
34
+ * Generates a random number between two given values, inclusive.
35
+ * @param {number} x The lower bound.
36
+ * @param {number} y The upper bound.
37
+ * @returns {number} A random number between x and y, inclusive.
38
+ */
39
+ export const randomNumIn = (x, y) => {
40
+ return x + Math.round(Math.random() * (y - x));
41
+ };
42
+
43
+ /**
44
+ * Shuffles an array in place or returns a new shuffled array.
45
+ * @param {Array} arr The array to shuffle.
46
+ * @param {boolean} [inPlace=false] Whether to modify the original array or return a new one. Default is false.
47
+ * @returns {Array} The shuffled array. If `inPlace` is false, returns a new shuffled array. Otherwise, modifies the original array.
48
+ */
49
+ export const shuffle = (arr, inPlace = false) => {
50
+ const arrLength = arr.length;
51
+ if (!inPlace) {
52
+ const protoArr = [...arr];
53
+ arr = protoArr;
31
54
  }
32
- for(let i=arrLength-1;i>=0;i--){
33
- const j=randomNumIn(0,i);
34
- [arr[i],arr[j]]=[arr[j],arr[i]];
55
+ for (let i = arrLength - 1; i >= 0; i--) {
56
+ const j = randomNumIn(0, i);
57
+ [arr[i], arr[j]] = [arr[j], arr[i]];
35
58
  }
36
- if(!inPlace){
59
+ if (!inPlace) {
37
60
  return arr;
38
61
  }
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
- }
62
+ };
63
+
64
+ /**
65
+ * Selects random characters from multiple lists and returns a shuffled array of characters.
66
+ * @param {number} [charLength=25] The number of characters to generate.
67
+ * @param {string[][]} lists An array of arrays containing character lists (e.g., letters, symbols, numbers).
68
+ * @returns {string[]} A shuffled array of randomly picked characters from the provided lists.
69
+ */
70
+ export const shuffleMax = (charLength = 25, lists) => {
71
+ const arr = [];
72
+ for (let i = 0; i < charLength; i++) {
73
+ const randomListNumber = Math.floor(Math.random() * lists.length);
74
+ const randomLst = lists[randomListNumber];
75
+ const randomNumber = Math.floor(Math.random() * randomLst.length);
76
+ arr.push(randomLst[randomNumber]);
77
+ }
78
+ return arr;
79
+ };
80
+
81
+ /**
82
+ * Generates a password by randomly selecting characters from predefined lists (lowercase, uppercase, symbols, numbers),
83
+ * then shuffling them to create a secure, random password.
84
+ * @param {number} [charLength=25] The length of the password to generate. Default is 25 characters.
85
+ * @returns {string} The generated random password.
86
+ */
87
+ export const genPassword = (charLength = 25) => {
88
+ const password = shuffle(shuffleMax(charLength, passLists)).join('');
89
+ return password;
90
+ };