{"_id":"@axel669/asuid","name":"@axel669/asuid","dist-tags":{"latest":"0.2.1"},"versions":{"0.2.1":{"name":"@axel669/asuid","version":"0.2.1","description":"Similar idea to the ksuid, but uses a larger timestamp for millisecond resolution. Copy-paste friendly, 35 chars long, and lexicographical sorting of the ids will sort them by time, but if multiple asuids are generated in the same millisecond (or using th","type":"module","main":"dist/node.js","scripts":{"test":"aegis tests/**/*.test.js","build":"rollup -c config/rollup.config.js","mkdocs":"ipsen"},"bin":{"asuid":"cli.js"},"repository":{"type":"git","url":"git+https://github.com/axel669/lib.asuid.git"},"author":{"name":"Axel"},"license":"MIT","bugs":{"url":"https://github.com/axel669/lib.asuid/issues"},"homepage":"https://github.com/axel669/lib.asuid#readme","devDependencies":{"@axel669/aegis":"^0.2.7","@axel669/ipsen":"0.4.0-beta.3","rollup":"^4.5.2"},"exports":{".":"./dist/browser.js","./node":"./dist/node.js"},"gitHead":"18a856a8b30c166858e98ec62336174d0ad77bc0","_id":"@axel669/asuid@0.2.1","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-tR+aizUPcSCNSMbI9xQlYtAHk/1qtcm/4tbiU8hVoFDS1IrdcqG5fZ3EvZibkrTo2DKlgrd2y47XzMcFwPekaQ==","shasum":"69474a10c2ba568fe8d917c033d01838432a9d8d","tarball":"https://registry.npmjs.org/@axel669/asuid/-/asuid-0.2.1.tgz","fileCount":7,"unpackedSize":12378,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICsfhdvuugZ/J4cDJF89Au1CYYw76kSb29CXFX+lUIvaAiEAuk0xaMmngH1oCWmYpP3ddKsODKzyM7f7QoQVZprnIK4="}]},"_npmUser":{"name":"axel669","email":"axel@axel669.net"},"directories":{},"maintainers":[{"name":"axel669","email":"axel@axel669.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/asuid_0.2.1_1700878413942_0.533940364648539"},"_hasShrinkwrap":false}},"time":{"created":"2023-11-25T02:13:33.854Z","0.2.1":"2023-11-25T02:13:34.113Z","modified":"2023-11-25T02:13:34.396Z"},"maintainers":[{"name":"axel669","email":"axel@axel669.net"}],"description":"Similar idea to the ksuid, but uses a larger timestamp for millisecond resolution. Copy-paste friendly, 35 chars long, and lexicographical sorting of the ids will sort them by time, but if multiple asuids are generated in the same millisecond (or using th","homepage":"https://github.com/axel669/lib.asuid#readme","repository":{"type":"git","url":"git+https://github.com/axel669/lib.asuid.git"},"author":{"name":"Axel"},"bugs":{"url":"https://github.com/axel669/lib.asuid/issues"},"license":"MIT","readme":"# Almost Sortable Unique IDs\nSimilar idea to the ksuid, but uses a larger timestamp for millisecond\nresolution. Copy-paste friendly, 35 chars long, and lexicographical sorting of\nthe ids will sort them by time, but if multiple asuids are generated in the\nsame millisecond (or using the same timestamp) then the random bytes will\nprevent ordering them in perfect generated order (hence, almost sortable).\n\n<div class=\"demo-area\"></div>\n<script type=\"module\">\n    import asuid from \"https://esm.sh/@axel669/asuid\"\n    const demoArea = document.querySelector(\".demo-area\")\n    demoArea.innerHTML = `\n        <button ws-x=\"\">Generate</button>\n        <div>Generate an ASUID</div>\n    `\n    const resultArea = demoArea.querySelector(\"div\")\n    demoArea.querySelector(\"button\").addEventListener(\n        \"click\",\n        () => resultArea.innerText = asuid()\n    )\n</script>\n\n## Format\n\n`| 56 bit timestamp | 120 bit id |`\n\nThe 56 bit timestamp allows for values in the range\n[-8640000000000000, 8640000000000000] with millisecond precision. This means\nany valid JS date can become a valid asuid, including dates in the past (for\nassigning ids to older records).\n\n## Installation\n```bash\nnpm add @labyrinthos/asuid\n```\n\n## Usage\n\n### Imports\n\nBeacuse this library uses the js cryptography api, there is a different import\nfor node vs non-node envs.\n\n```js\n// browser/cloudflare workers\nimport asuid from \"@labyrinthos/asuid\"\n// node\nimport asuid from \"@labyrinthos/asuid/node\"\n```\n\n### Generate\n```js\n//  generate fully random asuid\nasuid()\n\n//  generate random id for a timestamp (or date)\nasuid(timeStamp)\nasuid(new Date(timeStamp))\nasuid(BigInt(timeStamp))\n\n//  generate asuid for current time with set id bytes\nasuid(null, uint8Array)\nasuid(null, idString)\n\n//  regenerate id from parts\nasuid(timeStamp, uint8Array)\nasuid(timeStamp, idString)\n```\n\n### Parse\n```js\nimport asuid from \"@labyrinthos/asuid\"\n\nconst parsed = asuid.parse(id)\n{\n    // timestamp for the asuid\n    time\n    // date object from the timestamp\n    date\n    // the id string (last 15 bytes/24 characters)\n    id\n    // the asuid that was parsed\n    source\n}\n```\n","readmeFilename":"readme.md"}