// atproto timestamp identifiers: 53 bits of microseconds and a 10-bit clock id, as sortable base32. const ALPHABET = "234567abcdefghijklmnopqrstuvwxyz"; const CLOCK_ID = BigInt(Math.floor(Math.random() * 1024)); export const TID_PATTERN = /^[234567abcdefghij][234567abcdefghijklmnopqrstuvwxyz]{12}$/; let last = 0; export function tid(now = Date.now()): string { last = Math.max(now * 1000, last + 1); let n = (BigInt(last) << 10n) | CLOCK_ID; let out = ""; for (let i = 0; i < 13; i++, n >>= 5n) out = ALPHABET[Number(n & 31n)] + out; return out; }