MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / setTaskDueAtIndex

Function setTaskDueAtIndex

packages/shared-domain/src/tasklists.ts:198–218  ·  view source on GitHub ↗
(
  markdown: string,
  taskIndex: number,
  due: string | null
)

Source from the content-addressed store, hash-verified

196/** Replace, insert, or remove the `due:YYYY-MM-DD` token on the task
197 * line at `taskIndex`. Pass `null` to clear. */
198export 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

Callers 2

store.tsFile · 0.90
tasklists.test.tsFile · 0.90

Calls 1

editTaskAtIndexFunction · 0.85

Tested by

no test coverage detected