NewSortable IDs are here
prefID
Menu

Introduction

prefID generates short, unique IDs that carry a prefix telling you what they belong to.

Instead of an opaque identifier like 9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d, prefID gives you user_a1b2c3 — an ID whose prefix tells you exactly what it belongs to. That prefix makes IDs readable in logs, URLs, and your database, and because prefID is written in TypeScript, the prefix is understood by the type system too.

import { id } from "prefid";

id("user");   // => "user_a8Kd0f2bQ1nR7pZ3xW4mT6y"
id("order");  // => "order_9f8e7d6c5b4a3F2e1D0cB9aX"
const { id } = require("prefid");

id("user");   // => "user_a8Kd0f2bQ1nR7pZ3xW4mT6y"
id("order");  // => "order_9f8e7d6c5b4a3F2e1D0cB9aX"

Why prefixed IDs?

  • Readable — you instantly know order_9f8e7d is an order and user_a1b2c3 is a user, without looking anything up.
  • Safer — TypeScript treats a user ID and an order ID as different types, so you can't accidentally pass one where the other is expected.
  • Debuggable — a stray ID in a log line explains itself.

Design goals

  • Secure by default — the random part uses the platform's cryptographic RNG, never Math.random().
  • Zero dependencies — one small, focused package.
  • Universal — Node, browsers, Deno, Bun, and edge runtimes, shipping both ESM and CommonJS.
  • Fully typed — the generated ID keeps its prefix in the type.

Next steps

Head to Installation to add prefID to your project, then the Quick Start to generate your first ID.