(template: string, workspaces: readonly Workspace[])
| 10 | * Truncates the template part so the result always fits TAG_RE's 33 chars. |
| 11 | */ |
| 12 | export function defaultTagFor(template: string, workspaces: readonly Workspace[]): string { |
| 13 | const now = new Date() |
| 14 | const month = now.toLocaleString('en-US', { month: 'short' }).toLowerCase() |
| 15 | const date = `${month}${now.getDate()}` |
| 16 | const head = template.slice(0, 33 - date.length - 4) // room for "-" + date + "-NN" |
| 17 | const base = `${head}-${date}` |
| 18 | const taken = new Set(workspaces.map((w) => w.tag)) |
| 19 | if (!taken.has(base)) return base |
| 20 | let i = 2 |
| 21 | while (taken.has(`${base}-${i}`)) i++ |
| 22 | return `${base}-${i}` |
| 23 | } |
| 24 | |
| 25 | interface UseCreateWorkspaceOpts { |
| 26 | /** Workspace template to create from. Empty string = not yet selected. */ |
no test coverage detected