{"id":30057306,"url":"https://github.com/nrjdalal/msid","last_synced_at":"2025-08-07T23:57:22.847Z","repository":{"id":304475568,"uuid":"1018872100","full_name":"nrjdalal/msid","owner":"nrjdalal","description":"Minimal, monotonic, URL-safe, Client-first, reversible date-based IDs - just 7 chars for millisecond precision!","archived":false,"fork":false,"pushed_at":"2025-08-04T00:01:02.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-04T02:34:45.452Z","etag":null,"topics":["base-n","date","day","decoder","encoder","milliseconds","monotonic","reversible","seconds"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/msid","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nrjdalal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"nrjdalal"}},"created_at":"2025-07-13T08:26:35.000Z","updated_at":"2025-07-31T00:03:56.000Z","dependencies_parsed_at":"2025-07-13T11:49:00.498Z","dependency_job_id":null,"html_url":"https://github.com/nrjdalal/msid","commit_stats":null,"previous_names":["nrjdalal/msid"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nrjdalal/msid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrjdalal%2Fmsid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrjdalal%2Fmsid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrjdalal%2Fmsid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrjdalal%2Fmsid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nrjdalal","download_url":"https://codeload.github.com/nrjdalal/msid/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrjdalal%2Fmsid/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269343299,"owners_count":24401085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-07T02:00:09.698Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["base-n","date","day","decoder","encoder","milliseconds","monotonic","reversible","seconds"],"created_at":"2025-08-07T23:57:19.741Z","updated_at":"2025-08-07T23:57:22.824Z","avatar_url":"https://github.com/nrjdalal.png","language":"TypeScript","funding_links":["https://github.com/sponsors/nrjdalal"],"categories":[],"sub_categories":[],"readme":"# msid\n\n**Minimal, monotonic, URL-safe, Client-first, reversible date-based IDs - just 7 chars for millisecond precision!**\n\n[![Twitter](https://img.shields.io/twitter/follow/nrjdalal?label=%40nrjdalal)](https://twitter.com/nrjdalal) [![npm](https://img.shields.io/npm/v/msid?color=blue\u0026logo=npm)](https://www.npmjs.com/package/msid) [![downloads](https://img.shields.io/npm/dt/msid?color=blue\u0026logo=npm)](https://www.npmjs.com/package/msid) [![stars](https://img.shields.io/github/stars/nrjdalal/msid?color=blue\u0026logo=github)](https://github.com/nrjdalal/msid)\n\n\u003e Encode any `Date` (or “now”) into the shortest possible, msid guarantees **lexographically sortable** and **strictly increasing IDs** when called in rapid succession string at **ms**, **second**, or **day** precision - and decode it back without loss.\n\n- **ms resolution (default)** ~ 7 chars\n- **second resolution** ~ 6 chars\n- **day resolution** ~ 4 chars\n\n---\n\n## 📖 Examples\n\n```ts\n// Millisecond precision (default)\nmsid()\n// encoded - UqofYU9 ~ 7 chars\n// current - 2025-07-13T08:18:15.597Z\n// decoded - 2025-07-13T08:18:15.597Z\n\n// Second precision\nmsid({ resolution: \"second\" })\n// encoded - 1uaruZ ~ 6 chars\n// current - 2025-07-13T08:18:15.597Z\n// decoded - 2025-07-13T08:18:15.000Z\n\n// Day precision\nmsid({ resolution: \"day\" })\n// encoded - 05H8 ~ 4 chars\n// current - 2025-07-13T08:18:15.597Z\n// decoded - 2025-07-13T00:00:00.000Z\n```\n\n---\n\n## ✨ Features\n\n- 🔢 **Variable‑length Base‑N** (no padding)\n- 📆 **Multi‑resolution**: `ms` | `second` | `day`\n- ⏳ **Custom epoch**: any start date (default `1970-01-01T00:00:00Z`)\n- 🔤 **Custom alphabet**: URL‑safe (`0-9A-Za-z`)\n- 🔄 **Reversible**: `msid(id)` restores the exact instant\n- 🔒 **Monotonic**: guarantees strictly increasing IDs when called in rapid succession, with optimized fast-path for default epoch/alphabet and fallback for custom settings\n\n---\n\n## 🚀 Quick Start\n\n```sh\nbun add msid\n# npm install msid\n```\n\nBased on the input type, it will either encode a `Date` to a string or decode a string back to a `Date`.\n\n```ts\nimport msid from \"msid\"\n\n// Encode current time\nmsid() // → UqofYU9\n\n// Encode in resolution: \"ms\" default\nmsid({ resolution: \"ms\" }) // → UqofYU9\n\n// Encode in resolution: \"second\"\nmsid({ resolution: \"second\" }) // → 1uaruZ\n\n// Encode in resolution: \"day\"\nmsid({ resolution: \"day\" }) // → 05H8\n\n// Decode in resolution: \"ms\" default\nmsid(\"UqofYU9\") // → 2025-07-13T08:18:15.597Z\n\n// Decode in resolution: \"second\"\nmsid(\"1uaruZ\") // → 2025-07-13T08:18:15.000Z\n\n// Decode in resolution: \"day\"\nmsid(\"05H8\") // → 2025-07-13T00:00:00.000Z\n\n// Custom epoch\nmsid({ epoch: \"2000-01-01T00:00:00.000Z\" }) // → EBT2bwj\n\n// Custom alphabet\nmsid({ alphabet: \"0123456789abcdef\" }) // → 19802dd03ad\n```\n\n---\n\n## 🛠️ Benchmarks\n\n```\nPlatform:      darwin\nArchitecture:  arm64\nCPU Model:     Apple M2 Pro\nCPU Cores:     12\nTotal Memory:  16.00 GB\n```\n\n```\nUsing hyperfine for benchmarking!\n\n📝 Encode comparison (Node.js vs. Bun):\n\nBenchmark 1: node ./test/bench.js msid\n  Time (mean ± σ):     352.0 ms ±   3.7 ms    [User: 333.6 ms, System: 10.2 ms]\n  Range (min … max):   347.0 ms … 366.1 ms    100 runs\n\nBenchmark 2: bun ./test/bench.js msid\n  Time (mean ± σ):     319.0 ms ±   3.8 ms    [User: 313.5 ms, System: 14.3 ms]\n  Range (min … max):   312.0 ms … 329.7 ms    100 runs\n\nSummary\n  bun ./test/bench.js msid ran\n    1.10 ± 0.02 times faster than node ./test/bench.js msid\n\n📝 Decode comparison (Node.js vs. Bun):\n\nBenchmark 1: node ./test/bench.js decode\n  Time (mean ± σ):      92.7 ms ±   2.0 ms    [User: 80.4 ms, System: 6.3 ms]\n  Range (min … max):    90.7 ms … 108.2 ms    100 runs\n\nBenchmark 2: bun ./test/bench.js decode\n  Time (mean ± σ):      53.4 ms ±   1.9 ms    [User: 54.1 ms, System: 9.5 ms]\n  Range (min … max):    50.9 ms …  65.4 ms    100 runs\n\nSummary\n  bun ./test/bench.js decode ran\n    1.74 ± 0.07 times faster than node ./test/bench.js decode\n\n📝 MSID vs ULID encode time comparison:\n\nBenchmark 1: node ./test/bench.js msid\n  Time (mean ± σ):     352.7 ms ±   4.0 ms    [User: 334.1 ms, System: 10.4 ms]\n  Range (min … max):   347.8 ms … 375.2 ms    100 runs\n\nBenchmark 2: node ./test/bench.js ulid\n  Time (mean ± σ):     358.3 ms ±   7.3 ms    [User: 342.9 ms, System: 10.0 ms]\n  Range (min … max):   329.8 ms … 385.4 ms    100 runs\n\nSummary\n  node ./test/bench.js msid ran\n    1.02 ± 0.02 times faster than node ./test/bench.js ulid\n```\n\n---\n\n## 🔗 Related\n\n- [ULID](https://github.com/ulid/javascript) – Universally Unique Lexicographically Sortable Identifiers\n- [KSUID](https://github.com/segmentio/ksuid) – K-Sortable Globally Unique IDs\n\n---\n\n## 📄 License\n\nMIT – [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrjdalal%2Fmsid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnrjdalal%2Fmsid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrjdalal%2Fmsid/lists"}