Provides functions to generate and validate UUIDs (Universally Unique Identifiers).
- Description:
- Provides functions to generate and validate UUIDs (Universally Unique Identifiers).
Methods
(static) v4() → {string}
- Description:
- Generates a random RFC 4122 Version 4 UUID. Uses the built-in, cryptographically secure random UUID generator.
Example
const uuid = require('uuid');
const newUuid = uuid.v4();
console.log(newUuid); // Outputs a random UUID
Returns:
A new UUID string (e.g., "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d").
- Type
- string
(static) validate(uuidString) → {boolean}
- Description:
- Validates if a string is a correctly formatted UUID. This function checks if the string matches the standard UUID format (8-4-4-4-12 hex digits). It does not check if the UUID is actually in use or registered, only its format.
Example
const uuid = require('uuid');
const isValid = uuid.validate('a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d');
console.log(isValid); // Outputs true or false
Parameters:
Name | Type | Description |
---|---|---|
uuidString |
string | The string to validate. |
Returns:
True if the string is a valid UUID, false otherwise.
- Type
- boolean