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 tonumber(val) == 1
  17. then
  18. return true
  19. elseif val == false
  20. or val == 'no'
  21. or val == 'n'
  22. or val == 'false'
  23. or val == 'f'
  24. or tonumber(val) == 0
  25. then
  26. return false
  27. else
  28. return default
  29. end
  30. end

-- Function allowing for consistent treatment of boolean-like wikitext input. -- It works similarly to the template .

return function (val, default) -- If your wiki uses non-ascii characters for any of "yes", "no", etc., you -- should replace "val:lower()" with "mw.ustring.lower(val)" in the -- following line. val = type(val) == 'string' and val:lower() or val if val == nil then return nil elseif val == true or val == 'yes' or val == 'y' or val == 'true' or val == 't' or tonumber(val) == 1 then return true elseif val == false or val == 'no' or val == 'n' or val == 'false' or val == 'f' or tonumber(val) == 0 then return false else return default end end