docnumbering
v0.0.3
Published
Document Number/ID Generator with ability to auto increment
Readme
Docnumbering
docnumbering is a flexible and customizable identity generation library. It allows you to define a sequence of rules to generate structured IDs dynamically.
Features
- Static values, input-based, datetime, and incrementing ID components.
- Customizable ID structure using predefined rule types.
- Supports different formats such as year-based numbering.
- Memory-based storage for ID tracking.
Installation
npm install docnumberingUsage
import { factory, MemoryStore, Rule, RuleFormat, RuleType } from "docnumbering";
const rules: Rule[] = [
{ type: RuleType.STATIC, value: "IT" },
{ type: RuleType.STATIC, value: "-" },
{ type: RuleType.INPUT },
{ type: RuleType.STATIC, value: "-" },
{ type: RuleType.DATETIME, format: RuleFormat.YEAR_4 },
{ type: RuleType.STATIC, value: "-" },
{ type: RuleType.INCREMENT, format: RuleFormat.BASE_10, fixedLength: 3 },
];
const store = new MemoryStore();
const idgen = factory(rules, store, { now: new Date("2025") });
async function generateId() {
console.log(await idgen.nextId(["LAPTOP"])); // IT-LAPTOP-2025-001
}
generateId();Example Patterns
- IT-LAPTOP-2025-001: A structured ID with category, year, and incrementing number.
- IT-ANDROID-2024-002: Uses dynamic input for category.
- IT-BAG-2023-005: Automatically increments for each new ID.
Demo
Try out the ID generator at: numbering.easytag.id
