mirror of
https://github.com/CorentinTh/it-tools.git
synced 2026-01-03 00:38:11 +00:00
25 lines
647 B
TypeScript
25 lines
647 B
TypeScript
import { shuffleString } from '@/utils/random';
|
|
|
|
export function createToken({
|
|
withUppercase = true,
|
|
withLowercase = true,
|
|
withNumbers = true,
|
|
withSymbols = false,
|
|
length = 64,
|
|
}: {
|
|
withUppercase?: boolean;
|
|
withLowercase?: boolean;
|
|
withNumbers?: boolean;
|
|
withSymbols?: boolean;
|
|
length?: number;
|
|
}) {
|
|
const alphabet = [
|
|
...(withUppercase ? 'ABCDEFGHIJKLMOPQRSTUVWXYZ' : ''),
|
|
...(withLowercase ? 'abcdefghijklmopqrstuvwxyz' : ''),
|
|
...(withNumbers ? '0123456789' : ''),
|
|
...(withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : ''),
|
|
].join('');
|
|
|
|
return shuffleString(alphabet.repeat(length)).substring(0, length);
|
|
}
|