dev

This is the documentation page for Module:Feature

See Global Lua Modules/Feature Miscellaneous useful functions.

Documentation

Package items

lib.ternary(cond, T, F) (function)
Choose one of two values to return.
Parameters:
cond Determines which value to return. (boolean)
T The value to return if cond is true (or truthy).
F The value to return if cond is false (or falsey).
lib.trim(text) (function)
Removes ASCII whitespace from the start and end of text. Slightly more efficient than the mw.text implementation.
Parameter: text The text to trim. (string)
Returns: The trimmed text. (string)
See also: https://help.fandom.com/wiki/Extension:Scribunto#mw.text.trim_is_slow
lib.gsplit() (function)
Returns an iterator over substrings that would be returned by lib. split.
Returns: Iterator over substrings of text separated by delim. (function)
See also: lib.split for argument documentation.
lib.split(text, delim, opt) (function)
Returns a table containing the substrings of text that are separated by delim. (Compared to mw.text.split, this function always treats delim as a literal string rather than a pattern, and it trims output substrings using lib.trim by default.)
Parameters:
text The string to split. (string)
delim The delimiter string to use when splitting text. (Using an empty string will split text into individual characters.) (string; optional)
opt Extra options: (table; optional)
opt.noTrim Set true to disable trimming of generated substrings using lib.trim. (boolean; optional)
opt.removeEmpty Set true to omit empty substrings (i.e., when multiple delim appear consecutively, or when delim appears at the start or end of text). (boolean; optional)
Returns: Substrings of text separated by delim`. (table)
lib.unstripNoWiki() (function)
A wrapper around mw. text.unstripNoWiki that un-escapes characters/sequences that <nowiki> escapes.
See also: https://github.com/wikimedia/mediawiki/blob/c22d01f23b7fe754ef106e97bae32c3966f8db3e/includes/parser/CoreTagHooks.php#L146 for MediaWiki source code for <nowiki>
lib.spairs(tbl, order) (function)
Returns an iterator over tbl that outputs items in the order defined by order.
Parameters:
tbl The table to iterate over. (table)
order The iteration order. Can be specified either as an ordered list (table) of keys from tbl or as an ordering function that accepts tbl, keyA, and keyB and returns true when the entry in tbl associated wity keyA should come before the one for keyB. If not specified, the keys' natural ordering is used (i.e., function(tbl, a, b) return a < b end). (table|function; optional)
Returns: The iterator. (function)
lib.parseTemplateFormat(input, key_separator, end_separator, equal_separator) (function)
Parses Phantom Template Format strings into a list of maps.
Parameters:
input A string formed by concatenating the output of Phantom Templates. Usually, this string is generated by DPL. (string)
key_separator Separator between the entries (key-value pairs) of items in input. Defaults to ';'. (string; optional)
end_separator Separator between items in input. Defaults to '$'. (string; optional)
equal_separator Separator between the key and value of each entry in input. Defaults to '='. (string; optional)
Returns: A list of items from input; each value is a map of the item's entries. (table)
lib.parseTemplateFormatOrdered(input, key_separator, end_separator, equal_separator) (function)
Parses Phantom Template Format strings into a list of ordered maps.
Parameters:
input A string formed by concatenating the output of Phantom Templates. Usually, this string is generated by DPL. (string)
key_separator Separator between the entries (key-value pairs) of items in input. Defaults to ';'. (string; optional)
end_separator Separator between items in input. Defaults to '$'. (string; optional)
equal_separator Separator between the key and value of each entry in input. Defaults to '='. (string; optional)
Returns:
A list of items from input; each value is a list of the item's entries. (table)
The i-th item of input. (table)
The value of the page key for this item. (string)
The j-th key-value pair of this item. (table)
The j-th key of this item. (string)
The j-th value of this item.
lib.thousandsSeparator(n) (function)
Add thousands separator to number n.
Parameter: n If a frame is given, then its first argument (frame.args1 ) will be used as input instead. (number|frame; optional)
Returns: The number formatted with commas for thousands separators. (string)
See also: https://stackoverflow.com/questions/10989788/format-integer-in-lua/10992898#10992898
lib.isEmpty() (function)
Returns: true iff string or table is empty (boolean)
Note: May not be correct for tables with metatables.
lib.isNotEmpty() (function)
Returns: true iff string or table is not empty (boolean)
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:
t A table of items (table)
elm The item to search for
Returns: true if elm is a value in t; false otherwise. (Does not check keys of t.)
See also:
http://stackoverflow.com/q/2282444
another implementation: Dev:TableTools.includes()