fix: update prop typo, extract truncate method

This commit is contained in:
Mythie
2023-05-25 18:43:37 +10:00
parent 4a2162478e
commit 748f842115
4 changed files with 22 additions and 9 deletions

View File

@ -0,0 +1,13 @@
/**
* Truncates a title to a given max length substituting the middle with an ellipsis.
*/
export const truncate = (str: string, maxLength: number = 20) => {
if (str.length <= maxLength) {
return str;
}
const startLength = Math.ceil((maxLength - 3) / 2);
const endLength = Math.floor((maxLength - 3) / 2);
return `${str.slice(0, startLength)}...${str.slice(-endLength)}`;
};