npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sequential-generator

v1.1.0

Published

A simple generator for creating sequential codes with prefix and date

Readme

Sequential Generator 🚀

A simple, timezone-aware sequential code generator with a date-based prefix. Designed for generating readable, traceable, and unique reference codes.

Perfect for invoices, orders, tickets, documents, or any system that requires human-readable sequential identifiers.


✨ Features

  • Sequential Code Generation Generates codes in the format {prefix}{date}{sequence} Example: INV202305110001

  • Timezone-Aware Correctly calculates dates based on a specified timezone (e.g. Asia/Bangkok, America/New_York)

  • Custom Date Format Supports custom date formats (default: YYYYMMDD)

  • Configurable Sequence Length Control the number of digits in the sequence (default: 4 digits → 0001)

  • Automatic Sequence Expansion Automatically increases sequence length when the limit is reached (999900001)

  • Custom Separator Optional separator between segments Example: INV-20230101-0001


🎯 Use Cases

| Use Case | Example Output | | --- | --- | | Invoice Number | INV-20250101-0001 | | Purchase Order | PO-20250101-0001 | | Transfer Number | TRF-20250101-0001 | | Inbound Receipt | IB-20250101-0001 | | Support Ticket | TKT-20250101-0001 | | Delivery Order | DO-20250101-0001 | | Quotation | QT-20250101-0001 | | Credit Note | CN-20250101-0001 | | Payment Receipt | REC-20250101-0001 | | Work Order | WO-20250101-0001 | | Booking / Reservation | BK-20250101-0001 |


📦 Installation

npm install sequential-generator

🛠 Usage

import { SequentialGenerator } from 'sequential-generator';

const generator = new SequentialGenerator({
  prefix: 'INV',
  timeZone: 'Asia/Bangkok',
  separator: '-',
});

// Generate a new code
const code = generator.generate();
console.log(code);
// INV-20230511-0001

// Parse a code
console.log(generator.parse('INV-20230511-0001'));
// { prefix: 'INV', date: '20230511', sequence: 1 }

// Reset the generator sequence
generator.reset();

// Validate an existing code
console.log(generator.validate('INV-20230511-0001'));
// true

// Increment a code (stateless / DB-friendly)
console.log(generator.increment('INV-20230511-0001'));
// INV-20230511-0002

⚙️ Custom Configuration

const generator = new SequentialGenerator({
  prefix: 'INV',
  timeZone: 'Asia/Bangkok',
  dateFormat: 'YYYYMMDD',
  sequentialLength: 6, // → INV20250101000001
});

Adjusting Sequence Length

The sequentialLength option controls how many digits the sequence number has (default: 4).

// Default (4 digits)
new SequentialGenerator({ prefix: 'INV', timeZone: 'Asia/Bangkok' });
// → INV202501010001

// 3 digits
new SequentialGenerator({ prefix: 'INV', timeZone: 'Asia/Bangkok', sequentialLength: 3 });
// → INV20250101001

// 6 digits
new SequentialGenerator({ prefix: 'INV', timeZone: 'Asia/Bangkok', sequentialLength: 6 });
// → INV20250101000001

The sequence will automatically expand beyond the configured length when the limit is reached (e.g. 999900001 when sequentialLength is 4).


📚 API Reference

class SequentialGenerator

Constructor

new SequentialGenerator(options: {
  prefix: string;
  timeZone: string;
  dateFormat?: string;        // default: YYYYMMDD
  sequentialLength?: number; // default: 4
  separator?: string;
});

Methods

| Method | Description | | ----------------------- | --------------------------------------------------------- | | generate() | Generates a new sequential code based on the current date | | validate(code) | Validates whether a code matches the expected format | | parse(code) | Decomposes a code into its components (prefix, date, seq) | | increment(code) | Returns the next sequential code (stateless) | | reset() | Resets internal sequence and date state | | extractDate(code) | Extracts the date portion from a code | | extractSequence(code) | Extracts the numeric sequence from a code |


📅 Date Format & 🌐 Timezone

This library uses Day.js ^1.11.19 for date and timezone handling.

Date Format

All Day.js format tokens are supported. The default is YYYYMMDD.

| Format | Output | Resets every | | --- | --- | --- | | YYYYMMDD | 20250101 | Day | | YYYYMM | 202501 | Month | | YY | 25 | Year |

Timezone

The timeZone option accepts IANA timezone names via the Day.js timezone plugin. The default is UTC.

| Region | timeZone value | | --- | --- | | UTC (default) | UTC | | Thailand | Asia/Bangkok | | Japan | Asia/Tokyo | | London | Europe/London | | New York | America/New_York | | Los Angeles | America/Los_Angeles |

For the full list, see the IANA timezone database.


🏗 Dual Package Support

This library is published as a Dual Package, supporting both:

  • CommonJS (require)
  • ES Modules (import)

It is compatible with modern build tools like Vite, Webpack, and Next.js, as well as classic Node.js environments.


📝 License

MIT License Copyright (c) 2024 Pratchaya Ueapisitkul