Type-safe, prefixed IDs
Short, unique IDs that carry a prefix telling you what they belong to — user_a1b2c3, order_9f8e7d. Readable, secure, and typed — for TypeScript and JavaScript alike.
npm install prefidimport { id } from "prefid";
id("user"); // => "user_a8Kd0f2bQ1nR7pZ3xW4mT6y"
id("order"); // => "order_9f8e7d6c5b4a3F2e1D0cB9aX"const { id } = require("prefid");
id("user"); // => "user_a8Kd0f2bQ1nR7pZ3xW4mT6y"
id("order"); // => "order_9f8e7d6c5b4a3F2e1D0cB9aX"Self-describing
The prefix tells you what an ID is at a glance — in logs, URLs, and your database.
Type-safe
id("user") is typed as `user_${string}`, so mixing up ID types is a compile error.
Sortable option
sortableId() embeds a time component so IDs sort chronologically — ULID / UUIDv7-style.
Secure
The random part uses the platform's cryptographic RNG — never Math.random().
Zero dependencies
Tiny and focused on one job. Nothing to audit, nothing to bloat your bundle.
Universal
Runs in Node, browsers, Deno, Bun, and edge runtimes. Ships ESM + CommonJS.
Guaranteed-unique helper
ensureUnique() retries against your own store until it finds a free ID.
Ready to give your IDs a name?
Install prefID and generate your first type-safe, prefixed ID in under a minute.