@basementscripts/token-generator
Generate random char string of alpha, numeric, and special characters.
Getting Started
$ yarn add @basementscripts/token-generator
Options
type
- Character type of the token string available options are;
-
Alpha
- alpha upper and lower chars onlyabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
-
AlphaLower
- alpha lower chars onlyabcdefghijklmnopqrstuvwxyz
-
Numeric
- numeric chars only0123456789
-
Special
- special chars only!@#$%^&*()-_=+[{]}<>
-
AlphaNumeric
- alpha and numeric chars only0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
-
AlphaNumericLower
- alpha and numeric chars lowercase only0123456789abcdefghijklmnopqrstuvwxyz
-
Full
- includes all available chars as potential0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()-_=+[{]}<>
length
- The total length of the string desired
leadWithAlpha
- Force string to start with a leading alpha char
Basic Use
The default generated token will be a 32 char alphanumeric token string eg. FjFoaNmxGAZFP4FaMoPG1K2vYuw3bGFG
import { generateToken } from '@basementscripts/token-generator'
...
const token = generateToken()
Generate 6 Digit Token
Generates a 6 digit token string eg. 085293
import { generateToken, Chars } from '@basementscripts/token-generator'
...
const token = generateToken({ type: Chars.Numeric, length: 6 })