Module:Yesno
Revision as of 11:48, 19 August 2020 by classes>Louis Alarcon (1 revision imported)
Documentation for this module may be created at Module:Yesno/doc
1 -- Function allowing for consistent treatment of boolean-like wikitext input.
2 -- It works similarly to the template {{yesno}}.
3
4 return function (val, default)
5 -- If your wiki uses non-ascii characters for any of "yes", "no", etc., you
6 -- should replace "val:lower()" with "mw.ustring.lower(val)" in the
7 -- following line.
8 val = type(val) == 'string' and val:lower() or val
9 if val == nil then
10 return nil
11 elseif val == true
12 or val == 'yes'
13 or val == 'y'
14 or val == 'true'
15 or val == 't'
16 or val == 'on'
17 or tonumber(val) == 1
18 then
19 return true
20 elseif val == false
21 or val == 'no'
22 or val == 'n'
23 or val == 'false'
24 or val == 'f'
25 or val == 'off'
26 or tonumber(val) == 0
27 then
28 return false
29 else
30 return default
31 end
32 end