export class HtmlUtils { public static getElementByIdOrFail(id: string): T { const elem = document.getElementById(id); if (HtmlUtils.isHtmlElement(elem)) { return elem; } throw new Error("Cannot find HTML element with id '"+id+"'"); } public static removeElementByIdOrFail(id: string): T { const elem = document.getElementById(id); if (HtmlUtils.isHtmlElement(elem)) { elem.remove(); return elem; } throw new Error("Cannot find HTML element with id '"+id+"'"); } public static urlify(text: string): string { const urlRegex = /(https?:\/\/[^\s]+)/g; return text.replace(urlRegex, (url: string) => { return '' + url + ''; }) } private static isHtmlElement(elem: HTMLElement | null): elem is T { return elem !== null; } }