* chore(deps): update dependency typescript to v5 * chore(deps): switched to fucking typescript v5 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Corentin Thomasset <corentin.thomasset74@gmail.com>
27 lines
674 B
TypeScript
27 lines
674 B
TypeScript
import { shuffleString } from '@/utils/random';
|
|
|
|
export function createToken({
|
|
withUppercase = true,
|
|
withLowercase = true,
|
|
withNumbers = true,
|
|
withSymbols = false,
|
|
length = 64,
|
|
alphabet,
|
|
}: {
|
|
withUppercase?: boolean
|
|
withLowercase?: boolean
|
|
withNumbers?: boolean
|
|
withSymbols?: boolean
|
|
length?: number
|
|
alphabet?: string
|
|
}) {
|
|
const allAlphabet = alphabet ?? [
|
|
withUppercase ? 'ABCDEFGHIJKLMOPQRSTUVWXYZ' : '',
|
|
withLowercase ? 'abcdefghijklmopqrstuvwxyz' : '',
|
|
withNumbers ? '0123456789' : '',
|
|
withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : '',
|
|
].join(''); ;
|
|
|
|
return shuffleString(allAlphabet.repeat(length)).substring(0, length);
|
|
}
|