don't hate me, old git is fuck up

This commit is contained in:
Ren Amamiya
2023-02-21 14:58:47 +07:00
commit 672298daf9
103 changed files with 12172 additions and 0 deletions

13
src/utils/getDate.tsx Normal file
View File

@@ -0,0 +1,13 @@
export const daysAgo = (numOfDays, date = new Date()) => {
const daysAgo = new Date(date.getTime());
daysAgo.setDate(date.getDate() - numOfDays);
return daysAgo;
};
export const hoursAgo = (numOfHours, date = new Date()) => {
const hoursAgo = new Date(date.getTime());
hoursAgo.setHours(date.getHours() - numOfHours);
return hoursAgo;
};

12
src/utils/truncate.tsx Normal file
View 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);
};