feat: shared UUID#18
Merged
Merged
Conversation
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>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
uuid()to@webiny/stdlib— a RFC 4122 v4 UUID generator that works in both Node.js and browser environmentscrypto.randomUUID()when available (Node.js, secure browser contexts) and falls back to a manual implementation usingcrypto.getRandomValues()for insecure (HTTP)contexts
Design
The fallback exists because
crypto.randomUUID()throws in browsers served over HTTP (requires a securecontext).
crypto.getRandomValues()has no such restriction, so the manual path coversthat gap.
The function lives in
src/common/utils/uuid/(platform-agnostic) and is exported from@webiny/stdlib.Test plan
4, variant bits are8,9,a, orbcrypto.randomUUIDis unavailable