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

genthaiid

v2.0.3

Published

better thaiid

Readme

genthaiid

Generate, validate, and complete Thai national ID numbers in JavaScript.

The package is ESM-only and exports the generator as the default export.

Installation

npm install genthaiid

Usage

import gen, {
  random,
  verify,
  completeid,
  randomCompleteID,
  getLastDigit,
  getRndInteger,
  thaiIdRegex,
} from "genthaiid";

const id = gen();
console.log(id); // 13-digit Thai ID

console.log(verify(id)); // true
console.log(thaiIdRegex.test(id)); // true

console.log(random(3)); // ["...", "...", "..."]
console.log(randomCompleteID("1100")); // "1100XXXXXXXX"
console.log(getLastDigit("110170020345")); // checksum digit
console.log(getRndInteger(0, 9)); // random integer between 0 and 9

console.log(completeid("11017002034_5"));
// returns every matching ID that fits the placeholder

API

gen()

Returns a random 13-digit Thai ID number as a string.

random(count)

Returns an array of generated Thai ID numbers.

  • If count is a number, it uses parseInt(count).
  • If count is a numeric string, it decrements the string safely and generates that many IDs.
  • If count is invalid, omitted, or not numeric, it returns an array with one generated ID.

Examples:

random(2);     // ["...", "..."]
random("2");  // ["...", "..."]
random(null);  // ["..."]

randomCompleteID(startDigits)

Generates a random 13-digit Thai ID that starts with the provided digits.

  • startDigits must be between 4 and 12 digits.
  • The first digit must be between 1 and 8 (Thai ID rule).
  • Remaining digits are randomly generated.
  • Returns a valid 13-digit Thai ID string that always passes verify().
  • Returns undefined if the input is invalid (fewer than 4 digits, first digit is 0 or 9, or contains non-digits).

Examples:

randomCompleteID("1100");      // "1100XXXXXXXX7" (random fill)
randomCompleteID("1234567");   // "1234567XXXXX2" (random fill)
randomCompleteID("110");       // undefined (too few digits)
randomCompleteID("9100");      // undefined (first digit must be 1-8)

verify(id, checkfirstdigit = true, checklastdigit = true)

Checks whether a value is a valid Thai ID.

  • Requires exactly 13 digits.
  • By default, validates both the first digit rule and the checksum digit.
  • checkfirstdigit enforces the first digit to be between 1 and 8.
  • checklastdigit enforces the calculated checksum.

completeid(idWithPlaceholders, checkfirstdigit = true, checklastdigit = true)

Completes a partial 13-digit Thai ID using _ as a placeholder and returns every valid match.

Examples:

completeid("11017002034_5");
completeid("1____________");

Returns:

  • string[] when multiple candidates are checked and valid matches are found
  • string when the original input is already valid
  • undefined when the input is not a 13-digit pattern

getLastDigit(firstTwelveDigits)

Calculates the checksum digit from the first 12 digits of a Thai ID.

getRndInteger(min, max)

Returns a random integer between min and max, inclusive.

thaiIdRegex

Regular expression for the first-digit rule:

/^[1-8]\d{12}$/

TypeScript

The package ships with declarations in index.d.ts.

License

MIT