feat(tool): added token generator

This commit is contained in:
Corentin Thomasset 2022-04-04 00:25:29 +02:00
parent 25a8659786
commit 40dec52c84
No known key found for this signature in database
GPG key ID: DBD997E935996158
5 changed files with 189 additions and 46 deletions

View file

@ -0,0 +1,24 @@
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);
}