2024-10-06 16:30:18 -04:00
|
|
|
/**
|
|
|
|
* Capitalize the first letter of
|
|
|
|
* each word in the given string.
|
|
|
|
*
|
|
|
|
* @param str the string to capitalize
|
|
|
|
* @return the capitalized string
|
|
|
|
*/
|
|
|
|
export const capitalizeWords = (str: string | undefined): string | undefined =>
|
|
|
|
str &&
|
|
|
|
str.toLowerCase().replace(/\b\w/g, (char: string) => char.toUpperCase());
|
2024-10-06 20:35:01 -04:00
|
|
|
|
|
|
|
export const truncateText = (
|
|
|
|
text: string | undefined,
|
|
|
|
maxLength: number
|
|
|
|
): string | undefined =>
|
|
|
|
text && text.length > maxLength
|
|
|
|
? text.slice(0, maxLength - 3).trim() + "..."
|
|
|
|
: text;
|