refactor: token generator can use a custom alphabet
This commit is contained in:
		
							parent
							
								
									a77a82f5a2
								
							
						
					
					
						commit
						59ec6293b6
					
				| @ -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 = | ||||||
|  |     alphabet ?? | ||||||
|  |     [ | ||||||
|       ...(withUppercase ? 'ABCDEFGHIJKLMOPQRSTUVWXYZ' : ''), |       ...(withUppercase ? 'ABCDEFGHIJKLMOPQRSTUVWXYZ' : ''), | ||||||
|       ...(withLowercase ? 'abcdefghijklmopqrstuvwxyz' : ''), |       ...(withLowercase ? 'abcdefghijklmopqrstuvwxyz' : ''), | ||||||
|       ...(withNumbers ? '0123456789' : ''), |       ...(withNumbers ? '0123456789' : ''), | ||||||
|       ...(withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : ''), |       ...(withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : ''), | ||||||
|     ].join(''); |     ].join(''); | ||||||
| 
 | 
 | ||||||
|   return shuffleString(alphabet.repeat(length)).substring(0, length); |   return shuffleString(allAlphabet.repeat(length)).substring(0, length); | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user