stream-chat-react-native-core
Version:
The official React Native and Expo components for Stream Chat, a service for building chat applications
18 lines (13 loc) • 563 B
text/typescript
// Add dots in between the title if it is too long and then append the remaining last characters.
// Eg: "This is a very long title" => "This is a very long ti...le"
export const getTrimmedAttachmentTitle = (title?: string, maxLength?: number) => {
const maxLengthValue = maxLength || 18;
if (!title) return '';
const ellipsis = '...';
if (title.length <= maxLengthValue) {
return title;
}
const start = title.slice(0, maxLengthValue / 2);
const end = title.slice(title.length - maxLengthValue / 2);
return `${start}${ellipsis}${end}`;
};