Модуль:Yesno: различия между версиями

Материал из Викимультии — энциклопедии мультипликации
Перейти к навигации Перейти к поиску
[непроверенная версия][отпатрулированная версия]
Нет описания правки
 
Нет описания правки
 
Строка 1: Строка 1:
-- Used to evaluate args to booleans where applicable
-- Function allowing for consistent treatment of boolean-like wikitext input.
-- Based on <https://en.wikipedia.org/wiki/Module:Yesno>
-- It works similarly to the template {{yesno}}.
-- see page history there for contributors
 
return function (val, default)
return function( arg, default )
-- If your wiki uses non-ascii characters for any of "yes", "no", etc., you
    arg = type( arg ) == 'string' and mw.ustring.lower( arg ) or arg
-- should replace "val:lower()" with "mw.ustring.lower(val)" in the
-- following line.
    if arg == nil or arg == false then
val = type(val) == 'string' and val:lower() or val
        return nil
if val == nil then
    end
return nil
elseif val == true
    if
or val == 'yes'
        arg == 'yes' or
or val == 'y'
        arg == 'y' or
or val == 'true'
         arg == 'true' or
or val == 't'
        tonumber( arg ) == 1
or val == 'да'
    then
or val == 'д'
        return true
         or val == '+'
    end
or tonumber(val) == 1
then
    if
return true
        arg == 'no' or
elseif val == false
        arg == 'n' or
or val == 'no'
        arg == 'false' or
or val == 'n'
        arg == '' or
or val == 'false'
        tonumber( arg ) == 0
or val == 'f'
    then
or val == 'нет'
        return false
or val == 'н'
    end
or val == '-'
or tonumber(val) == 0
    return true
then
return false
else
return default
end
end
end
--[[Категория:Модули]]

Текущая версия от 12:16, 7 августа 2019


Документация
-- Function allowing for consistent treatment of boolean-like wikitext input.
-- It works similarly to the template {{yesno}}.

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 val == 'да'
		or val == 'д'
        or val == '+'
		or tonumber(val) == 1
	then
		return true
	elseif val == false
		or val == 'no'
		or val == 'n'
		or val == 'false'
		or val == 'f'
		or val == 'нет'
		or val == 'н'
		or val == '-'
		or tonumber(val) == 0
	then
		return false
	else
		return default
	end
end