Module:ControllerUtilities
From Against the Storm Official Wiki
Documentation for this module may be created at Module:ControllerUtilities/doc
--- --- Centralizes some common functionality across controllers --- ---@module ControllerUtilities ControllerUtilities = {} --region Public Constants --endregion --region Private Constants local PATTERN_EVERYTHING_BETWEEN_COMMAS_AND_SPACES = "[^%s,][^,]+[^%s,]" --endregion --region Public methods ---expandIDList ---@param commaSeparatedStringOfIDs string the list of ids, separated by commas ---@param needsKeyValueFlags boolean true if the list should be made of keys and values of true, false if the list should be an array ---@return table the ids now as a table function ControllerUtilities.expandCommaSeparatedStringsIntoTable(commaSeparatedStringOfIDs, needsKeyValueFlags) local list = {} for eachID in string.gmatch(commaSeparatedStringOfIDs, PATTERN_EVERYTHING_BETWEEN_COMMAS_AND_SPACES) do if needsKeyValueFlags then list[eachID] = true else table.insert(list, eachID) end end return list end --endregion return ControllerUtilities