npm install @immutabl3/random-token
Generates a base64, url-safe token. Uses -
, _
, 0-9
, a-z
, and A-Z
.
const randomToken = require('@immutabl3/random-token');
const token = randomToken(); // '0XjaS_7F'
Generates a token. Defaults to a length of 8.
[n=8]
(number): the length of the token
(string): Returns the token
Validates a token string. Pass optional length
to validate the length of the token as well.
[token]
(string): the token to validate
[n]
(number): the length of the token
(boolean): Returns true
is the token is valid
The string of characters used to generate then token. Use as a reference only. Changing this string will not change token generation.
To run tests, download the repo and run:
npm install
npm test
MIT