Jump to content

Module:Yesno/sandbox

From Wikipedia, the free encyclopedia
--- Function allowing for consistent treatment of boolean-like wikitext input.-- It works similarly to the template {{tl|yesno}}.---- @module yesno-- @alias yn-- @param {string} val Value to test-- @param {boolean} default Default boolean to return-- @return true for "yes", "on", etc.; false for "no", "off", etc.; the default-- value if not specified, and nil if the default parameter is not -- specified-- @release stablereturnfunction(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'andval:lower()orvalifval==nilthenreturnnilelseifval==trueorval=='yes'orval=='y'orval=='true'orval=='t'orval=='on'ortonumber(val)==1thenreturntrueelseifval==falseorval=='no'orval=='n'orval=='false'orval=='f'orval=='off'ortonumber(val)==0thenreturnfalseelse-- not specified, return defaultreturndefaultendend
close