2022-08-01 09:04:48 +00:00
|
|
|
import {
|
|
|
|
flashNotification,
|
|
|
|
getText,
|
2022-10-10 12:50:21 +00:00
|
|
|
} from "../../syscall/silverbullet-syscall/editor.ts";
|
|
|
|
import { listPages } from "../../syscall/silverbullet-syscall/space.ts";
|
2022-08-01 09:04:48 +00:00
|
|
|
|
|
|
|
function countWords(str: string): number {
|
|
|
|
const matches = str.match(/[\w\d\'-]+/gi);
|
|
|
|
return matches ? matches.length : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function readingTime(wordCount: number): number {
|
|
|
|
// 225 is average word reading speed for adults
|
|
|
|
return Math.ceil(wordCount / 225);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function statsCommand() {
|
|
|
|
const text = await getText();
|
2022-08-01 16:27:50 +00:00
|
|
|
const allPages = await listPages();
|
2022-08-01 09:04:48 +00:00
|
|
|
const wordCount = countWords(text);
|
|
|
|
const time = readingTime(wordCount);
|
2022-08-01 16:27:50 +00:00
|
|
|
await flashNotification(
|
2022-10-12 09:47:13 +00:00
|
|
|
`${wordCount} words; ${time} minutes read; ${allPages.length} total pages in space.`,
|
2022-08-01 16:27:50 +00:00
|
|
|
);
|
2022-08-01 09:04:48 +00:00
|
|
|
}
|