This repository has been archived by the owner on Jul 24, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update for running generate with config file
- Loading branch information
1 parent
c954961
commit 42b7ff3
Showing
9 changed files
with
93 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as crypto from 'crypto'; | ||
|
||
export function randomStringHex(length: number): string { | ||
return crypto | ||
.randomBytes(Math.ceil(length / 2)) | ||
.toString('hex') // convert to hexadecimal format | ||
.slice(0, length); // return required number of characters | ||
} | ||
|
||
export function randomStringBase64(length: number): string { | ||
return crypto | ||
.randomBytes(Math.ceil((length * 3) / 4)) | ||
.toString('base64') // convert to base64 format | ||
.slice(0, length) // return required number of characters | ||
.replace(/\+/g, '0') // replace '+' with '0' | ||
.replace(/\//g, '0'); // replace '/' with '0' | ||
} | ||
|
||
export function randomString(length: number, chars?: string): string { | ||
chars = chars || 'abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789'; | ||
|
||
const rnd = crypto.randomBytes(length); | ||
const value = new Array(length); | ||
const d = 256 / Math.min(256, chars.length); | ||
|
||
for (var i = 0; i < length; i++) { | ||
value[i] = chars[Math.floor(rnd[i] / d)]; | ||
} | ||
|
||
return value.join(''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters