模組:Yesno
外观
-- 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 booleans = {
[true] = true, [false] = false,
["true"] = true, ["false"] = false,
[1] = true, [0] = false,
["1"] = true, ["0"] = false,
["yes"] = true, ["no"] = false,
["y"] = true, ["n"] = false,
["t"] = true, ["f"] = false,
["on"] = true, ["off"] = false,
["是"] = true, ["否"] = false,
}
return function (val, default)
if val == nil then
return nil
elseif type(val) == "string" then
val = lower(val)
end
if booleans[val] ~= nil then
return booleans[val]
end
return default
end