mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-04 21:37:11 -04:00
26 lines
672 B
TypeScript
26 lines
672 B
TypeScript
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);
|
|
}
|