Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

id.ts

9 lines436 Bytes

1export function generateId(prefix: string): string {
2 const timestamp = Date.now()
3 // Drop the "0." prefix from the base36 float (2 chars), keeping the full
4 // random portion (~9+ chars of entropy). Previously used `.substring(7)`
5 // which left only ~4 random chars — see the regression test in ai-fal's
6 // utils.
7 const randomPart = Math.random().toString(36).substring(2)
8 return `${prefix}-${timestamp}-${randomPart}`
9}