Methods
randomUuid(withDashesopt, nullable) → {String}
Generate a RFC4122-compliant random UUID, as far as possible with JS. Generation is heavily dependent on the quality of randomization, which in some JS-engines is weak using Math.random. Therefore, we are using the specific crypto api if available and only fall back to random if necessary. Additionally, we track used UUIDs to never return the same id twice per reload.
For a detailed discussion, see: https://stackoverflow.com/a/2117523
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
withDashes |
Boolean |
<optional> <nullable> |
true | defines if UUID shall include dashes or not |
Throws:
error if too many collisions happen and the random implementation seems to be broken
Returns:
a "UUID"
- Type
- String
Example
const uuidWithDashes = randomUuid();
const uuidWithoutDashes = randomUuid(false);