Snowflakify class for generating snowflake IDs.

Hierarchy

  • default

Constructors

  • Remarks

    A Snowflakify instance must follow the following conditions:

    • At least one TimestampFragment or RandomFragment.
    • A RandomFragment must be coupled with at least one TimestampFragment or SequenceFragment.

    Parameters

    • Optional options: SnowflakifyOptions

      Optional parameter for specifying Snowflakify options.

      Can be an array of fragments or an object with the following properties:

      • epoch: A custom epoch timestamp.
      • preset: "worker_process", "ipv4", or "mac"

    Returns default

Properties

buffer: default
fragments: FragmentArray

Array of fragments used to generate snowflake IDs.

Remarks

When reading this array outside of a Snowflakify class:

  • Do not call fragments methods.
  • Do not add or remove fragments.
  • Do not reorder fragments.
  • Do not modify this array.
totalBits: number

Total number of bits in the snowflake ID.

Methods

  • Returns a destructured snowflake.

    Returns

    An array of destructured fragments.

    Throws

    [SNOWFLAKE_INVALID] If snowflake is not a number, bigint, or string of a positive number.

    Parameters

    • snowflake: string | number | bigint

      The snowflake to be destructured.

    Returns DestructuredFragment[]

  • Returns a destructured snowflake.

    Returns

    An array of destructured fragments.

    Throws

    [SNOWFLAKE_INVALID] If snowflake is not a valid hexademical string.

    Parameters

    • snowflake: string

      The hexadecimal snowflake to be destructured.

    Returns DestructuredFragment[]

  • Returns the buffers content.

    Returns

    An array of snowflake IDs or undefined if the buffer is not instatiated.

    Returns undefined | BigInt64Array

  • Returns a snowflake ID as Hexadecimal.

    Returns

    a snowflake ID converted to Hexadecimal

    Returns string

  • Returns a snowflake ID.

    Returns

    The sum of all fragments values shifted to the left by their bitShift.

    Returns bigint

Generated using TypeDoc