Module:Sandbox/Nihiltres/Category manager/doc

This module implements a simple tool for managing category output in modules.

Usage
The module cannot be used from wikitext. It can be imported to another module using code similar to the following:

Category-list table format
Each function in the module takes a table as its first parameter, and that table is used as the list of categories. These tables are assumed to only be manipulated by this module's functions, but there is no protection against external manipulation; there's just basic type/value validation. Each item in a category-list table has its category name (without prefix) as its key; duplicate categories are therefore impossible. Values for each key can either be  (no sort key) or a string containing that sort key. A  value or any other type of value will cause errors. There are three functions for manipulating a category list table, and their individual documentation follows.

addCategory
Usage:

The  function adds a category by setting the key from   in the   table to either   or the provided   value if present.

If an existing category is added a second time, its value will be overwritten with the new value; for this reason the module does not include a separate function for setting sort keys.

The  parameter must be a table, the   parameter must be a non-empty, non-whitespace string, and   must be either a string or nil.

removeCategory
Usage:

The  function removes a category by setting the key from   to nil in the   table.

The  parameter must be a table, and the   parameter must be a non-empty, non-whitespace string.

writeCategoryList
Usage:

The  function produces a string containing all the categories in the table formatted as wikitext. Optionally, a boolean  parameter may be provided, and if true, it will cause the function to output an empty string. This is useful as it makes it easy to disable category output through a parameter, probably in conjunction with Module:Yesno.

The  parameter must be a table formatted according to the category-list table format, and the   parameter must be either a boolean or nil.