NewSortable IDs are here
prefID
Menu

Installation

Add prefID to any JavaScript or TypeScript project. It has zero runtime dependencies.

Install

Install with your package manager of choice:

bash
npm install prefid
bash
pnpm add prefid
bash
yarn add prefid
bash
bun add prefid

Importing

prefID ships both ES Modules and CommonJS, so either import style works out of the box.

ES Modules / TypeScript

ts
import { id } from "prefid";

id("user");

CommonJS

js
const { id } = require("prefid");

id("user");

JavaScript or TypeScript

prefID works in plain JavaScript exactly as well as in TypeScript. The published package is already compiled JavaScript, so there is nothing to compile on your end — every function (id, createId, template, ensureUnique, isId, getPrefix) runs the same in a .js file.

TypeScript users get one bonus on top: the typed prefix (`user_${string}`) catches wrong-ID mistakes at compile time. JavaScript users still get editor autocomplete from the bundled type definitions — they just don't get compile-time checking, because JavaScript has no compile step.

Requirements

  • Node.js 14.18+, or any modern browser, Deno, Bun, or edge runtime.
  • TypeScript is optional — the package works in plain JavaScript too — but you get the most value from the typed prefixes.

Ready to generate an ID? Continue to the Quick Start.