Skip to main content

Class: Snowflake

@sapphire/snowflake.Snowflake

A class for parsing snowflake ids

Hierarchy

Constructors

constructor

โ€ข new Snowflake(epoch)

Parameters

NameTypeDescription
epochnumber | bigint | Datethe epoch to use

Defined in

projects/utilities/packages/snowflake/src/lib/Snowflake.ts:28

Properties

#epoch

โ€ข Private #epoch: bigint

Internal reference of the epoch passed in the constructor

internal

Defined in

projects/utilities/packages/snowflake/src/lib/Snowflake.ts:17


#increment

โ€ข Private #increment: bigint

Internal incrementor for generating snowflakes

internal

Defined in

projects/utilities/packages/snowflake/src/lib/Snowflake.ts:11


decode

โ€ข decode: (id: string | bigint) => DeconstructedSnowflake

Type declaration

โ–ธ (id): DeconstructedSnowflake

Deconstructs a snowflake given a snowflake ID

example

const epoch = new Date('2000-01-01T00:00:00.000Z');
const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');
Parameters
NameTypeDescription
idstring | bigintthe snowflake to deconstruct
Returns

DeconstructedSnowflake

a deconstructed snowflake

Defined in

projects/utilities/packages/snowflake/src/lib/Snowflake.ts:23

Methods

deconstruct

โ–ธ deconstruct(id): DeconstructedSnowflake

Deconstructs a snowflake given a snowflake ID

example

const epoch = new Date('2000-01-01T00:00:00.000Z');
const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');

Parameters

NameTypeDescription
idstring | bigintthe snowflake to deconstruct

Returns

DeconstructedSnowflake

a deconstructed snowflake

Defined in

projects/utilities/packages/snowflake/src/lib/Snowflake.ts:79


generate

โ–ธ generate(options?): bigint

Generates a snowflake given an epoch and optionally a timestamp

example

const epoch = new Date('2000-01-01T00:00:00.000Z');
const snowflake = new Snowflake(epoch).generate();

Parameters

NameTypeDescription
optionsSnowflakeGenerateOptionsoptions to pass into the generator, see SnowflakeGenerateOptions note when increment is not provided it defaults to the private increment of the instance

Returns

bigint

A unique snowflake

Defined in

projects/utilities/packages/snowflake/src/lib/Snowflake.ts:44