1.0.5 • Published 1 year ago

discord-snowflake-id v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

discord-snowflake-id

discord-snowflake-id is a library for parsing Discord snowflake IDs and with zero dependencies

Installation

Install this package using the following command in your terminal:

npm i discord-snowflake-id
yarn add discord-snowflake-id
pnpm add discord-snowflake-id

Example Usage

Import this package like this:

import { Snowflake } from "discord-snowflake-id"

...or using CommonJS require function:

const { Snowflake } = require("discord-snowflake-id")

Then use Snowflake object to get timestamp, worker id, process id and increment from an ID. Here is an example in TypeScript:

const { timestamp, workerId, processId, increment } = new Snowflake("635867082751344641")

And there is also a way to generate a Snowlake object from timestamp, worker id, process id and increment. Take a look at this example:

const { id } = Snowflake.construct({ timestamp, workerId, processId, increment })