Documentation for this module may be created at Module:StringFunctions/doc

local p = {}
local getArgs = require("Dev:Arguments").getArgs

function p.join(frame)
    local args = getArgs(frame, {removeBlanks = false})
    local sep = args.sep or ", "
    local parts = {}

    for _, part in ipairs(args) do
        if part ~= "" then
            table.insert(parts, part)
        end
    end

    if #parts == 0 then
        return args.default
    end

    return mw.text.listToText(parts, sep, args["last-sep"] or sep)
end

function p.parameterize(frame)
    local args = getArgs(frame)
    local tmp = args[0]

    for argName in pairs(args) do
        tmp = tmp:gsub("{" .. argName .. "}", "{{{" .. argName .. "}}}")
    end

    return frame:preprocess(tmp)
end

return p
Community content is available under CC-BY-SA unless otherwise noted.