From 1046e6135cb727a099b2149ce2d603af8bf71d10 Mon Sep 17 00:00:00 2001 From: deicidus <> Date: Sun, 31 Jul 2022 23:20:18 -0700 Subject: [PATCH] Renamed to remove superfluous s in filename --- utils.ts => util.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) rename utils.ts => util.js (65%) diff --git a/utils.ts b/util.js similarity index 65% rename from utils.ts rename to util.js index 0e1c471..0b613af 100644 --- a/utils.ts +++ b/util.js @@ -1,3 +1,5 @@ +// General helper functions + export const cancelablePromise = promise => { let isCanceled = false @@ -13,13 +15,12 @@ export const cancelablePromise = promise => { cancel: () => (isCanceled = true), } } + export const noop = () => {} -export const delay = n => new Promise(resolve => setTimeout(resolve, n)) +export const delay = (n = 550) => new Promise(resolve => setTimeout(resolve, n)) -export const isObject = obj => { - return Object.prototype.toString.call(obj) === '[object Object]' -} +export const isObject = obj => Object.prototype.toString.call(obj) === '[object Object]' export const convertToDuration = (milliseconds: number) => { const stringifyTime = (time: number): string => String(time).padStart(2, '0') @@ -42,3 +43,15 @@ export const convertToTimeWorked = (milliseconds: number) => { return `${minutes % 60}m` } } + + // Returns a random int between min and max (inclusive) +export function randomInt(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min + 1)) + min; +} + +// Returns a random item from the given array +export function selectRandom(arrayToChooseFrom) { + return arrayToChooseFrom[randomInt(0, arrayToChooseFrom.length - 1)] +}