mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 09:12:02 +10:00
14 lines
415 B
TypeScript
14 lines
415 B
TypeScript
/**
|
|
* 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)}`;
|
|
};
|