2.0.0 • Published 3 years ago
discord-snowflake v2.0.0
discord-snowflake
discord-snowflake is a library for parsing Discord Snowflakes.
Usage
To install the package, run the following in your terminal:
npm install discord-snowflakeThen in your code import the library:
import * as SnowflakeUtils from "discord-snowflake";API
EPOCH
A constant representing the Discord epoch.
import { EPOCH } from "discord-snowflake";Type: Snowflake
A type representing a Discord Snowflake.
import type { Snowflake } from "discord-snowflake";Typeguard: isSnowflake(id: string): boolean
A typeguard function that returns whether the string is a valid Snowflake or not.
import { isSnowflake } from "discord-snowflake";
console.log(isSnowflake("90339695967350784"));
// => truegetTimestamp(snowflake: Snowflake): number
import { getTimestamp } from "discord-snowflake";
console.log(getTimestamp("90339695967350784"));
// => 1441609061949getDate(snowflake: Snowflake): Date
import { getDate } from "discord-snowflake";
console.log(getDate("90339695967350784"));
// => 2015-09-07T06:57:41.949Z (date object)getWorkerId(snowflake: Snowflake): number
import { getWorkerId } from "discord-snowflake";
console.log(getWorkerId("90339695967350784"));
// => 0getProcessId(snowflake: Snowflake): Number
import { getProcessId } from "discord-snowflake";
console.log(getProcessId("90339695967350784"));
// => 3getIncrement(snowflake: Snowflake): number
import { getIncrement } from "discord-snowflake";
console.log(getIncrement("90339695967350784"));
// => 0parse(snowflake: Snowflake)
import { parse } from "discord-snowflake";
console.log(parse("90339695967350784"));
// => { timestamp: 1441609061949, workerId: 0, processId: 3, increment: 0 }Credits
Special thanks to theking465 for the original package implementation.