mirror of
https://github.com/TheNetsky/Microsoft-Rewards-Script.git
synced 2026-01-17 21:43:59 +00:00
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
export default class Util {
|
|
|
|
async wait(ms: number): Promise<void> {
|
|
return new Promise<void>((resolve) => {
|
|
setTimeout(resolve, ms)
|
|
})
|
|
}
|
|
|
|
getFormattedDate(ms = Date.now()): string {
|
|
const today = new Date(ms)
|
|
const month = String(today.getMonth() + 1).padStart(2, '0') // January is 0
|
|
const day = String(today.getDate()).padStart(2, '0')
|
|
const year = today.getFullYear()
|
|
|
|
return `${month}/${day}/${year}`
|
|
}
|
|
|
|
shuffleArray<T>(array: T[]): T[] {
|
|
const shuffledArray = array.slice()
|
|
|
|
shuffledArray.sort(() => Math.random() - 0.5)
|
|
|
|
return shuffledArray
|
|
}
|
|
|
|
randomNumber(min: number, max: number): number {
|
|
return Math.floor(Math.random() * (max - min + 1)) + min
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
} |