(raw: string)
| 18 | } |
| 19 | |
| 20 | export function parseTaskInput(raw: string): ParsedTask { |
| 21 | let text = raw |
| 22 | |
| 23 | // Extract @mentions — react-mentions format: @[display](id) |
| 24 | const tags: string[] = [] |
| 25 | text = text.replace(/@\[(\w+)\]\(\w+\)/g, (_, display: string) => { |
| 26 | tags.push(display) |
| 27 | return "" |
| 28 | }) |
| 29 | // Plain @word fallback |
| 30 | text = text.replace(/@(\w+)/g, (_, word: string) => { |
| 31 | tags.push(word) |
| 32 | return "" |
| 33 | }) |
| 34 | |
| 35 | // Extract priority p1–p4 |
| 36 | let priority_id: number | null = null |
| 37 | text = text.replace(/\bp([1-4])\b/gi, (_, n: string) => { |
| 38 | priority_id = Number.parseInt(n, 10) |
| 39 | return "" |
| 40 | }) |
| 41 | |
| 42 | // Extract due date |
| 43 | let due: string | null = null |
| 44 | const today = startOfDay(new Date()) |
| 45 | |
| 46 | text = text.replace(/\btoday\b/gi, () => { |
| 47 | due = today.toISOString() |
| 48 | return "" |
| 49 | }) |
| 50 | text = text.replace(/\btomorrow\b/gi, () => { |
| 51 | due = addDays(today, 1).toISOString() |
| 52 | return "" |
| 53 | }) |
| 54 | |
| 55 | for (const [name, dayIndex] of Object.entries(WEEKDAYS)) { |
| 56 | const pattern = new RegExp(`\\b${name}\\b`, "gi") |
| 57 | if (pattern.test(text)) { |
| 58 | text = text.replace(new RegExp(`\\b${name}\\b`, "gi"), "") |
| 59 | if (due === null) { |
| 60 | due = nextDay(today, dayIndex).toISOString() |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | const title = text.replace(/\s+/g, " ").trim() |
| 66 | |
| 67 | return { title, tags, priority_id, due } |
| 68 | } |
nothing calls this directly
no outgoing calls
no test coverage detected