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.

feat: formatList numbers the tasks with { numbered: true } #14

OpenAlemTuzlakwants to merge 1 commit intomain fromfeat/numbered-listopened

Showing 4 changed files with 24 additions and 3 deletions (loading 1).

x
0 of 4 viewed, 4 left
14 additions and 2 deletionssrc/format.tsModified
View file
@@ -1,12 +1,24 @@
import type { TaskList } from './tasks.ts'
​
+/** How `formatList` writes the list. */
+export type FormatOptions = {
+ /** Number the tasks 1, 2, 3 in place of bullets. The numbers follow the order of the list. */
+ numbered?: boolean
+}
+​
/**
* The list as Markdown checkboxes, one line for each task.
*
* @example formatList([{ id: 1, title: 'Ship it', done: true, priority: 1 }]) // '- [x] Ship it'
+ * @example formatList([{ id: 1, title: 'Ship it', done: true, priority: 1 }], { numbered: true }) // '1. [x] Ship it'
*/
-export function formatList(list: TaskList): string {
- return list.map((task) => `- [${task.done ? 'x' : ' '}] ${task.title}`).join('\n')
+export function formatList(list: TaskList, options: FormatOptions = {}): string {
+ return list
+ .map((task, index) => {
+ const marker = options.numbered ? `${index + 1}.` : '-'
+ return `${marker} [${task.done ? 'x' : ' '}] ${task.title}`
+ })
+ .join('\n')
​
/** How much of the list is done, as a whole percent. An empty list is 0 percent done. */
1 addition and 1 deletionsrc/index.tsModified
View file
@@ -1,2 +1,2 @@