Module:Utils

-- local getArgs = require('Dev:Arguments').getArgs local language = mw.language.getContentLanguage

return { make_wrapper_function = function(func) return function(frame) return func(getArgs(frame)) end end;

-- This function is meant to be called with the names of the namespaces that pages can be categorized in. -- It will return a function to be used to categorize pages, which accepts any number of category names. categorize = function(...) local namespaces = {...} return function(...) local result = '' if mw.title.getCurrentTitle:inNamespaces(unpack(namespaces)) then for _, category in next, {...} do result = result .. ""				end end return result end end;

trim_positional_arguments = function(args) local positional_arguments = {} local argn = 1 local positional_argument = args[argn] while positional_argument do			table.insert(positional_arguments, mw.text.trim(positional_argument)) argn = argn + 1 positional_argument = args[argn] end return positional_arguments end;

array_to_set = function(array) local set = {}

for _, value in next, array do			set[value] = true end

return set end;

parse_number = function(num, error_if_invalid) if type(num) == 'number' then return num elseif type(num) == 'string' then local number = tonumber(language:parseFormattedNumber(num)) if number then return number elseif error_if_invalid then return error(num .. " is not a valid number") end elseif error_if_invalid then return error(tostring(num) .. " is not a valid number") end end;

format_number = function(number) return language:formatNum(number) end; }