@evokegroup/code-generator
v1.0.3
Published
Generates codes
Downloads
10
Keywords
Readme
@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 |