# discord-snowflake

> A library for identifying and parsing Discord Snowflakes

Latest version **2.0.0** (published 2022-07-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install discord-snowflake
pnpm add discord-snowflake
yarn add discord-snowflake
bun add discord-snowflake
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-07-28 |
| First published | 2021-01-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 7.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ianmitchell, theking465 |

## Links

- npm: https://www.npmjs.com/package/discord-snowflake
- Homepage: https://github.com/ianmitchell/interaction-kit/tree/main/packages/discord-snowflake
- npm.io page: https://npm.io/package/discord-snowflake

## Recent versions

- 2.0.0 (latest) — 2022-07-28
- 1.0.1 — 2021-01-19
- 1.0.0 — 2021-01-19

## README

# discord-snowflake

discord-snowflake is a library for parsing [Discord Snowflakes](https://discord.com/developers/docs/reference#snowflakes).

## Usage

To install the package, run the following in your terminal:

```
npm install discord-snowflake
```

Then in your code import the library:

```js
import * as SnowflakeUtils from "discord-snowflake";
```

## API

### `EPOCH`

A constant representing the Discord epoch.

```js
import { EPOCH } from "discord-snowflake";
```

### Type: `Snowflake`

A type representing a Discord Snowflake.

```ts
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.

```js
import { isSnowflake } from "discord-snowflake";

console.log(isSnowflake("90339695967350784"));
// => true
```

### `getTimestamp(snowflake: Snowflake): number`

```js
import { getTimestamp } from "discord-snowflake";

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

### `getDate(snowflake: Snowflake): Date`

```js
import { getDate } from "discord-snowflake";

console.log(getDate("90339695967350784"));
// =>  2015-09-07T06:57:41.949Z (date object)
```

### `getWorkerId(snowflake: Snowflake): number`

```js
import { getWorkerId } from "discord-snowflake";

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

### `getProcessId(snowflake: Snowflake): Number`

```js
import { getProcessId } from "discord-snowflake";

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

### `getIncrement(snowflake: Snowflake): number`

```js
import { getIncrement } from "discord-snowflake";

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

### `parse(snowflake: Snowflake)`

```js
import { parse } from "discord-snowflake";

console.log(parse("90339695967350784"));
// => { timestamp: 1441609061949, workerId: 0, processId: 3, increment: 0 }
```

# Credits

Special thanks to [theking465](https://github.com/theking465) for the original package implementation.

---
_Source: https://npm.io/package/discord-snowflake · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
