mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-24 08:46:15 -04:00
feat(tool): added token generator
This commit is contained in:
parent
25a8659786
commit
40dec52c84
5 changed files with 189 additions and 46 deletions
24
src/tools/token-generator/token-generator.service.ts
Normal file
24
src/tools/token-generator/token-generator.service.ts
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue