Jump to content

Module:If any equal: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
new function ifAnyEqual which will read parent args
yes or no
Line 48: Line 48:
end
end
end
end
return match
return match and 'yes' or 'no'
end
end



Revision as of 12:30, 6 January 2025

require('strict')
local p = {}

p.main = function(frame)
	local check_value = function(value)
		for n, v in pairs(frame.args) do
			if type(n)=='number' and v:lower()==value:lower() then
				return true
			end
		end
	end
	local match = false
	if frame.args.value and frame.args.value~='' then
		match = check_value(frame.args.value)
	elseif frame.args.values and frame.args.values~='' then
		for value in mw.text.gsplit(frame.args.values, "%s*,%s*") do
			if check_value(value) then
				match = true
				break
			end
		end
	end
	return match and 'yes' or 'no'
end

p.ifAnyEqual = function(frame)
	local parent = frame:getParent()
	if not parent.args then
		return nil
	end
	local check_value = function(value)
		for pos, name in pairs(frame.args) do
			if type(pos)=='number' and parent.args[name] and parent.args[name]:lower()==value:lower() then
				return name
			end
		end
	end
	local match = false
	if frame.args.value and frame.args.value~='' then
		match = check_value(frame.args.value)
	elseif frame.args.values and frame.args.values~='' then
		for value in mw.text.gsplit(frame.args.values, "%s*,%s*") do
			local check = check_value(value)
			if check then
				match = check
				break
			end
		end
	end
	return match and 'yes' or 'no'
end

return p