mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-24 08:46:15 -04: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);
|
||
|
}
|