Skip to content

feat: shared UUID#18

Merged
brunozoric merged 7 commits into
mainfrom
bruno/feat/shared-uuid
Jun 7, 2026
Merged

feat: shared UUID#18
brunozoric merged 7 commits into
mainfrom
bruno/feat/shared-uuid

Conversation

@brunozoric

Copy link
Copy Markdown
Contributor

Summary

  • Add uuid() to @webiny/stdlib — a RFC 4122 v4 UUID generator that works in both Node.js and browser environments
  • Uses native crypto.randomUUID() when available (Node.js, secure browser contexts) and falls back to a manual implementation using crypto.getRandomValues() for insecure (HTTP)
    contexts
  • No external dependencies — built entirely on platform built-ins

Design

The fallback exists because crypto.randomUUID() throws in browsers served over HTTP (requires a secure
context
). crypto.getRandomValues() has no such restriction, so the manual path covers
that gap.

The function lives in src/common/utils/uuid/ (platform-agnostic) and is exported from @webiny/stdlib.

  import { uuid } from "@webiny/stdlib";

  const id = uuid(); // "f47ac10b-58cc-4372-a567-0e02b2c3d479"

Test plan

  • Returns valid UUID v4 format (regex match)
  • Version nibble is 4, variant bits are 8, 9, a, or b
  • 1000 successive calls produce 1000 unique values
  • Lowercase hex, correct hyphen positions
  • Fallback path produces valid UUIDs when crypto.randomUUID is unavailable
  • Fallback path uniqueness (1000 calls)

brunozoric and others added 6 commits June 7, 2026 07:25
Uses crypto.randomUUID() when available (Node.js, secure browser
contexts) and falls back to a manual implementation using
crypto.getRandomValues() for insecure (HTTP) browser contexts.
No external dependencies.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ADMEs

Each util (boolean, dotProp, uuid) now lives in its own folder with a
barrel index.ts and a dedicated README. The root utils/README.md becomes
an index table linking to each util's README.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
typeof check is a single pointer-tag comparison — much cheaper than
Object.prototype.toString.call() + string matching for the most
common input type.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Same rationale as the boolean fast path — typeof + strict equality
is cheaper than Object.prototype.toString.call() for numbers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@brunozoric brunozoric self-assigned this Jun 7, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@brunozoric brunozoric merged commit 5fa60fc into main Jun 7, 2026
16 checks passed
@brunozoric brunozoric deleted the bruno/feat/shared-uuid branch June 8, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant