1.0.1 • Published 4 years ago

errorsparty.dev-snowflake v1.0.1

Weekly downloads
3
License
MIT
Repository
-
Last release
4 years ago

errorsparty.dev-snowflake

An identity for everyone.

A unique ID that also includes a timestamp of when it was generated.

96 (43) Timestamp
53 (17) Service ID
36 (20) Incrementor Value
16 (16) Random 2 Bytes
 0

After the date of 26th September, 2178. 15:10, this module will produce 13 bytes instead of 12 bytes.

Usage

// Imports
import { Snowflake } from "errorspary.dev-snowflake";
import { Schema } from "mongoose";

const mySchema = new Schema({
	id: { type: BigInt, unique: true, default: () => new Snowflake() }
});

and parse a snowflake:

// Imports
import { Snowflake } from "errorspary.dev-snowflake";

console.log(
	Snowflake.from("iETT6ifUVvLq9Tb3")
);
// Snowflake {
//   fullYear: 2020,
//   month: 5,
//   date: 23,
//   hours: 11,
//   minutes: 59,
//   seconds: 1,
//   milliseconds: 90,
//   serviceID: 0,
//   noise: 23617,
//   incrementor: 0,
//   num: 14347624808338048402356984897n,
//   str: 'iETT6ifUVvLq9Tb3'
// }