mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-23 08:16:16 -04:00
refactor: token generator can use a custom alphabet
This commit is contained in:
parent
737319edf1
commit
83da6b7ee9
1 changed files with 11 additions and 7 deletions
|
@ -6,19 +6,23 @@ export function createToken({
|
||||||
withNumbers = true,
|
withNumbers = true,
|
||||||
withSymbols = false,
|
withSymbols = false,
|
||||||
length = 64,
|
length = 64,
|
||||||
|
alphabet,
|
||||||
}: {
|
}: {
|
||||||
withUppercase?: boolean;
|
withUppercase?: boolean;
|
||||||
withLowercase?: boolean;
|
withLowercase?: boolean;
|
||||||
withNumbers?: boolean;
|
withNumbers?: boolean;
|
||||||
withSymbols?: boolean;
|
withSymbols?: boolean;
|
||||||
length?: number;
|
length?: number;
|
||||||
|
alphabet?: string;
|
||||||
}) {
|
}) {
|
||||||
const alphabet = [
|
const allAlphabet =
|
||||||
...(withUppercase ? 'ABCDEFGHIJKLMOPQRSTUVWXYZ' : ''),
|
alphabet ??
|
||||||
...(withLowercase ? 'abcdefghijklmopqrstuvwxyz' : ''),
|
[
|
||||||
...(withNumbers ? '0123456789' : ''),
|
...(withUppercase ? 'ABCDEFGHIJKLMOPQRSTUVWXYZ' : ''),
|
||||||
...(withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : ''),
|
...(withLowercase ? 'abcdefghijklmopqrstuvwxyz' : ''),
|
||||||
].join('');
|
...(withNumbers ? '0123456789' : ''),
|
||||||
|
...(withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : ''),
|
||||||
|
].join('');
|
||||||
|
|
||||||
return shuffleString(alphabet.repeat(length)).substring(0, length);
|
return shuffleString(allAlphabet.repeat(length)).substring(0, length);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue