Skip to content

Snowflake

Snowflake

Represents a Snowflake, a unique identifier used in distributed systems.

Kind: global class

Snowflake.deconstruct(snowflake) ⇒ Object

Deconstructs a Discord snowflake into its individual components.

Kind: static method of Snowflake
Returns: Object - An object containing the deconstructed components of the snowflake:

  • createdAt: The date and time when the snowflake was created.
  • timestamp: The timestamp of the snowflake.
  • workerId: The ID of the worker that generated the snowflake.
  • processId: The ID of the process that generated the snowflake.
  • increment: The increment portion of the snowflake.
  • binary: The binary representation of the snowflake.
ParamTypeDescription
snowflakestringThe snowflake to deconstruct.

Snowflake.generate([timestamp]) ⇒ string

Generates a unique ID based on the given timestamp.

Kind: static method of Snowflake
Returns: string - - The generated unique ID.
Throws:

  • TypeError - If the timestamp is not a number or a valid Date object.
ParamTypeDefaultDescription
[timestamp]number | DateDate.now()The timestamp to generate the ID from.