@sapphire/snowflake
Discord-style Snowflake ID generator with deconstruction, epoch configuration, and thread-safe increment.
Official Documentation ↗v3.5. Check the official docs for the latest API surface.Installation
npm install @sapphire/snowflakeMethods
No methods match this filter.
@sapphire/snowflake is discord-style snowflake id generator with deconstruction, epoch configuration, and thread-safe increment. This page documents the core methods, installation, and common usage patterns for the current stable release.
Installation
Install @sapphire/snowflake with your preferred package manager using the command shown in the frontmatter. The package is published to the npm registry and ships with TypeScript types where applicable.
Core methods
The methods listed in the frontmatter cover the primary API surface. Each signature reflects the v3.5 release. Consult the official documentation linked in sourceUrl for advanced options, edge cases, and breaking changes between major versions.
Frequently asked questions
The faq section in the frontmatter answers the most common questions about @sapphire/snowflake, including comparisons with alternatives, configuration tips, and runtime requirements. If your question is not covered, check the source URL for the full guide.
Errors
The official API reference declares the following error types:
TypeError(throw new TypeError(…)) — official text: “throw new TypeError("timestamp" argument must be a number, bigint, or Date (received ${typeof timestamp}));” (source: https://raw.githubusercontent.com/sapphiredev/utilities/main/packages/snowflake/src/lib/Snowflake.ts, fetched 2026-11-08T09:53:13.312Z)
API reference evidence
Fetched from official sources on 2026-11-08T09:53:13.312Z via WebFetch https://unpkg.com/@sapphire/[email protected]/dist/esm/index.d.mts.
Snowflake.generate→ signature from https://unpkg.com/@sapphire/[email protected]/dist/esm/index.d.mts; official text: “generate({ increment, timestamp, workerId, processId }?: SnowflakeGenerateOptions): bigint;”Snowflake.deconstruct→ signature from https://unpkg.com/@sapphire/[email protected]/dist/esm/index.d.mts; official text: “deconstruct(id: string | bigint): DeconstructedSnowflake;”
FAQ
- What is a Snowflake?
- A 64-bit ID encoding timestamp, worker ID, and process ID; used by Discord and Twitter for sortable unique IDs.
- Are IDs sortable?
- Yes. Snowflakes are monotonically increasing within a worker, so they sort chronologically.
- Can I use a custom epoch?
- Yes. Set EPOCH before generating; use 1420070400000 for Discord or your own base.
Report a problem with this API docOpens a pre-filled issue on GitHub.