-- This module produces a count of all the arguments passed to it.
local yesno = require('Module:Yesno')
-- Trim a stringlocal function trim(s) return s:match('^%s*(.-)%s*$')end
-- Test whether a string is blanklocal function isBlank(s) return not s:find('%S')end
-- Tests whether a string is a valid positional key, and if so, returns it. If-- the key is invalid, this returns nil.local function isPositionalKey(s) s = trim(s) if s:find('^[1-9][0-9]*$') then return tonumber(s) endend
-- Return the count of all arguments for which testFunc returns a truthy value.local function count(args, testFunc) local ret = 0 for key, val in pairs(args) do if testFunc(key, val) then ret = ret + 1 end end return retend
-- Check shared arguments and get the parent argument count.local function main(frame, testFunc) local blankifiedTestFunc if yesno(frame.args.checkblanks) ~= false then -- Extend the test function to check for blanks as well. blankifiedTestFunc = function (key, val) if not isBlank(val) then return testFunc(key, val) end end else blankifiedTestFunc = testFunc end return count(frame:getParent.args, blankifiedTestFunc)end
return