Module:Road data/parser/hooks/doc

This module includes hook functions that provide extra functionality to Module:Road data/parser and its associated string modules.

Basics
Each hook is simply a function stored in the  package table exported by this module. Each function accepts two arguments:
 * : The table in the string module that references the hook. In this example, this argument would be the table stored in the  field of the type table (from Module:Road data/strings/USA/KY):
 * : The arguments originally passed to the parser.

Hooks may modify the argument table by simply setting a new key as equal to a computed value. Modifying existing values is allowed, but discouraged.

The return value of a hook is an ordinary format string, which may be computed within the function or pulled from the  argument. Generally, if the hook does not compute the format string to be returned, the hook should return, which should equal a format string.

This hook determines the format string to be used by the parser based on whether the route number is above or below a particular number.

Parameters:
 * : The number on which to split.
 * : The format string to use if the route number is below.
 * : The format string to use if the route number is equal to or above.

This hook operates in a similar fashion to, but tests the length of the route number instead of its value.

Parameters:
 * : The length on which to split.
 * : The format string to use if the route number's length is below.
 * : The format string to use if the route number's length is equal to or above.

This hook determines the format string to be used by the parser based on whether the route number is between two given numbers.

Parameters:
 * : The lower limit of the test (inclusive).
 * : The upper limit of the test (exclusive).
 * : The format string to use if the route number is between  and.
 * : The format string to use if the route number is not between  and.

This hook adds an argument to the  table based on the result of applying a supplied mask to a particular argument.

Parameters:
 * : The argument to be masked.
 * : The key used to store the mask result in the  table.
 * : The name of the module to be used as a mask, without the "Module:" prefix. The module must return a table which maps a  argument to the value stored in the   field of.
 * : The format string to be processed by the parser. This string may reference the argument stored in  by this hook.

This hook zero-pads the route number so that the route number has a particular number of digits.

Parameters:
 * : The length to which the route number should be zero-padded.
 * : The format string to be processed by the parser. This string may reference the zero-padded route number as the  argument.

This hook is similar to running an to match the title of an article to a specified value in order to display certain content. Particularly useful for images with Fair-use rationales.

Parameters:
 * : The title against which the page name is compared.
 * : The result if article and the page name match.
 * : The result if article and the page name do not match. Defaults to  if not specified.

This hook converts the route "number" to lowercase.

Parameters:
 * : The format string to be processed by the parser. This string may reference the lowercased route number as the  argument.

This hook determines whether a particular argument starts with any of the given patterns, and returns the value associated with the matching pattern.

Parameters:
 * : The argument to test.
 * : Key-value pairs of starting patterns and the values to return if a match is found.
 * : The value to return if no match is found.