blob: f928a4156deb9f175b734bb53dc8567397cca074 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import { shuffleString } from '@/utils/random';
export function createToken({
withUppercase = true,
withLowercase = true,
withNumbers = true,
withSymbols = false,
length = 64,
alphabet,
}: {
withUppercase?: boolean
withLowercase?: boolean
withNumbers?: boolean
withSymbols?: boolean
length?: number
alphabet?: string
}) {
const allAlphabet = alphabet ?? [
withUppercase ? 'ABCDEFGHIJKLMOPQRSTUVWXYZ' : '',
withLowercase ? 'abcdefghijklmopqrstuvwxyz' : '',
withNumbers ? '0123456789' : '',
withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : '',
].join('');
return shuffleString(allAlphabet.repeat(length)).substring(0, length);
}
|