{"id":15249855,"url":"https://github.com/coolaj86/uuidv7","last_synced_at":"2025-07-07T00:31:35.793Z","repository":{"id":257800575,"uuid":"860786977","full_name":"coolaj86/uuidv7","owner":"coolaj86","description":"UUIDv7, written in Zig (and Go, and JS, and Swift - just for good measure, of course)","archived":false,"fork":false,"pushed_at":"2025-01-10T04:10:23.000Z","size":59,"stargazers_count":2,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T16:28:41.022Z","etag":null,"topics":["go","golang","javascript","swift","uuid","uuid-generator","uuidv7","zig","ziglang"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coolaj86.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2024-09-21T06:58:19.000Z","updated_at":"2025-01-10T04:05:09.000Z","dependencies_parsed_at":"2024-09-26T03:28:58.165Z","dependency_job_id":null,"html_url":"https://github.com/coolaj86/uuidv7","commit_stats":null,"previous_names":["coolaj86/polyglot-uuidv7"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolaj86%2Fuuidv7","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolaj86%2Fuuidv7/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolaj86%2Fuuidv7/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolaj86%2Fuuidv7/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coolaj86","download_url":"https://codeload.github.com/coolaj86/uuidv7/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248271920,"owners_count":21075800,"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","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":["go","golang","javascript","swift","uuid","uuid-generator","uuidv7","zig","ziglang"],"created_at":"2024-09-29T15:07:38.502Z","updated_at":"2025-04-10T18:43:53.965Z","avatar_url":"https://github.com/coolaj86.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [uuidv7](https://github.com/coolaj86/uuidv7)\n\nGenerate UUID v7 strings, like `019212d3-87f4-7d25-902e-b8d39fe07f08`.\n\n```sh\nuuidv7 \u003e uuidv7.txt\n```\n\n```text\n019212d3-87f4-7d25-902e-b8d39fe07f08\n```\n\n|        32-bit time         | 16-bit time | 4 ver + 12 rnd | 2 var + 14 rnd |              16 rnd + 32 rnd               |\n| :------------------------: | :---------: | :------------: | :------------: | :----------------------------------------: |\n| 01\u0026nbsp;92\u0026nbsp;12\u0026nbsp;d3 | 87\u0026nbsp;f4  |   7d\u0026nbsp;25   |   90\u0026nbsp;2e   | b8\u0026nbsp;d3\u0026nbsp;9f\u0026nbsp;e0\u0026nbsp;7f\u0026nbsp;08 |\n\n# Table of Contents\n\n- [Install](#install)\n- [In JavaScript](#javascript-version)\n- [UUIDv7 Spec](#uuidv7-spec)\n  - [By the Characters](#by-the-characters)\n  - [By the Bits](#by-the-bits)\n- [Build](#build)\n  - [Go Build (and TinyGo)](#go)\n  - [Swift](#swift)\n  - [Zig Build](#zig)\n- [License](#license)\n\n# Install\n\nPre-built archives available for Mac, Linux, \u0026 Widows. \\\nCompile from source for FreeBSD, OpenBSD, etc.\n\n1. Download from GitHub Releases: \u003chttps://github.com/coolaj86/uuidv7/releases\u003e\n2. Extract\n3. Place in your `PATH`\n\n```sh\nb_triplet='x86_64-linux-musl'\ncurl -L -O https://github.com/coolaj86/uuidv7/releases/download/v1.0.0/uuidv7-v1.0.0-\"$b_triplet\".tar.gz\ntar xvf ./uuidv7-v1.0.0-\"$b_triplet\".tar.gz\nmv ./uuidv7 ~/bin/\n```\n\n# JavaScript Version\n\nSupports both `import` and `require`.\n\nExtremely simple implementation that can be tuned for speed or memory\nefficiency.\n\n```sh\nnpm install --save @root/uuidv7\n```\n\nHigh-level API:\n\n```js\nimport UUIDv7 from \"@root/uuidv7\";\n\nUUIDv7.uuidv7();\n// 01922aa4-88ad-7cae-a517-a298a491d35c\n\nUUIDv7.uuidv7Bytes();\n// Uint8Array(16) [ 1, 146,  42, 176, 37, 122, 114, 189\n//                 172, 240,  1, 146, 42, 176,  37, 122 ]\n```\n\nLow-level API:\n\n```js\nlet buffer = new Uint8Array(4096); // optional, if you need lots of UUIDs, and fast\nUUIDv7.setBytesBuffer(buffer);\n```\n\n```js\nlet now = Date.now();\nlet ms64 = BigInt(now);\nlet bytes = new Uint8Array(16);\nlet start = 0;\nglobalThis.crypto.getRandomValues(bytes);\n\nvoid UUIDv7.fill(bytes, start, ms64);\n\nconsole.log(bytes);\n// Uint8Array(16) [ 1, 146,  42, 176, 37, 122, 114, 189\n//                 172, 240,  1, 146, 42, 176,  37, 122 ]\n```\n\n```js\nlet uuidv7 = UUIDv7.format(bytes);\nconsole.log(uuidv7);\n// 01922aa4-88ad-7cae-a517-a298a491d35c\n```\n\n# UUIDv7 Spec\n\n## By the Characters\n\nThere are 36 characters total: 32 hex (`0123456789abcdef`) + 4 dashes (`-`)\n\n```text\n  8 time    4 time    1v + 3ra   ½v + 3½rb    12 random b\n019212d3  -  87f4   -   7d25   -   902e   -   b8d39fe07f08\n```\n\n- 8ch hex time high\n- `-`\n- 4ch hex time low\n- `-`\n- 4ch hex version + \"random a\"\n  - 1ch hex version: `7`\n  - 3ch hex \"random a\"\n- `-`\n- 4ch hex variant + \"random b\"\n  - 1ch hex version: `8`, `9`, `a`, `b`\n  - 3ch hex \"random b\"\n- `-`\n- 12ch hex randam a\n  - 4ch hex random a\n  - 8ch hex random a\n\n## By the Bits\n\nThere are 128 bits total: \\\n48 time and 80 random, with 4 version and 2 variant bits substituted\n\n```text\n   48 time         4ver, 12ra   2var, 14rb        random b\n019212d3-87f4    -    7d25    -    902e    -    b8d39fe07f08\n```\n\n- 48 bits of timestamp\n  - 32-bit high (minutes to years)\n  - 16-bit low (seconds \u0026 milliseconds)\n- 16 bits of version + random\n  - 4-bit version (`0b0111`)\n  - 12-bit random\n- 64-bits variant + random\n  - 2-bit variant (`0b10`)\n  - 62-bit random\n\n# Build\n\n## Go\n\n```sh\ncurl https://webi.sh/go | sh\nsource ~/.config/envman/PATH.env\n```\n\nFor the current platform:\n\n```sh\ngo build -o uuidv7 ./cmd/.\n```\n\nFor Linux containers:\n\n```sh\nGOOS=linux GOARCH=amd64 GOAMD64=v2 go build -o uuidv7 ./cmd/.\n```\n\nThe entire build matrix (into `./dist/`):\n\n```sh\ngoreleaser --snapshot --skip=publish --clean\n```\n\n### TinyGo\n\n```sh\ncurl https://webi.sh/go | sh\nsource ~/.config/envman/PATH.env\n```\n\n```sh\ntinygo build -o uuidv7 ./cmd/.\n```\n\n```sh\nGOOS=linux GOARCH=amd64 GOAMD64=v2 tinygo build -o uuidv7 ./cmd/.\n```\n\n## Swift\n\n```sh\nswift build --configuration release --show-bin-path\n\n./.build/arm64-apple-macosx/release/uuidv7\n```\n\n## Zig\n\nSee \u003c/build.sh\u003e.\n\nBuilds with zig v0.13 and the v0.14 previews so far.\n\n```sh\ncurl https://webi.sh/zig@0.13 | sh\nsource ~/.config/envman/PATH.env\n```\n\n```sh\nzig build-exe ./uuidv7.zig -O ReleaseSmall -femit-bin=\"uuidv7\"\n\nfor b_target in x86-linux-musl aarch64-macos-none x86_64-windows-gnu; do\n    zig build-exe ./uuidv7.zig -O ReleaseSmall \\\n        -target \"${b_target}\" -femit-bin=\"uuidv7-${b_target}\"\ndone\n```\n\n# License\n\nCopyright 2024 AJ ONeal \u003caj@therootcompany.com\u003e\n\nThis Source Code Form is subject to the terms of the Mozilla Public \\\nLicense, v. 2.0. If a copy of the MPL was not distributed with this \\\nfile, You can obtain one at https://mozilla.org/MPL/2.0/.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoolaj86%2Fuuidv7","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoolaj86%2Fuuidv7","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoolaj86%2Fuuidv7/lists"}