local checkType = require('libraryUtil').checkTypelocal p =
--Global strings and formslocal defaults =
--Adds a category to the provided category list; sortKey is optionalfunction p.addCategory(catList, name, sortKey) --Check and normalize parameters checkType('addCategory', 1, catList, 'table') checkType('addCategory', 2, name, 'string') name = mw.text.trim(name) checkType('addCategory', 3, sortKey, 'string', true) if #name
nil or #sortKey
--Add category to category list catList[name] = sortKey or trueend
--Removes a category from the provided category listfunction p.removeCategory(catList, name) --Check and normalize parameters checkType('removeCategory', 1, catList, 'table') checkType('removeCategory', 2, name, 'string') name = mw.text.trim(name) if #name
--Remove category from category list catList[name] = nilend
--Converts a category list to a string containing its categories as wikitextfunction p.writeCategoryList(catList, nullify) checkType('removeCategory', 1, catList, 'table') checkType('removeCategory', 2, name, 'boolean', true)
if nullify then return "" end local constructedList = for k, v in pairs(catList) do if (type(k) ~= "string" or ((type(v) ~= "boolean" or v
true) and string.format(defaults.categoryForm, k) or string.format(defaults.keyedCategoryForm, k, v) ) end return table.concat(constructedList)end
return p