Module:Utils: Difference between revisions

ArrowHead294 (talk | contribs)
mNo edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local get_args = require("Module:Arguments").getArgs
local get_args = require("Module:Arguments").getArgs
local p = {}
local yesno = require("Module:Yesno")


-- Trim a string (remove leading and trailing, but not interior, whitespace)
-- Trim a string (remove leading and trailing, but not interior, whitespace)
function p.trim(s)
function p.trim(s)
   return s:match("^%s*(.-)%s*$")
   return s:match("^%s*(.-)%s*$")
end
-- Wrapper function for template access to [[Module:Yesno]]
function p._yesno(frame)
return yesno(frame.args["input"], frame.args["default"])
end
end


Line 30: Line 37:
function p.value_provided(s)
function p.value_provided(s)
return type(s) == "string" and #s > 0
return type(s) == "string" and #s > 0
end
-- Return a link to Wikipedia in Wiki markup
function p.wlink(a, b)
return string.format("[[wikipedia:%s|%s]]",
a,
((b == nil or p.trim(b) == "") and a or b)
)
end
end