idb-ts
    Preparing search index...

    Class KeyGenerators

    Built-in key generation utilities used by the KeyPath generator option and available for direct use in application code.

    import { KeyGenerators } from 'idb-ts';

    const id = KeyGenerators.uuid(); // UUID v4 (backward compatible)
    const idV4 = KeyGenerators.uuidV4(); // RFC 4122 v4 (random)
    const idV6 = KeyGenerators.uuidV6(); // RFC 4122 v6 (time-based)
    const timestamp = KeyGenerators.timestamp(); // 1696118400000
    const random = KeyGenerators.random(); // "xyz789abc123"
    Index

    Constructors

    Methods

    • Generates a short random alphanumeric string derived from Math.random().toString(36).

      Returns string

      A random string of approximately 13 characters, e.g., "xyz789abc123".

    • Returns the current Unix timestamp in milliseconds (Date.now()).

      Returns number

      A numeric timestamp, e.g., 1696118400000.

    • Generates a RFC 4122 UUID v4 string (alias for uuidV4). For backward compatibility and convenience.

      Returns string

      A UUID v4 string.

    • Generates a RFC 4122 UUID v4 string using cryptographically secure random. Uses Node.js crypto module when available, falls back to browser crypto API, then to Math.random() as final fallback.

      Returns string

      A UUID v4 string, e.g., "a1b2c3d4-e5f6-4789-abcd-ef1234567890".

    • Generates a RFC 4122 UUID v6 string (time-based with random component). UUID v6 offers better database indexing performance than v4 due to temporal ordering.

      Returns string

      A UUID v6 string, e.g., "1ef5a6c2-0000-6000-8000-000000000000".