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