MCPcopy Create free account
hub / github.com/cortexkit/magic-context / generateUuidV7

Function generateUuidV7

packages/cli/src/commands/migrate.ts:199–210  ·  view source on GitHub ↗
(date = new Date())

Source from the content-addressed store, hash-verified

197}
198
199export function generateUuidV7(date = new Date()): string {
200 const bytes = randomBytes(16);
201 let ms = BigInt(date.getTime());
202 for (let i = 5; i >= 0; i--) {
203 bytes[i] = Number(ms & 0xffn);
204 ms >>= 8n;
205 }
206 bytes[6] = (bytes[6] & 0x0f) | 0x70;
207 bytes[8] = (bytes[8] & 0x3f) | 0x80;
208 const hex = bytes.toString("hex");
209 return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
210}
211
212function shortId(): string {
213 return randomBytes(4).toString("hex");

Callers 1

buildPiEntriesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected