discord-snowflake
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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-snowflake

Then 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"));
// => true

getTimestamp(snowflake: Snowflake): number

import { getTimestamp } from "discord-snowflake";

console.log(getTimestamp("90339695967350784"));
// => 1441609061949

getDate(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"));
// => 0

getProcessId(snowflake: Snowflake): Number

import { getProcessId } from "discord-snowflake";

console.log(getProcessId("90339695967350784"));
// => 3

getIncrement(snowflake: Snowflake): number

import { getIncrement } from "discord-snowflake";

console.log(getIncrement("90339695967350784"));
// => 0

parse(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.

Readme

Keywords

none

Package Sidebar

Install

npm i discord-snowflake

Weekly Downloads

8

Version

2.0.0

License

MIT

Unpacked Size

7.91 kB

Total Files

7

Last publish

Collaborators

  • ianmitchell
  • theking465