snowflake-gen
v1.0.2
Published
Does what it says on the tin.
Downloads
8
Readme
Snowflake Generator
Does what it says on the tin.
Usage
The function accepts an optional parameter which is a Unix timestamp (ms) to use as the epoch for the snowflake. This defaults to Discord's value (1420070400000
).
import { generateSnowflake } from 'snowflake-gen';
generateSnowflake() // 1119762871952658432
generateSnowflake(0) // 1119781265757814784
How does it work?
Snowflakes are split into three sections:
- A 41-bit Unix epoch
- A 10-bit machine ID (we use randomness because I'm lazy)
- A 12-bit sequence
This library uses bitshifting to construct the snowflake. See the JSDoc and source code for details.