MCPcopy Create free account
hub / github.com/arctic-cli/interface / create

Function create

packages/arctic/src/id/id.ts:53–72  ·  view source on GitHub ↗
(prefix: keyof typeof prefixes, descending: boolean, timestamp?: number)

Source from the content-addressed store, hash-verified

51 }
52
53 export function create(prefix: keyof typeof prefixes, descending: boolean, timestamp?: number): string {
54 const currentTimestamp = timestamp ?? Date.now()
55
56 if (currentTimestamp !== lastTimestamp) {
57 lastTimestamp = currentTimestamp
58 counter = 0
59 }
60 counter++
61
62 let now = BigInt(currentTimestamp) * BigInt(0x1000) + BigInt(counter)
63
64 now = descending ? ~now : now
65
66 const timeBytes = Buffer.alloc(6)
67 for (let i = 0; i < 6; i++) {
68 timeBytes[i] = Number((now >> BigInt(40 - 8 * i)) & BigInt(0xff))
69 }
70
71 return prefixes[prefix] + "_" + timeBytes.toString("hex") + randomBase62(LENGTH - 12)
72 }
73}

Callers 1

generateIDFunction · 0.70

Calls 1

randomBase62Function · 0.70

Tested by

no test coverage detected