Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • KSUID

Index

Constructors

constructor

Properties

Protected base

base: BaseN

Protected epoch

epoch: number

Protected pad

pad: (x: any) => string

Type declaration

    • (x: any): string
    • Parameters

      • x: any

      Returns string

Protected Optional rnd

rnd: IRandom

Readonly size

size: number

Returns the byte size of a single ID, based on the KSUID's configuration. The default config (payload 16 bytes) will result in 20-byte IDs (27 chars base62 encoded).

Methods

format

  • format(buf: Uint8Array): string
  • Returns baseN encoded version of given binary ID (generated via .nextBinary()).

    Parameters

    • buf: Uint8Array

    Returns string

next

  • next(): string
  • Returns a new baseN encoded ID string.

    Returns string

nextBinary

  • nextBinary(): Uint8Array
  • Returns a new ID as byte array.

    Returns Uint8Array

parse

  • parse(id: string): { epoch: number; id: Uint8Array }
  • Takes a KSUID string (assumed to be generated with the same config as this instance) and parses it into an object of: { epoch, id }, where epoch is the Unix epoch of the ID and id the random bytes.

    remarks

    This operation requires bigint support by the host environment.

    Parameters

    • id: string

    Returns { epoch: number; id: Uint8Array }

    • epoch: number
    • id: Uint8Array

timeOnly

  • timeOnly(epoch?: number): string
  • Returns a new baseN encoded ID string for given epoch (default: current time) and with all random payload bytes set to 0.

    Parameters

    • Optional epoch: number

    Returns string

timeOnlyBinary

  • timeOnlyBinary(epoch?: number): Uint8Array
  • Binary version of {@link KSUI.timeOnly}, but returns byte array. The first 4 bytes will contain the timestamp.

    Parameters

    • epoch: number = ...

    Returns Uint8Array

Generated using TypeDoc