CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-uuid

RFC9562 UUIDs

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

UUID

UUID is a comprehensive TypeScript library for generating RFC9562 (formerly RFC4122) compliant UUIDs. It supports all UUID versions (v1, v3, v4, v5, v6, v7) with secure random value generation, zero dependencies, and cross-platform compatibility for Node.js, browsers, and React Native.

Package Information

  • Package Name: uuid
  • Package Type: npm
  • Language: TypeScript (includes built-in types)
  • Installation: npm install uuid

Core Imports

import { 
  v1, v3, v4, v5, v6, v7, 
  parse, stringify, unsafeStringify, stringToBytes,
  validate, version, v1ToV6, v6ToV1,
  NIL, MAX, DNS, URL 
} from "uuid";

For CommonJS:

const { 
  v1, v3, v4, v5, v6, v7, 
  parse, stringify, unsafeStringify, stringToBytes,
  validate, version, v1ToV6, v6ToV1,
  NIL, MAX, DNS, URL 
} = require("uuid");

Individual imports:

import { v4 as uuidv4 } from "uuid";
import { parse as uuidParse, unsafeStringify } from "uuid";
import { DNS, URL } from "uuid";

Basic Usage

import { v4, v1, validate, parse, stringify } from "uuid";

// Generate random UUID (most common)
const randomId = v4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'

// Generate timestamp-based UUID
const timestampId = v1(); // ⇨ '4f20936c-6e8f-11ef-8f2f-d1234567890a'

// Validate UUID
const isValid = validate(randomId); // ⇨ true

// Convert between string and bytes
const bytes = parse(randomId); // ⇨ Uint8Array(16)
const backToString = stringify(bytes); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'

Architecture

The UUID package is structured around several core components:

  • UUID Generation: Functions for creating UUIDs of different versions (v1-v7)
  • UUID Utilities: Functions for parsing, stringifying, validating, and version detection
  • Constants: Predefined UUID values (NIL, MAX) and namespace constants
  • Type System: Complete TypeScript definitions with generic buffer support
  • Conversion Functions: Convert between UUID versions (v1↔v6)

Capabilities

UUID Generation

Core UUID generation functions supporting all RFC9562 versions, each optimized for different use cases from timestamp-based to namespace-based to random generation.

// Random UUID (most common)
function v4(options?: Version4Options): string;
function v4<TBuf extends Uint8Array>(options: Version4Options | undefined, buf: TBuf, offset?: number): TBuf;

// Timestamp-based UUIDs
function v1(options?: Version1Options): string;
function v1<TBuf extends Uint8Array>(options: Version1Options | undefined, buf: TBuf, offset?: number): TBuf;

function v6(options?: Version6Options): string;
function v6<TBuf extends Uint8Array>(options: Version6Options | undefined, buf: TBuf, offset?: number): TBuf;

function v7(options?: Version7Options): string;
function v7<TBuf extends Uint8Array>(options: Version7Options | undefined, buf: TBuf, offset?: number): TBuf;

// Namespace-based UUIDs
function v3(value: string | Uint8Array, namespace: UUIDTypes): string;
function v3<TBuf extends Uint8Array>(value: string | Uint8Array, namespace: UUIDTypes, buf: TBuf, offset?: number): TBuf;

function v5(value: string | Uint8Array, namespace: UUIDTypes): string;
function v5<TBuf extends Uint8Array>(value: string | Uint8Array, namespace: UUIDTypes, buf: TBuf, offset?: number): TBuf;

UUID Generation

UUID Utilities

Essential utility functions for working with UUIDs including parsing, stringifying, validation, version detection, and string conversion.

function parse(uuid: string): Uint8Array;
function stringify(arr: Uint8Array, offset?: number): string;
function unsafeStringify(arr: Uint8Array, offset?: number): string;
function stringToBytes(str: string): Uint8Array;
function validate(uuid: unknown): boolean;
function version(uuid: string): number;

UUID Utilities

Constants and Conversions

Predefined UUID constants and conversion functions for working with different UUID formats and versions.

const NIL: string; // '00000000-0000-0000-0000-000000000000'
const MAX: string; // 'ffffffff-ffff-ffff-ffff-ffffffffffff'
const DNS: string; // '6ba7b810-9dad-11d1-80b4-00c04fd430c8'
const URL: string; // '6ba7b811-9dad-11d1-80b4-00c04fd430c8'

function v1ToV6(uuid: string): string;
function v1ToV6(uuid: Uint8Array): Uint8Array;

function v6ToV1(uuid: string): string;
function v6ToV1(uuid: Uint8Array): Uint8Array;

Constants and Conversions

Types

Primary types used throughout the UUID package:

type UUIDTypes<TBuf extends Uint8Array = Uint8Array> = string | TBuf;

type Version1Options = {
  node?: Uint8Array;
  clockseq?: number;
  random?: Uint8Array;
  rng?: () => Uint8Array;
  msecs?: number;
  nsecs?: number;
  _v6?: boolean; // Internal use only!
};

type Version4Options = {
  random?: Uint8Array;
  rng?: () => Uint8Array;
};

type Version6Options = Version1Options;

type Version7Options = {
  random?: Uint8Array;
  msecs?: number;
  seq?: number;
  rng?: () => Uint8Array;
};
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/uuid@11.1.x
Publish Source
CLI
Badge
tessl/npm-uuid badge