Module:yesno
Appearance
- The following documentation is located at Module:yesno/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module returns a function that will convert various values to false
or true
. It can be used to interpret boolean template parameters, if Module:parameters is not being used.
-- Function allowing for consistent treatment of boolean-like wikitext input.
-- It works similarly to the template {{yesno}}.
local lower = string.lower
local type = type
local yesno = {
[true] = true, [false] = false,
["true"] = true, ["false"] = false,
["t"] = true, ["f"] = false,
[1] = true, [0] = false,
["1"] = true, ["0"] = false,
["yes"] = true, ["no"] = false,
["y"] = true, ["n"] = false,
["on"] = true, ["off"] = false,
}
return function (val, default)
if val == nil then
return nil
end
local ret = yesno[val]
if ret ~= nil then
return ret
elseif type(val) == "string" then
ret = yesno[lower(val)]
if ret ~= nil then
return ret
end
end
return default
end