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:
condDetermines which value to return. (boolean)TThe value to return ifcondis true (or truthy).FThe value to return ifcondis false (or falsey).
lib.trim(text)(function)- Removes ASCII whitespace from the start and end of
text. Slightly more efficient than themw.textimplementation. - Parameter:
textThe 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
textseparated bydelim. (function) - See also:
lib.splitfor argument documentation. 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:
- Returns: Substrings of
text separated bydelim`. (table) lib.unstripNoWiki()(function)- A wrapper around
mw. text.unstripNoWikithat 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
tblthat outputs items in the order defined byorder. - Parameters:
tblThe table to iterate over. (table)orderThe iteration order. Can be specified either as an ordered list (table) of keys fromtblor 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). (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:
inputA string formed by concatenating the output of Phantom Templates. Usually, this string is generated by DPL. (string)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 '='. (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:
inputA string formed by concatenating the output of Phantom Templates. Usually, this string is generated by DPL. (string)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 '='. (string; optional)
- Returns:
lib.thousandsSeparator(n)(function)- Add thousands separator to number
n. - Parameter:
nIf 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:
tA table of items (table)elmThe item to search for
- Returns: true if
elmis a value int; false otherwise. (Does not check keys oft.) - See also:
- http://stackoverflow.com/q/2282444
- another implementation: Dev:TableTools.includes()