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

Function setTaskWaitingAtIndex

packages/shared-domain/src/tasklists.ts:141–164  ·  view source on GitHub ↗
(
  markdown: string,
  taskIndex: number,
  waiting: boolean
)

Source from the content-addressed store, hash-verified

139 * separating space; removing collapses any extra whitespace it left
140 * behind so the line stays tidy. */
141export function setTaskWaitingAtIndex(
142 markdown: string,
143 taskIndex: number,
144 waiting: boolean
145): string {
146 return editTaskAtIndex(markdown, taskIndex, (match) => {
147 const prefix = match[1]
148 const checkChar = match[2]
149 const tailWithBracket = match[3]
150 if (!tailWithBracket.startsWith(']')) return null
151 const tail = tailWithBracket.slice(1)
152 const has = WAITING_TOKEN_RE.test(tail)
153 let nextTail = tail
154 if (waiting && !has) {
155 nextTail = `${tail.replace(/\s+$/u, '')} @waiting`
156 } else if (!waiting && has) {
157 nextTail = tail
158 .replace(WAITING_TOKEN_RE, '$1')
159 .replace(/\s{2,}/g, ' ')
160 .replace(/\s+$/u, '')
161 }
162 return `${prefix}${checkChar}]${nextTail}`
163 })
164}
165
166const PRIORITY_TOKEN_RE = /(^|\s)!(?:high|med|medium|low|h|m|l)\b/i
167const DUE_TOKEN_RE = /(^|\s)due:\S+/i

Callers 2

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

Calls 1

editTaskAtIndexFunction · 0.85

Tested by

no test coverage detected