blob: f48a4deb2b57334fd08d76387f4da0ae5d8729b8 (
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
27
28
|
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);
}
|