@mpact/mulsid
v0.1.0
Published
Mini Unique Lexicographically-Sortable IDs
Maintainers
Readme
MULSID
Mini Unique Lexicographically Sortable ID. A short (10 character) ID for improved database efficiency in inserts and storage. MULSID is not suitable certain use-cases, as it makes a compromise on randomness to favor shorter ID length.
About
You can read more about MULSID, how it works, and what it is useful for in this blog post. Check out the demo to see MULSID in action.
Install
NPM
npm install @mpact/mulsidBun
bun add @mpact/mulsidDeno
deno add jsr:@mpact/mulsidUsage
To generate a random MULSID, you can import and use the mulsid function
import { mulsid } from "@mpact/mulsid";
const id = mulsid() // 3Ra1dnMrqSYou can also guarantee a monotonically increasing ID by using the monotonicMULSID function
import { monotonicMULSID } from "@mpact/mulsid";
const id1 = monotonicMULSID(); // 3Ra1iMP4L5
const id2 = monotonicMULSID(); // 3Ra1iMP4L6You can also determine the time the MULSID was generated within 9 milliseconds using the decodeTime function
import { mulsid, decodeTimestamp } from "@mpact/mulsid";
const id = mulsid(0); // 0000000SeM
const time = decodeTimestamp(id); // 0
const id2 = mulsid(4); // 0000000rrc
const time2 = decodeTimestamp(id2); // 0
const id3 = mulsid(10); // 0000001uLE
const time3 = decodeTimestamp(id3) // 9