8000 chore(docs): add jsdoc to the function · SMAKSS/random-string@3fa2f6d · GitHub
[go: up one dir, main page]

Skip to content

Commit 3fa2f6d

Browse files
committed
chore(docs): add jsdoc to the function
1 parent 2cb738b commit 3fa2f6d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
const DEFAULT_ALLOWED_CHARACTERS =
22
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*';
33

4+
/**
5+
* Generates a random string based on the given length and set of allowed characters.
6+
*
7+
* @param {Object} [options={}] - The options for generating the random string.
8+
* @param {number} [options.length=Math.ceil(Math.random() * 20)] - The length of the string to generate.
9+
* @param {string} [options.allowedCharacters=DEFAULT_ALLOWED_CHARACTERS] - A string of allowed characters.
10+
* @returns {string} The generated random string.
11+
*
12+
* @example
13+
* // Example 1: Generate a random string with default options
14+
* const randomStr = randomString();
15+
* console.log(randomStr); // Output will be a random string of length between 1 and 20 characters.
16+
*
17+
* @example
18+
* // Example 2: Generate a random string of length 10
19+
* const randomStr10 = randomString({ length: 10 });
20+
* console.log(randomStr10); // Output will be a random string of exactly 10 characters.
21+
*
22+
* @example
23+
* // Example 3: Generate a random string of length 5 with specific allowed characters
24+
* const allowedChars = 'abc123';
25+
* const randomStrCustom = randomString({ length: 5, allowedCharacters: allowedChars });
26+
* console.log(randomStrCustom); // Output will be a random string of exactly 5 characters, with characters only from 'abc123'.
27+
*/
428
function randomString({
529
length = Math.ceil(Math.random() * 20),
630
allowedCharacters = DEFAULT_ALLOWED_CHARACTERS

0 commit comments

Comments
 (0)
0