( markdown: string, taskIndex: number, due: string | null )
| 196 | /** Replace, insert, or remove the `due:YYYY-MM-DD` token on the task |
| 197 | * line at `taskIndex`. Pass `null` to clear. */ |
| 198 | export function setTaskDueAtIndex( |
| 199 | markdown: string, |
| 200 | taskIndex: number, |
| 201 | due: string | null |
| 202 | ): string { |
| 203 | return editTaskAtIndex(markdown, taskIndex, (match) => { |
| 204 | const prefix = match[1] |
| 205 | const checkChar = match[2] |
| 206 | const tailWithBracket = match[3] |
| 207 | if (!tailWithBracket.startsWith(']')) return null |
| 208 | const tail = tailWithBracket.slice(1) |
| 209 | const cleaned = tail.replace(DUE_TOKEN_RE, '$1').replace(/\s{2,}/g, ' ') |
| 210 | let nextTail: string |
| 211 | if (due) { |
| 212 | nextTail = `${cleaned.replace(/\s+$/u, '')} due:${due}` |
| 213 | } else { |
| 214 | nextTail = cleaned.replace(/\s+$/u, '') |
| 215 | } |
| 216 | return `${prefix}${checkChar}]${nextTail}` |
| 217 | }) |
| 218 | } |
| 219 | |
| 220 | /** Replace everything after the checkbox on the task line at `taskIndex` with |
| 221 | * `text` (verbatim — the caller owns any `due:`/`!priority` tokens). Used by |
no test coverage detected