mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 01:01:49 +10:00
fix: update prop typo, extract truncate method
This commit is contained in:
13
packages/lib/helpers/strings.ts
Normal file
13
packages/lib/helpers/strings.ts
Normal 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)}`;
|
||||
};
|
||||
Reference in New Issue
Block a user