New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

token-gen

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

token-gen

Generate unique human readable codes (e.g. vouchers, referrals, passwords, keys)

latest
Source
npmnpm
Version
0.5.0
Version published
Weekly downloads
5
400%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

TokenGen

TokenGen is a small library that will allow you to generate human readable codes for your voucher codes, keys, etc.

Installation

NPM

npm install token-gen

Meteor < 1.3 (legacy)

Just add the package from atmosphere:

meteor add hirespace:token-gen

Usage

The most common usage would be:

import TokenGen from 'token-gen'; // var TokenGen = require('token-gen');

var code = TokenGen();

console.log(code.toString()); // "48CML"

Options

The generated code can be customised passing an options object to the constructor:

var code = TokenGen({
    tokenLength: 3, // Default: 5
    alphabet: 'ABC' // Default: '0123456789ACDEFGHJKLMNPQRTUVWXYZ'
});

console.log(code.toString()); // "BBA"

Full list of options

tokenLength

It's the generated code character length.

  • default: 5

Note: The amount of different codes you could generate is alphabetLength ^ codeLength. Therefore, with the default alphabet, the maximum amount of different codes with a 5 characters code is 33554432. We found 33 million codes is more than enough for most usages. If you need more, the code length can be customised.

As this is the most common option, it is possible to call the generator directly with a number, which represents the tokenLength:

var code = TokenGen(3);

console.log(code.toString()); // "20A"

alphabet

The character included in this string will be the only characters used to generate the code. The generated codes are any combination of these characters.

  • default: 0123456789ACDEFGHJKLMNPQRTUVWXYZ

We use a default alphabet composed of 32 characters that are not confusing to read (e.g. we removed B because it could be confused with an 8).

License

Made with :heart: by Hire Space (hirespace.com) and distributed using a ISC license.

FAQs

Package last updated on 18 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts