Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/negezor/snowyflake
❄️ A modern implementation Snowflake on TypeScript
https://github.com/negezor/snowyflake
bigint generator snowflake typescript
Last synced: about 2 months ago
JSON representation
❄️ A modern implementation Snowflake on TypeScript
- Host: GitHub
- URL: https://github.com/negezor/snowyflake
- Owner: negezor
- License: mit
- Created: 2018-12-19T12:51:55.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-10T15:51:07.000Z (9 months ago)
- Last Synced: 2024-11-02T06:53:39.830Z (2 months ago)
- Topics: bigint, generator, snowflake, typescript
- Language: TypeScript
- Size: 1.02 MB
- Stars: 13
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Snowyflake - A modern implementation Snowflake on TypeScript
| 📖 [Documentation](docs/) |
|---------------------------|## Installation
> **[Node.js](https://nodejs.org/) 16.0.0 or newer is required**> **TypeScript config required `"target": "ES2019"` or higher**
### Yarn
Recommended
```
yarn add snowyflake
```### NPM
```
npm i snowyflake
```## Example usage
```js
import { Snowyflake, Epoch } from 'snowyflake';const snowyflake = new Snowyflake({
workerId: 1n,
epoch: Epoch.Twitter // BigInt timestamp
});const snowflake = snowyflake.nextId();
console.log(snowflake); // => 1075766315999952896n
const deconstructSnowflake = snowyflake.deconstruct(snowflake);
console.log(deconstructSnowflake); // =>
// { timestamp: 1545317651163n,
// workerId: 1n,
// processId: 0n,
// sequence: 0n }```