random-token
Random token generation of given size
Last updated 6 years ago by ashnur .
BSD-2-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install random-token 
SYNC missed versions from official npm registry.

random-token

generate a (pseudo-)random string of given length composed from alphanumeric characters

install

npm install random-token

usage

initiate

var randomToken = require('random-token');

default salt is "abcdefghijklmnopqrstuvwxzy0123456789"

var token = randomToken(16); // example output → 'xg8250nbg4klq5b3'

different salt

var randomToken = require('random-token').create('abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
var token = randomToken(16); // example output → '3ZGErMDCwxTOZYFp'

Note: valid salts are strings with length > 0 if an invalid salt is given to .create, the returned generator will use the default salt

convenience methods

.create

create a different generator

var randomToken = require('random-token').create('Aa0');
var rt = randomToken.gen('Aa0');
var token = rt(16); // example output → 'A0aAAaA0AA0Aa0AA'

.salt

you can check a generators salt by calling .salt() on it

var randomToken = require('random-token').gen('abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
randomToken.salt(); // output → 'abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'

Current Tags

  • 0.0.8                                ...           latest (6 years ago)

8 Versions

  • 0.0.8                                ...           6 years ago
  • 0.0.7                                ...           6 years ago
  • 0.0.6                                ...           6 years ago
  • 0.0.5                                ...           6 years ago
  • 0.0.4                                ...           6 years ago
  • 0.0.3                                ...           7 years ago
  • 0.0.2                                ...           7 years ago
  • 0.0.1                                ...           7 years ago

Copyright 2014 - 2016 © taobao.org |