`index.ts`
```ts
export function parseMarkdownList(
text: string
): { prefix?: string; content?: string } | undefined {
const { groups } = Array.from(
text.matchAll(/^(?<prefix> *([-*] (\[.] |)|))(?<content>.*)$/g)
).at(0) as any;
return groups && { prefix: groups.prefix, content: groups.content };
}
```
テストコード。
`index.test.ts`
```ts
import { expect, test } from "bun:test";
import { parseMarkdownList } from ".";
test.each([
["hoge", { prefix: "", content: "hoge" }],
["- ", { prefix: "- ", content: "" }],
["- hoge", { prefix: "- ", content: "hoge" }],
["- [ ] hoge", { prefix: "- [ ] ", content: "hoge" }],
["- [x] hoge", { prefix: "- [x] ", content: "hoge" }],
[" hoge", { prefix: " ", content: "hoge" }],
[" - ", { prefix: " - ", content: "" }],
[" - hoge", { prefix: " - ", content: "hoge" }],
[" - [ ] hoge", { prefix: " - [ ] ", content: "hoge" }],
[" - [x] hoge", { prefix: " - [x] ", content: "hoge" }],
["* ", { prefix: "* ", content: "" }],
["* hoge", { prefix: "* ", content: "hoge" }],
["* [ ] hoge", { prefix: "* [ ] ", content: "hoge" }],
["* [x] hoge", { prefix: "* [x] ", content: "hoge" }],
])(
`parseMarkdownList("%s")`,
(text: string, expected: ReturnType<typeof parseMarkdownList>) => {
expect(parseMarkdownList(text)).toEqual(expected);
}
);
```