diff --git a/Shared/utility.js b/Shared/utility.js index 8771cfe..2f3d81f 100644 --- a/Shared/utility.js +++ b/Shared/utility.js @@ -1,6 +1,25 @@ //initialize the exports exports = module.exports = {}; +//CloneArray +//arg - an array to be copied +exports.CloneArray = function(arg) { + // https://blog.andrewray.me/how-to-clone-a-nested-array-in-javascript/ + let copy; + + if(Array.isArray(arg)) { + copy = arg.slice(0); + for(let i = 0; i < copy.length; i++) { + copy[i] = arrayClone(copy[i]); + } + return copy; + } else if(typeof(arg) === "object") { + throw "Cannot clone array containing an object!"; + } else { + return arg; + } +} + //GetFooterCommands - Gets footer commands for botspam channel commands //commandArray - the array of possible commands to use //excludeCommand (optional) - the command to filter out @@ -18,6 +37,13 @@ exports.GetFooterCommands = function(commandArray, excludeCommand = null) { return returnText; } +//FormatMSS +//s - seconds +exports.FormatMSS = function(s){ + //https://stackoverflow.com/questions/3733227/javascript-seconds-to-minutes-and-seconds + return (s - (s %= 60)) / 60 + (9 < s ? ':' : ':0') + s; +} + //IsAdmin //client - discord.js client //user - discord.js user OR username