This commit is contained in:
TheNetsky
2023-10-14 17:01:13 +02:00
parent b341f7e339
commit e315abba3f
12 changed files with 167 additions and 71 deletions

View File

@@ -7,17 +7,17 @@ export function log(title: string, message: string, type?: 'log' | 'warn' | 'err
switch (type) {
case 'warn':
str = `[${currentTime}] [WARN] [${title}] ${message}`
str = `[${currentTime}] [PID: ${process.pid}] [WARN] [${title}] ${message}`
console.warn(str)
break
case 'error':
str = `[${currentTime}] [ERROR] [${title}] ${message}`
str = `[${currentTime}] [PID: ${process.pid}] [ERROR] [${title}] ${message}`
console.error(str)
break
default:
str = `[${currentTime}] [LOG] [${title}] ${message}`
str = `[${currentTime}] [PID: ${process.pid}] [LOG] [${title}] ${message}`
console.log(str)
break
}

View File

@@ -13,8 +13,7 @@ export function getFormattedDate(ms = Date.now()) {
return `${month}/${day}/${year}`
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function shuffleArray(array: any[]): any[] {
export function shuffleArray<T>(array: T[]): T[] {
const shuffledArray = array.slice()
shuffledArray.sort(() => Math.random() - 0.5)
@@ -24,4 +23,16 @@ export function shuffleArray(array: any[]): any[] {
export function randomNumber(min: number, max: number) {
return Math.floor(Math.random() * (max - min + 1)) + min
}
export function chunkArray<T>(arr: T[], numChunks: number): T[][] {
const chunkSize = Math.ceil(arr.length / numChunks)
const chunks: T[][] = []
for (let i = 0; i < arr.length; i += chunkSize) {
const chunk = arr.slice(i, i + chunkSize)
chunks.push(chunk)
}
return chunks
}