-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
21 lines (19 loc) · 760 Bytes
/
utils.ts
File metadata and controls
21 lines (19 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export const generateId = (): string => {
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
};
export const formatDate = (timestamp: number): string => {
if (!timestamp) return '';
const date = new Date(timestamp);
const day = date.getDate().toString().padStart(2, '0');
const month = date.toLocaleDateString('en-US', { month: 'short' }).toUpperCase();
const year = date.getFullYear();
return `${day}-${month}-${year}`;
};
export const shuffleArray = <T,>(array: T[]): T[] => {
const newArray = [...array];
for (let i = newArray.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[newArray[i], newArray[j]] = [newArray[j], newArray[i]];
}
return newArray;
};