/
/
API usage example — demonstrates how to work with the Todo interface programmatically, outside of React components. This is useful for scripts, tests, or server-side code.
Factory function for creating todos with sensible defaults
10 function createTodo(text: string): Todo { 11 return { 12 id: crypto.randomUUID(), 13 text, 14 completed: false, 15 createdAt: Date.now(), 16 }; 17 }
Batch operations — create multiple todos at once
20 function createBatch(texts: string[]): Todo[] { 21 return texts.map(createTodo); 22 }
Filtering utilities — common queries over a todo collection. These pure functions make it easy to compose todo operations.
28 function getCompleted(todos: Todo[]): Todo[] { 29 return todos.filter((t) => t.completed); 30 }