chore: Move API source code to API folder.
This commit is contained in:
parent
8015b0af74
commit
d3a664fea4
59 changed files with 43 additions and 38 deletions
26
api/src/libs/generateToken.ts
Normal file
26
api/src/libs/generateToken.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
function getRandomInt(min: number, max: number): number {
|
||||
const minCeiled = Math.ceil(min);
|
||||
const maxFloored = Math.floor(max);
|
||||
return Math.floor(Math.random() * (maxFloored - minCeiled) + minCeiled); // The maximum is exclusive and the minimum is inclusive
|
||||
}
|
||||
|
||||
export function generateRandomData(length: number): string {
|
||||
let newString = "";
|
||||
|
||||
for (let i = 0; i < length; i += 2) {
|
||||
const randomNumber = getRandomInt(0, 255);
|
||||
|
||||
if (randomNumber == 0) {
|
||||
i -= 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
newString += randomNumber.toString(16);
|
||||
}
|
||||
|
||||
return newString;
|
||||
}
|
||||
|
||||
export function generateToken() {
|
||||
return generateRandomData(128);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue