This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
outline/shared/utils/getTasks.js
2021-07-27 11:31:27 +05:30

22 lines
482 B
JavaScript

// @flow
const CHECKBOX_REGEX = /\[(X|\s|_|-)\]\s(.*)?/gi;
export default function getTasks(text: string) {
const matches = [...text.matchAll(CHECKBOX_REGEX)];
let total = matches.length;
if (!total) {
return {
completed: 0,
total: 0,
};
} else {
const notCompleted = matches.reduce(
(accumulator, match) =>
match[1] === " " ? accumulator + 1 : accumulator,
0
);
return { completed: total - notCompleted, total };
}
}