function

randomUUIDv5

function randomUUIDv5(
name: string | BufferSource,
namespace: string | BufferSource,
encoding?: 'base64' | 'base64url' | 'hex'
): string;

Generate a UUIDv5, a name-based UUID derived from the SHA-1 hash of a namespace UUID and a name.

@param name

The name to hash

@param namespace

A namespace UUID, or one of the predefined namespaces "dns", "url", "oid", or "x500"

@param encoding

Output encoding for the UUID

import { randomUUIDv5 } from "bun";
const uuid = randomUUIDv5("www.example.com", "dns");
console.log(uuid); // "2ed6657d-e927-568b-95e1-2665a8aea6a2"
import { randomUUIDv5 } from "bun";
const uuid = randomUUIDv5("www.example.com", "url");
console.log(uuid); // "b63cdfa4-3df9-568e-97ae-006c5b8fd652"
function randomUUIDv5(
name: string | BufferSource,
namespace: string | BufferSource,
encoding: 'buffer'
): Buffer;

Generate a UUIDv5 as a Buffer.

@param name

The name to hash

@param namespace

A namespace UUID, or one of the predefined namespaces "dns", "url", "oid", or "x500"

@param encoding

Pass "buffer" to get the UUID as bytes instead of a string

import { randomUUIDv5 } from "bun";
const uuid = randomUUIDv5("www.example.com", "url", "buffer");
console.log(uuid); // <Buffer b6 3c df a4 3d f9 56 8e 97 ae 00 6c 5b 8f d6 52>

Referenced types

type BufferSource =
| NodeJS.TypedArray<ArrayBufferLike>
| DataView<ArrayBufferLike>
| ArrayBufferLike