Module:Feature/doc
Cached copy of the original page · revision 1384978 · refresh
This is the documentation page for Feature. It contains usage information, categories, and other content not part of the original module page. | |||
|---|---|---|---|
| Main | Documentation | Sandbox | Usage |
Documentation
Package items
lib.ternary(cond, T, F)(function)Choose one of two values to return.
- Parameters:
(boolean)
condDetermines which value to return.TThe value to return ifcondis true (or truthy).FThe value to return ifcondis false (or falsey).
mw.text replacements
Some functions from mw.text are slow or may not always work as intended. This group of functions provides better alternatives for them.
lib.trim(text)(function)
lib.gsplit()(function)
lib.split(text, [delim], [opt])(function)Returns a table containing the substrings of
textthat are separated bydelim. (Compared tomw.text.split, this function always treatsdelimas a literal string rather than a pattern, and it trims output substrings usinglib.trimby default.)- Parameters:
(string)
textThe string to split.(string; optional)
delimThe delimiter string to use when splittingtext. (Using an empty string will splittextinto individual characters.)
- Returns:
(table)
Substrings of
text separated bydelim`.
lib.unstripNoWiki()(function)A wrapper around
mw.text.unstripNoWikithat un-escapes- See also:
lib.spairs(tbl, [order])(function)Returns an iterator over
tblthat outputs items in the order defined byorder.- Parameters:
(table)
tblThe table to iterate over.(table or function; optional)
orderThe iteration order.Can be specified either as an ordered list (table) of keys from
tblor as an ordering function that acceptstbl,keyA, andkeyBand returns true when the entry intblassociated witykeyAshould come before the one forkeyB.If not specified, the keys' natural ordering is used (i.e.,
function(tbl, a, b) return a < b end).
- Returns:
(function)
The iterator.
lib.parseTemplateFormat(input, [key_separator], [end_separator], [equal_separator])(function)Parses Phantom Template Format strings into a list of maps.
- Parameters:
(string)
inputA string formed by concatenating the output of Phantom Templates. Usually, this string is generated by DPL.(string; optional)
key_separatorSeparator between the entries (key-value pairs) of items ininput. Defaults to ';'.(string; optional)
end_separatorSeparator between items ininput. Defaults to '$'.(string; optional)
equal_separatorSeparator between the key and value of each entry ininput. Defaults to '='.
- Returns:
(table)
A list of items from
input; each value is a map of the item's entries.
lib.parseTemplateFormatOrdered(input, [key_separator], [end_separator], [equal_separator])(function)Parses Phantom Template Format strings into a list of ordered maps.
- Parameters:
(string)
inputA string formed by concatenating the output of Phantom Templates. Usually, this string is generated by DPL.(string; optional)
key_separatorSeparator between the entries (key-value pairs) of items ininput. Defaults to ';'.(string; optional)
end_separatorSeparator between items ininput. Defaults to '$'.(string; optional)
equal_separatorSeparator between the key and value of each entry ininput. Defaults to '='.
- Returns:
lib.thousandsSeparator(n)(function)Add thousands separator to number
n.- Parameter:
- Returns:
(string)
The number formatted with commas for thousands separators.
- See also:
lib.isEmpty()(function)- Returns:
(boolean)
true iff string or table is empty
- Note:
May not be correct for tables with metatables.
lib.isNotEmpty()(function)- Returns:
(boolean)
true iff string or table is not empty
- Note:
May not be correct for tables with metatables.
lib.nilIfEmpty()(function)- Returns:
nil if string or table is empty, otherwise return the value.
lib.inArray(t, elm)(function)- Parameters:
(table)
tA table of itemselmThe item to search for
- Returns:
true if
elmis a value int; false otherwise. (Does not check keys oft.)
- See also:
another implementation: Dev:TableTools.includes()
Other items
(variable)Ordered table iterator, allow to iterate on the natural order of the keys of a table.
Example: