# @pharastar/snowflakeid

> A lightweight module to generate time based 64-bit unique ids, inspired by Twitter id (snowflake).

Latest version **1.0.0** (published 2022-10-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @pharastar/snowflakeid
pnpm add @pharastar/snowflakeid
yarn add @pharastar/snowflakeid
bun add @pharastar/snowflakeid
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-10-26 |
| First published | 2022-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | pharastar.dev |
| Maintainers | pharastarllc |
| Keywords | snowflake, id, generator, id, authentication, flake |

## Links

- npm: https://www.npmjs.com/package/@pharastar/snowflakeid
- Repository: https://github.com/PharaStarLLC/snowflakeid
- Homepage: https://github.com/PharaStarLLC/snowflakeid#readme
- Issues: https://github.com/PharaStarLLC/snowflakeid/issues
- npm.io page: https://npm.io/package/@pharastar/snowflakeid

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-10-26

## README

# SnowflakeId

A lightweight module to generate time based 64-bit unique ids, inspired by Twitter id (snowflake).

---

## Installation

NodeJS

```js
npm install @pharastar/snowflakeid
```

---

### Usage

Initializtion

```js
const SnowflakeId = require('@pharastar/snowflakeid'); /* on node js only */

//initiate flake
const snowflake = new SnowflakeId({
    mid: 420, // optional, define machine id
    timeOffset: (2022 - 1970) * 31536000 * 1000 // optional, define a offset time
});
```

Create a instance of snowflake as shown above which will be used to generate snowflake ids afterward.

Id generation

```js
const id1 = snowflake.gen(); // returns something like 112867124767768576
const id2 = snowflake.gen(); // returns something like 112867124784545792
```

#### Options

mid: (Defaults to 1) A machine id or any random id. If you are generating id in distributed system, its highly advised to provide a proper mid which is unique to different machines.

timeOffset: (Defaults to 0) Time offset will be subtracted from current time to get the first 42 bit of id. This help in generating smaller ids.

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