RandomFragment class for random IDs.

Hierarchy

Constructors

  • Remarks

    When using a custom random function, please ensure it returns a positive number no greater than 2 ** bits - 1.

    Throws

    [RND_FUNCTION_RETURN_TYPE] If custom function does not return number or bigint, or if the value is out of range.

    Parameters

    • bits: number

      The number of bits for the fragment.

    • Optional fn: (() => number | bigint)

      Optional custom random function.

        • (): number | bigint
        • Returns number | bigint

    Returns default

Properties

bitMask: bigint

The bit mask used to isolate the fragment's bits from the snowflake.

bitMask is equal to maxValue << bitShift

bitMaskHex: string

The hexadecimal representation of the bit mask as string.

bitShift: bigint

The number of bits for left and right shifting.

bitShift is equal to the number of bits on the right side

bits: number

The number of bits for the fragment.

fn?: (() => number | bigint)

Type declaration

    • (): number | bigint
    • Optional custom random function.

      Returns number | bigint

identifier: string

The fragment identifier.

maxValue: bigint

The maximum value that can be represented by this fragment.

maxValue is equal to 2 ** bits - 1

value: bigint

The current value of the fragment.

Methods

  • Internal

    Returns a destructured fragment.

    Remarks

    Do not use this method outside of a Snowflakify instance.

    Returns

    A destructured fragment object with the following properties:

    • identifier: The identifier of the ID.
    • value: The value of the fragment for that snowflake.

    Parameters

    • snowflake: string | number | bigint

      The snowflake to destructure.

    Returns DestructuredFragment

Generated using TypeDoc