@pwldev/discord-snowflake
v1.0.4
Published
A single file package to generate, parse, and do more with Discord Snowflake IDs
Downloads
10
Maintainers
Readme
Discord Snowflake
An easy to use single file package to generate, parse and do more with Discord Snowflake IDs.
Installation
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");
Methods
generate
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
getDate
Gets a Snowflake ID's timestamp as a Date instance
import * as Snowflake from "@pwldev/discord-snowflake";
Snowflake.getDate(1087853498709577700)
// Date
getIncrement
Gets a Snowflake ID's increment
import * as Snowflake from "@pwldev/discord-snowflake";
Snowflake.getIncrement(1087853498709577700)
// 3769
getProcessId
Gets a Snowflake ID's Process ID
import * as Snowflake from "@pwldev/discord-snowflake";
Snowflake.getProcessId(1087853498709577700)
// 3769
getTimestamp
Gets a Snowflake ID's Unix Timestamp
import * as Snowflake from "@pwldev/discord-snowflake";
Snowflake.getTimestamp(1087853498709577700)
// 1087853498709577700
getWorkerId
Gets a Snowflake ID's Worker ID
import * as Snowflake from "@pwldev/discord-snowflake";
Snowflake.getWorkerId(1087853498709577700)
// 3769
parse
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 }
Links
Created by PwLDev Based on the official Discord API docs.