UNPKG

@cobuildlab/8base-chat

Version:

Chat component that uses 8base

42 lines (35 loc) 1.04 kB
/** * Trims empty lines. * @param text * @param moreThan - specifies when to trim empty lines. * For example, if there are more empty lines in a row than [moreThan] * then it trims */ export function trimEmptyLines(text: string, moreThan: number) { const replacement = new Array(moreThan - 1).fill('\n').join(''); return text.replace(/\n{3,}/g, replacement); } /** * Converts first letter to upper case, e.g. hello -> Hello * @param str */ export function capitalize(str: string) { return str.charAt(0).toUpperCase() + str.slice(1); } /** * Returns all results matching a string against regular expression * @param str * @param regex */ export function matchAll(str: string, regex: RegExp) { const matches: RegExpExecArray[] = []; let match; // tslint:disable-next-line: no-conditional-assignment while ((match = regex.exec(str)) !== null) { matches.push(match); } return matches; } export function hasHttpProtocol(url: string) { return /^https?:\/\//.test(url); }