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

Function parseNoteDefaults

packages/shared-domain/src/tasks.ts:109–132  ·  view source on GitHub ↗

Extract just the three keys we care about. Unparseable lines are ignored.

(body: string)

Source from the content-addressed store, hash-verified

107
108/** Extract just the three keys we care about. Unparseable lines are ignored. */
109function parseNoteDefaults(body: string): { defaults: NoteDefaults; fmEndOffset: number } {
110 const m = body.match(FRONTMATTER_RE)
111 if (!m) return { defaults: {}, fmEndOffset: 0 }
112 const block = m[1]
113 const defaults: NoteDefaults = {}
114 for (const rawLine of block.split('\n')) {
115 const line = rawLine.trim()
116 if (!line || line.startsWith('#')) continue
117 const colon = line.indexOf(':')
118 if (colon < 1) continue
119 const key = line.slice(0, colon).trim().toLowerCase()
120 const value = unquote(line.slice(colon + 1))
121 if (key === 'due') {
122 const d = normalizeDueDate(value)
123 if (d) defaults.due = d
124 } else if (key === 'priority') {
125 const p = normalizePriority(value)
126 if (p) defaults.priority = p
127 } else if (key === 'status') {
128 defaults.status = value.toLowerCase()
129 }
130 }
131 return { defaults, fmEndOffset: m[0].length }
132}
133
134// ---------------------------------------------------------------------------
135// Inline token extraction

Callers 1

parseTasksFromBodyFunction · 0.70

Calls 3

unquoteFunction · 0.70
normalizeDueDateFunction · 0.70
normalizePriorityFunction · 0.70

Tested by

no test coverage detected