Module:Sandbox/MonkeysHK

local table = require('Module:Table') local checkType = require('Module:LibraryUtil').checkTypeLight local p = {}

function p.existsWithoutWanted(frame) local args = parent and parent.args or frame.args or frame local frame = mw.getCurrentFrame -- PROTECTIONEXPIRY is a magic word that lets us check a page in a roundabout way without marking it as wanted. -- Trick taken from: https://www.mediawiki.org/wiki/Extension_talk:Scribunto/Lua_reference_manual#Avoid_creating_a_wanted_page_link_when_checking_if_page_exist return frame:callParserFunction('PROTECTIONEXPIRY:edit', args.title or args[1]) ~= '' end

p.pageExists = p.existsWithoutWanted

- -- function: allMatched(s: string, t: table) -- -- Attempt to match each pattern in the table/subsequent args, -- then return true if all matches exists - function p.allMatched(s, ...) checkType('allMatched', 1, s, 'string') local t = { ... }	if t[1] == 'table' then t = t[1] end for _, v in ipairs(t) do		if not(s:match(v)) then return false end end return true end

- -- function: anyMatched(s: string, t: table) -- -- Attempt to match each pattern in the table/subsequent args, -- returns true if any match exists - function p.anyMatched(s, ...) checkType('anyMatched', 1, s, 'string') local t = { ... }	if t[1] == 'table' then t = t[1] end for _, v in ipairs(t) do		if s:match(v) then return true end end return false end

- -- function: gsubAll(s: string, t: table) -- -- Apply each pattern and replacements in the table/pairs of subsequent args, -- returns the replaced string - function p.gsubAll(s, ...) checkType('gsubAll', 1, s, 'string') local t = { ... }	if t[1] == 'table' then t = t[1] end return s end

p.gsubMulti = p.gsubAll

return p