An easy to use single file package to generate, parse and do more with Discord Snowflake IDs.
To install this package with NPM use the command:
npm install @pwldev/discord-snowflake
This is a hybrid package, so you can import it both ways
import * as Snowflake from "@pwldev/discord-snowflake";
const SnowflakeManager = require("@pwldev/discord-snowflake");
Generates a Snowflake ID using a Unix Timestamp or Date instance.
import * as Snowflake from "@pwldev/discord-snowflake";
const newSnowflake = Snowflake.generate(1679460085433);
console.log(newSnowflake);
// 1087853498709577700
Gets a Snowflake ID's timestamp as a Date instance
import * as Snowflake from "@pwldev/discord-snowflake";
Snowflake.getDate(1087853498709577700)
// Date
Gets a Snowflake ID's increment
import * as Snowflake from "@pwldev/discord-snowflake";
Snowflake.getIncrement(1087853498709577700)
// 3769
Gets a Snowflake ID's Process ID
import * as Snowflake from "@pwldev/discord-snowflake";
Snowflake.getProcessId(1087853498709577700)
// 3769
Gets a Snowflake ID's Unix Timestamp
import * as Snowflake from "@pwldev/discord-snowflake";
Snowflake.getTimestamp(1087853498709577700)
// 1087853498709577700
Gets a Snowflake ID's Worker ID
import * as Snowflake from "@pwldev/discord-snowflake";
Snowflake.getWorkerId(1087853498709577700)
// 3769
Gets all information at once from a Snowflake ID
import * as Snowflake from "@pwldev/discord-snowflake";
Snowflake.parse(1087853498709577700)
// { "increment": 3769, "processId": 3769, "timestamp": 1420096000414, "workerId": 3769 }
Created by PwLDev
Based on the official Discord API docs.