MCPcopy Create free account
hub / github.com/anomalyco/opencode / create

Function create

packages/schema/src/identifier.ts:14–30  ·  view source on GitHub ↗
(descending: boolean, timestamp = Date.now())

Source from the content-addressed store, hash-verified

12}
13
14export function create(descending: boolean, timestamp = Date.now()) {
15 if (timestamp !== lastTimestamp) {
16 lastTimestamp = timestamp
17 counter = 0
18 }
19 counter++
20
21 const current = BigInt(timestamp) * 0x1000n + BigInt(counter)
22 const value = descending ? ~current : current
23 const time = Array.from({ length: 6 }, (_, index) =>
24 Number((value >> BigInt(40 - 8 * index)) & 0xffn)
25 .toString(16)
26 .padStart(2, "0"),
27 ).join("")
28 const bytes = crypto.getRandomValues(new Uint8Array(length - 12))
29 return time + Array.from(bytes, (byte) => chars[byte % 62]).join("")
30}

Callers 2

ascendingFunction · 0.70
descendingFunction · 0.70

Calls 1

fromMethod · 0.45

Tested by

no test coverage detected