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
return function (val, default)
if val == nil then
return nil
elseif not yesno then
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,
}
end
local ret = yesno[val]
if ret ~= nil then
return ret
elseif type(val) ~= "string" then
return default
end
ret = yesno[lower(val)]
if ret ~= nil then
return ret
end
return default
end