1.0.2 • Published 11 months ago

snowflake-gen v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

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.

1.0.2

11 months ago

1.0.1

11 months ago