Changes

Jump to navigation Jump to search
371 bytes added ,  11:48, 26 March 2021
m
1 revision imported
Line 1: Line 1: −
{{<includeonly>safesubst:</includeonly>#switch: {{<includeonly>safesubst:</includeonly>lc: {{{1|¬}}} }}
+
-- Function allowing for consistent treatment of boolean-like wikitext input.
|no
+
-- It works similarly to the template {{yesno}}.
|n
+
 
|f
+
return function (val, default)
|false
+
-- If your wiki uses non-ascii characters for any of "yes", "no", etc., you
|off
+
-- should replace "val:lower()" with "mw.ustring.lower(val)" in the
|0        = {{{no|<!-- null -->}}}
+
-- following line.
|        = {{{blank|{{{no|<!-- null -->}}}}}}
+
val = type(val) == 'string' and val:lower() or val
|¬        = {{{¬|}}}
+
if val == nil then
|yes
+
return nil
|y
+
elseif val == true
|t
+
or val == 'yes'
|true
+
or val == 'y'
|on
+
or val == 'true'
|1        = {{{yes|yes}}}
+
or val == 't'
|#default = {{{def|{{{yes|yes}}}}}}
+
or val == 'on'
}}<noinclude>
+
or tonumber(val) == 1
{{Documentation}}
+
then
</noinclude>
+
return true
 +
elseif val == false
 +
or val == 'no'
 +
or val == 'n'
 +
or val == 'false'
 +
or val == 'f'
 +
or val == 'off'
 +
or tonumber(val) == 0
 +
then
 +
return false
 +
else
 +
return default
 +
end
 +
end

Navigation menu