Thread viewer for Bluesky
1import DOMPurify from 'dompurify';
2
3export function numberOfDays(days: number): string {
4 return pluralize(days, 'day');
5}
6
7export function pluralize(value: number, word: string, plural?: string) {
8 if (value == 1) {
9 return `1 ${word}`;
10 } else {
11 plural = plural ?? `${word}s`;
12 return `${value} ${plural}`;
13 }
14}
15
16export function sanitizeHTML(html: string): string {
17 return DOMPurify.sanitize(html, {
18 ALLOWED_TAGS: [
19 'a', 'b', 'blockquote', 'br', 'code', 'dd', 'del', 'div', 'dl', 'dt', 'em', 'font',
20 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'li', 'ol', 'p', 'q', 'pre', 's', 'span', 'strong',
21 'sub', 'sup', 'u', 'wbr', '#text'
22 ],
23 ALLOWED_ATTR: [
24 'align', 'alt', 'class', 'clear', 'color', 'dir', 'href', 'lang', 'rel', 'title', 'translate'
25 ]
26 });
27}
28
29export function truncateText(text: string, maxLen: number): string {
30 if (text.length <= maxLen) {
31 return text;
32 } else {
33 return text.slice(0, maxLen - 1) + '…';
34 }
35}