export class StringHelper { public static toSlug(str: string | null): string | null { if (!str) { return str; } return str .trim() .toLowerCase() .replace(/\s+/g, '-') .replace(/[^\w\-]+/g, '') .replace(/\-\-+/g, '-') .replace(/^-+/, '') .replace(/-+$/, ''); } public static toTitlecase(str: string | null): string | null { if (!str) { return str; } return str.replace( /\w\S*/g, (substring: string) => substring.charAt(0).toUpperCase() + substring.substring(1).toLowerCase() ); } }