28 lines
635 B
TypeScript
28 lines
635 B
TypeScript
|
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);
|
||
|
}
|
||
|
|
||
|
export function safeRun(fn: () => Promise<void>) {
|
||
|
fn().catch((e) => {
|
||
|
console.error(e);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export function sleep(ms: number): Promise<void> {
|
||
|
return new Promise<void>((resolve) => {
|
||
|
setTimeout(() => {
|
||
|
resolve();
|
||
|
}, ms);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export function isMacLike() {
|
||
|
return /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
|
||
|
}
|