Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including fast-key-generator with all npm packages installed. Try it out:

var fastKeyGenerator = require("fast-key-generator")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

fast-key-generator v1.0.1

Simple utils library for key generation.

fast-key-generator

Simple utils library for API calls.

npm version npm downloads npm license


Instalation

To install fast-key-generator - you can use npm or yarn package manager.
npm install fast-key-generator --save
yarn add fast-key-generator

Documentation

The fast-key-generator library includes only one function generateKey. Below you can find the documentation for this function.


The generateKey function

The simple method for key generation.
The generateKey function takes only one parameter, which is an object.
The options parameter may includes the following fields:
NameTypeDefault valueDescription
sizenumber16Key size (without prefix).
prefixstring""Key prefix.
chartypestring"alpha"Can be one of "alpha", "numeric", "alphanum", "symbols".
chartsetstring""If you provide charset, then the generator will use the characters from this charset & ignore the chartype.
transformstring or function"none"Can be one of "none", "lower", "upper" or custom function that takes a key as the first argument & should return formatted key.
validatefunctionempty functionIf the function returns true, the generation process will be completed. If false, the generation process will start again until the function returns true.
excludearray of strings[]An array of strings that should not be keys.

Examples

import { generateKey } from 'fast-key-generator';

const key = generateKey();
// The key will be a string with a length of 16


import { generateKey } from 'fast-key-generator';

const key = generateKey({
  size: 1,
  prefix: 'key_',
  chartype: 'numeric',
  exclude: [
    'key_0',
    'key_1',
    'key_2',
    'key_3',
    'key_4',
    'key_5',
    'key_6',
    'key_7',
    'key_8',
  ]
});

// The key will be "key_9"


import { generateKey } from 'fast-key-generator';

const key = generateKey({
  size: 1,
  prefix: 'key_',
  chartype: 'numeric',
  validate: (key) => key.includes('2')
});

// The key will be "key_2"
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free