export const middleEllipsis = (
textContent: string | number,
startLength: number,
endLength: number,
ellipsisStyle: string,
suffixString?: string,
) => {
textContent = String(textContent);
let textContentArr = [];
let suffix = '';
if (suffixString) {
(textContentArr as string[]) = textContent.split(suffixString);
suffix = suffixString + textContentArr[textContentArr.length - 1];
textContent = textContent.replace(`${suffix}`, '');
}
if (startLength + endLength >= textContent.length) {
if (suffixString) {
return `${textContent}${suffix}`;
}
return textContent;
} else {
if (suffixString) {
return `${textContent.slice(0, startLength)}${ellipsisStyle}${textContent.slice(-endLength,)}${suffix}`;
}
return `${textContent.slice(0, startLength)}${ellipsisStyle}${textContent.slice(-endLength)}`;
}
};
export const fileNameEllipsis = (fileName) => middleEllipsis(fileName, 7, 7, '...', '.');
export const phoneEllipsis = (fileName) => middleEllipsis(fileName, 3, 4, '***');
export const emailEllipsis = (fileName) => middleEllipsis(fileName, 1, 1, '***', '@');
export const folderNameEllipsis = (fileName) => middleEllipsis(fileName, 7, 7, '...');