@evokegroup/code-generator

1.0.3 • Public • Published

@evokegroup/code-generator

Generates codes

Class: CodeGenerator

constructor(args)

Parameter Type Default Description
batchCode number, string 0 A batch code or length of a randomly generated batch code
batchCodeExclude string[] [] An array of batch codes that the random batch code generator should not allow
chars string CodeGenerator.Charset.Microsoft The set of characters to used to generate codes
length number 8 The character length of the generated codes
format string null A custom code format. Specify batch code characters with 'b'. Specify other code character with 'x'
dups string[] [] Any previously generated codes that should not be duplicated. Codes must match the batchCode, chars, lenth, and format of those to be generated.

Usage

const CodeGenerator = require('@evokegroup/code-generator');
const generator1 = new CodeGenerator();
const generator2 = new CodeGenerator({
  chars: CodeGenerator.EChars.AlphaUpper | CodeGenerator.EChars.Numeric | CodeGenerator.EChars.Unambiguous,
  length: 8
});
const generator3 = new CodeGenerator({
  batchCode: 2,
  batchCodeExclude: ['BC', '9T', 'HX'],
  chars: CodeGenerator.CharacterSets.Microsoft,
  length: 10,
  format: 'bbxxx-xxxxx'
});

Methods

generate(count) ⇒ Array<string>

Parameter Type Default Description
count number 1 The number of codes to generate

Usage

const CodeGenerator = require('@evokegroup/code-generator');
const generator = new CodeGenerator({
  characters: CodeGenerator.EChars.AlphaUpper,
  length: 6,
  format: 'xx-xx-xx'
});
const codes = generator.generate(10);

totalCodes() ⇒ Number

The total number of possible codes given the code length, batch code length, and characters.

Static Properties

Charset

Property Value Description
Microsoft 2346789BCDFGHJKMPQRTVWXY The characters Microsoft uses in it's product codes

EChars

See @evokegroup/string-generator -> StringGenerator.EChars

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @evokegroup/code-generator

    Weekly Downloads

    1

    Version

    1.0.3

    License

    ISC

    Unpacked Size

    7.35 kB

    Total Files

    3

    Last publish

    Collaborators

    • ybevoke
    • jtsuyuki
    • evokejames
    • evoke-cjamodeo