Thread viewer for Bluesky
14
fork

Configure Feed

Select the types of activity you want to include in your feed.

extracted some utils to separate files

+58 -56
+5 -56
src/utils.ts
··· 1 - import DOMPurify from 'dompurify'; 2 - import { URLError } from './api/api.js'; 3 - 4 - export class AtURI { 5 - repo: string; 6 - collection: string; 7 - rkey: string; 8 - 9 - constructor(uri: string) { 10 - if (!uri.startsWith('at://')) { 11 - throw new URLError(`Not an at:// URI: ${uri}`); 12 - } 13 - 14 - let parts = uri.split('/'); 15 - 16 - if (parts.length != 5) { 17 - throw new URLError(`Invalid at:// URI: ${uri}`); 18 - } 19 - 20 - this.repo = parts[2]; 21 - this.collection = parts[3]; 22 - this.rkey = parts[4]; 23 - } 24 - } 1 + export * from './utils/at_uri.js'; 2 + export * from './utils/text.js'; 25 3 26 4 export function $id<T>(name: string, type?: new (...args: any[]) => T): T { 27 5 return document.getElementById(name) as T; 28 - } 29 - 30 - export function atURI(uri: string): AtURI { 31 - return new AtURI(uri); 32 6 } 33 7 34 8 export function castToInt(value: any): number | null | undefined { ··· 54 28 } 55 29 } 56 30 57 - export function numberOfDays(days: number): string { 58 - return (days == 1) ? '1 day' : `${days} days`; 59 - } 60 - 61 - export function sanitizeHTML(html: string): string { 62 - return DOMPurify.sanitize(html, { 63 - ALLOWED_TAGS: [ 64 - 'a', 'b', 'blockquote', 'br', 'code', 'dd', 'del', 'div', 'dl', 'dt', 'em', 'font', 65 - 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'li', 'ol', 'p', 'q', 'pre', 's', 'span', 'strong', 66 - 'sub', 'sup', 'u', 'wbr', '#text' 67 - ], 68 - ALLOWED_ATTR: [ 69 - 'align', 'alt', 'class', 'clear', 'color', 'dir', 'href', 'lang', 'rel', 'title', 'translate' 70 - ] 71 - }); 72 - } 73 - 74 - export function showError(error: Error) { 75 - console.log(error); 76 - alert(error); 77 - } 78 - 79 31 export function sameDay(date1: Date, date2: Date): boolean { 80 32 return ( 81 33 date1.getDate() == date2.getDate() && ··· 84 36 ); 85 37 } 86 38 87 - export function truncateText(text: string, maxLen: number): string { 88 - if (text.length <= maxLen) { 89 - return text; 90 - } else { 91 - return text.slice(0, maxLen - 1) + '…'; 92 - } 39 + export function showError(error: Error) { 40 + console.log(error); 41 + alert(error); 93 42 }
+27
src/utils/at_uri.ts
··· 1 + import { URLError } from '../api/api.js'; 2 + 3 + export class AtURI { 4 + repo: string; 5 + collection: string; 6 + rkey: string; 7 + 8 + constructor(uri: string) { 9 + if (!uri.startsWith('at://')) { 10 + throw new URLError(`Not an at:// URI: ${uri}`); 11 + } 12 + 13 + let parts = uri.split('/'); 14 + 15 + if (parts.length != 5) { 16 + throw new URLError(`Invalid at:// URI: ${uri}`); 17 + } 18 + 19 + this.repo = parts[2]; 20 + this.collection = parts[3]; 21 + this.rkey = parts[4]; 22 + } 23 + } 24 + 25 + export function atURI(uri: string): AtURI { 26 + return new AtURI(uri); 27 + }
+26
src/utils/text.ts
··· 1 + import DOMPurify from 'dompurify'; 2 + 3 + export function numberOfDays(days: number): string { 4 + return (days == 1) ? '1 day' : `${days} days`; 5 + } 6 + 7 + export function sanitizeHTML(html: string): string { 8 + return DOMPurify.sanitize(html, { 9 + ALLOWED_TAGS: [ 10 + 'a', 'b', 'blockquote', 'br', 'code', 'dd', 'del', 'div', 'dl', 'dt', 'em', 'font', 11 + 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'li', 'ol', 'p', 'q', 'pre', 's', 'span', 'strong', 12 + 'sub', 'sup', 'u', 'wbr', '#text' 13 + ], 14 + ALLOWED_ATTR: [ 15 + 'align', 'alt', 'class', 'clear', 'color', 'dir', 'href', 'lang', 'rel', 'title', 'translate' 16 + ] 17 + }); 18 + } 19 + 20 + export function truncateText(text: string, maxLen: number): string { 21 + if (text.length <= maxLen) { 22 + return text; 23 + } else { 24 + return text.slice(0, maxLen - 1) + '…'; 25 + } 26 + }