Formulaic Docs

ID Generator Setup

The ID generator will need to be configured with the different ID formats you plan to generate.

We recommend creating a project-wide configuration file, id.ts.

src/id.ts
// import { IDConfig } from "@formulaic/id";
// export const IDs: IDConfig = { (1)

export const IDs = {

  article: "uuid", (2)

  draft: ["alphanumeric", 12], (3)

  user: ["safe", "millions"], (4)

} as const;

export type ID = typeof IDs;
1 During development, adding a type-hint : IDConfig will enable auto-complete of ID formats. However, you should remove the hint when you use the library.
2 Articles will be assigned IDs using UUIDv4.
3 Drafts will be given NanoIDs using 12 alphanumeric characters.
4 Users will be given lookalike safe and SFW IDs, using the "millions" shortcut to ensure we can create millions of users before reaching a 1% chance of collision.