pattern-code-generator
v2.0.5
Published
this is a code-generator tool which creates codes using given pattern
Downloads
18
Readme
Pattern Code Generator
A lightweight, efficient, and flexible utility for generating sequential codes based on customizable patterns. Perfect for creating unique identifiers, serial numbers, access codes, or other structured formats in a reliable and scalable way.
Features
- Pattern-Based Code Generation: Create sequential codes using user-defined alphanumeric or numeric patterns for consistent and predictable outputs.
- Customizable Output: Specify a starting code and generate a precise number of codes tailored to your needs.
- Lightweight & Performant: Designed with minimal dependencies for fast execution and easy integration into any project.
- Flexible Input Options: Supports both alphanumeric (
ALP) and numeric (NUM) code types for diverse use cases.
Installation
Install the pattern-code-generator package via npm to quickly integrate it into your project:
npm install pattern-code-generatorUsage
Import the generateCode function and use it to generate sequential codes based on your specified parameters.
import { generateCode } from 'pattern-code-generator';
const codes = generateCode(type, pattern, limit, previousCode);Parameters
| Parameter | Type | Description |
|-----------------|--------|-----------------------------------------------------------------------------|
| type | String | Code type: 'ALP' for alphanumeric or 'NUM' for numeric. |
| pattern | String | Format of the code (e.g., 'AABBCC' for alphanumeric, '123123' for numeric). |
| limit | Number | Number of codes to generate. |
| previousCode | String | (Optional) Starting code to generate subsequent codes (e.g., 'AABBZZ'). |
Example
Generate five alphanumeric codes following the pattern AABBCC:
const codes = generateCode('ALP', 'AABBCC', 5);
// Output: ['AABBCC', 'AABBCD', 'AABBCE', 'AABBCF', 'AABBCG']Generate three numeric codes starting after 123999:
const codes = generateCode('NUM', '123123', 3, '123999');
// Output: ['124000', '124001', '124002']