std@0.144.0/uuid

Deno standard library
GitHub Stars
2196
Go to latest
import * as mod from "https://deno.land/std@0.144.0/uuid/mod.ts";

Generators and validators for UUIDs for versions 1, 4 and 5.

Functions

isNil

Check if the passed UUID is the nil UUID.

v1.generate

Generates a RFC4122 v1 UUID (time-based).

v1.validate

Validates the UUID v1.

v4.generate 👎 deprecated
v4.validate

Validate that the passed UUID is an RFC4122 v4 UUID.

v5.generate

Generate a RFC4122 v5 UUID (SHA-1 namespace).

v5.validate

Validate that the passed UUID is an RFC4122 v5 UUID.

validate

Test a string to see if it is a valid UUID.

version

Detect RFC version of a UUID.

Interfaces

v1.V1Options

The options used for generating a v1 UUID.

std/uuid

Generate and validate v1, v4, and v5 UUIDs.

Examples

Generate and validate a v4 (random) UUID

import { v4 } from "https://deno.land/std@0.144.0/uuid/mod.ts";

// Generate a v4 UUID. For this we use the browser standard `crypto.randomUUID`
// function.
const myUUID = crypto.randomUUID();

// Validate the v4 UUID.
const isValid = v4.validate(myUUID);

Generate and validate a v5 (SHA-1 digest) UUID

import { v5 } from "https://deno.land/std@0.144.0/uuid/mod.ts";

const data = new TextEncoder().encode("Hello World!");

// Generate a v5 UUID using a namespace and some data.
const myUUID = await v5.generate("6ba7b810-9dad-11d1-80b4-00c04fd430c8", data);

// Validate the v5 UUID.
const isValid = v5.validate(myUUID);