2022-02-22 13:18:37 +00:00
|
|
|
export function countWords(str: string): number {
|
|
|
|
var matches = str.match(/[\w\d\'\'-]+/gi);
|
|
|
|
return matches ? matches.length : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function readingTime(wordCount: number): number {
|
|
|
|
// 225 is average word reading speed for adults
|
|
|
|
return Math.ceil(wordCount / 225);
|
|
|
|
}
|
2022-02-24 16:24:49 +00:00
|
|
|
|
|
|
|
export function safeRun(fn: () => Promise<void>) {
|
|
|
|
fn().catch((e) => {
|
|
|
|
console.error(e);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-25 14:34:00 +00:00
|
|
|
export function isMacLike() {
|
|
|
|
return /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
|
|
|
|
}
|