@sanity/uuid
A one-line wrapper that generates version-4 UUIDs formatted as valid Sanity document IDs.
Repository Health
Technical Analysis
@sanity/uuid is a minimal utility package published by Sanity.io that generates version-4 UUIDs suitable for use as Sanity document IDs. Internally it does nothing more than re-export the v4 generator from the popular uuid npm package under a shorter, semantically named uuid() function, so teams working inside the Sanity ecosystem don’t need to add their own dependency or remember which UUID version Sanity’s document IDs expect.
The package is explicitly marked as legacy in its own README: modern JavaScript runtimes ship crypto.randomUUID() natively, and Sanity’s maintainers now recommend using that or the uuid package directly instead of pulling in this wrapper. It remains published and functional for existing Sanity projects that already depend on it, but new code is discouraged from adopting it.
What You Get
- A single uuid() function that returns a version-4 UUID string formatted for use as a Sanity document ID
- Dual-format builds (CommonJS and ES modules) so it works with both require() and import syntax
- Full TypeScript type definitions generated from a strict tsconfig
- Zero configuration - no options, flags, or setup required to call it
Common Use Cases
- Generating a client-side document ID before creating a new document via the Sanity API
- Assigning IDs to draft documents in custom Sanity Studio input components
- Producing predictable, valid IDs in scripts that seed or migrate Sanity datasets
- Testing code paths that need a valid-looking Sanity document ID without hitting the API
Under The Hood
Architecture The entire implementation lives in a single file, src/uuid.ts, which re-exports the v4 function from the uuid package under the name uuid - there is no internal layering, no additional modules, and no abstraction to speak of. The package’s only job is to standardize on version-4 UUIDs formatted as valid Sanity document IDs; consumers import {uuid} from ‘@sanity/uuid’ and get back a string, with all actual generation logic delegated entirely to the external uuid dependency. If the underlying ID format ever changed, the only thing to update would be the pinned version of uuid in package.json.
Tech Stack Written in strict TypeScript (noImplicitAny, strictNullChecks, and related strict flags all enabled) and compiled to dual output formats - a CommonJS build via tsc —module commonjs and an ES modules build via tsc —module es6 - so consumers can import it either way. The sole runtime dependency is uuid ^11.0.0; build tooling is limited to typescript, rimraf for cleaning the lib directory, and prettier for formatting. There is no bundler, framework, database, or network dependency - this is a pure, dependency-thin utility package published straight to npm.
Code Quality Testing consists of a single hand-written script (test/uuid.test.js) that generates two UUIDs, checks each against a regex for the standard UUID v4 shape, and throws if two consecutive calls collide - there is no test framework such as Jest or Mocha, no assertion library, and no CI workflow configured in the repository (no .github/workflows directory present). TypeScript’s strict mode substitutes for some of the safety a broader test suite would otherwise provide. Given the size and stability of the codebase this minimal approach is proportionate, but it does mean there is no automated gate on pull requests.
API Design The public surface is a single named export, uuid(), with no configuration options and no way to request a different UUID version - by design it exists only to save Sanity users an import and a rename. The package’s own README already advises against using it, pointing developers to crypto.randomUUID() or the uuid package directly, which makes clear it never attempted anything beyond that one convenience. There is no novel technical contribution here; it is a thin, explicitly deprecated convenience wrapper.