Skip to content
Source
Sign inSign up
TanStack/showcase
A read-only demo of every feature
Every page of this repository is open, and nothing can change. Take a guided tour of what TanStack Source does.
Open History to see the last commit

format.ts

16 lines614 Bytes

1import type { TaskList } from './tasks.ts'
2​
3/**
4 * The list as Markdown checkboxes, one line for each task.
5 *
6 * @example formatList([{ id: 1, title: 'Ship it', done: true, priority: 1 }]) // '- [x] Ship it'
7 */
8export function formatList(list: TaskList): string {
9 return list.map((task) => `- [${task.done ? 'x' : ' '}] ${task.title}`).join('\n')
11​
12/** How much of the list is done, as a whole percent. An empty list is 0 percent done. */
13export function progress(list: TaskList): number {
14 if (list.length === 0) return 0
15 return Math.round((list.filter((task) => task.done).length / list.length) * 100)