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

Function create

packages/util/src/identifier.ts:28–47  ·  view source on GitHub ↗
(descending: boolean, timestamp?: number)

Source from the content-addressed store, hash-verified

26 }
27
28 export function create(descending: boolean, timestamp?: number): string {
29 const currentTimestamp = timestamp ?? Date.now()
30
31 if (currentTimestamp !== lastTimestamp) {
32 lastTimestamp = currentTimestamp
33 counter = 0
34 }
35 counter++
36
37 let now = BigInt(currentTimestamp) * BigInt(0x1000) + BigInt(counter)
38
39 now = descending ? ~now : now
40
41 const timeBytes = Buffer.alloc(6)
42 for (let i = 0; i < 6; i++) {
43 timeBytes[i] = Number((now >> BigInt(40 - 8 * i)) & BigInt(0xff))
44 }
45
46 return timeBytes.toString("hex") + randomBase62(LENGTH - 12)
47 }
48}

Callers 2

ascendingFunction · 0.70
descendingFunction · 0.70

Calls 1

randomBase62Function · 0.70

Tested by

no test coverage detected