Module:Truncate

From Soyjak Wiki, the free ensoyclopedia
Jump to navigationJump to search

local p = {}

function p.truncate(frame)
    local text = frame.args[1] or "" 
    local length = tonumber(frame.args[2])

    if not length or length <= 0 then
        return ""
    end

    if #text > length then
        return string.sub(text, 1, length)
    else
        return text
    end
end

return p