don't hate me, old git is fuck up
This commit is contained in:
12
src/utils/truncate.tsx
Normal file
12
src/utils/truncate.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
export const truncate = (fullStr: string, strLen: number, separator: string | unknown[]) => {
|
||||
if (fullStr.length <= strLen) return fullStr;
|
||||
|
||||
separator = separator || '...';
|
||||
|
||||
const sepLen = separator.length,
|
||||
charsToShow = strLen - sepLen,
|
||||
frontChars = Math.ceil(charsToShow / 2),
|
||||
backChars = Math.floor(charsToShow / 2);
|
||||
|
||||
return fullStr.substr(0, frontChars) + separator + fullStr.substr(fullStr.length - backChars);
|
||||
};
|
||||
Reference in New Issue
Block a user