Sequential Generator

Sequential Generator

Sequential Generator Banner

๐Ÿ›  What is Sequential Generator? (EN)

In small applications, we often need a way to generate document IDs like invoices (INV) or order numbers with a clear date and sequence. Sequential Generator is designed to:

How to Use

sequential-generator is an open-source Node.js module that generates customizable document codes with date prefixes.

เธ•เธฑเธงเธญเธขเนˆเธฒเธ‡:

SEX2505140001 โ†’ Generated on May 14, 2025 with prefix "SEX" and sequence "0001"

๐Ÿ”‘ Features

import SequentialGenerator  from 'sequential-generator';

// Create a generator with prefix, timezone, default date format and sequence length
const generator = new SequentialGenerator('SEX', 'Asia/Bangkok');

// Generate a new code
const newCode = generator.generate();
console.log(newCode);  // Example output: SEX2305110001

// Validate a code
const isValid = generator.validate('SEX2305110001');
console.log(isValid);  // true or false

// Increment an existing code
const incrementedCode = generator.increment('SEX2305110001');
console.log(incrementedCode);  // Example output: SEX2305110002

Max Limit

const maxCode = 'SEX2305119999';  // Maximum for 4-digit sequence
try {
  console.log(generator.increment(maxCode));
} catch (error) {
  console.error(error.message);  // Output: "Maximum number reached. Cannot increment."
}