mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-01-20 11:51:22 +00:00
14 lines
487 B
TypeScript
14 lines
487 B
TypeScript
import CONFIG from '@config/config'
|
|
|
|
export default function generateInviteCode() {
|
|
// 6 random numbers in [ 0, 35 ] are 36 possible numbers (10 [0-9] + 26 [A-Z])
|
|
return Array.from(
|
|
{ length: CONFIG.INVITE_CODE_LENGTH },
|
|
(n: number = Math.floor(Math.random() * 36)) => {
|
|
// n > 9: it is a letter (ASCII 65 is A) -> 10 + 55 = 65
|
|
// else: it is a number (ASCII 48 is 0) -> 0 + 48 = 48
|
|
return String.fromCharCode(n > 9 ? n + 55 : n + 48)
|
|
},
|
|
).join('')
|
|
}
|