Skip to content

Commit

Permalink
generateRandomString
Browse files Browse the repository at this point in the history
  • Loading branch information
Anushkabh committed Feb 19, 2024
1 parent fe85fac commit ba7ced1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ This function remove the number from string.
validator.addFullstop(str)
This function replaces space in string with fullstop.
```
```
validator.generateRandomString(length)
This function generates the random string of given length.
```


# Contributing Guidelines
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
removeUnderscore,
addFullstop,
removeNumber,
generateRandomString

} from "./utils/utilityFunctions";

Expand Down Expand Up @@ -92,6 +93,7 @@ const validator = {
decodeJWT,
addFullstop,
removeNumber,
generateRandomString
};

export default validator;
10 changes: 10 additions & 0 deletions src/utils/utilityFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,16 @@ export const removeNumber = (str: string): string => {
export const addFullstop = (str: string): string => {
return str.replace(/\s/g, '.');
};
export const generateRandomString = (length: number): string => {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+';
let result = '';
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
};




0 comments on commit ba7ced1

Please sign in to comment.