Global Lua Modules/ListFunctions

ListFunctions is a module that provides some functions for working with lists. It was designed to perfectly combine with Variables, Arrays, and DPL3 ({{#dplvar}}) extensions. It also trims all list's items and removes empty values.
== ==
== ==
=== lstSeparator ===
; 
: Replaces one list's separator with another.
:: input list — string
:: input separator — string or character
:: output separator — string or character
==== Examples ====
Code 	Result
{{#invoke:ListFunctions|lstSeparator|1, 2, 3, 4|,|/}}	
{{#invoke:ListFunctions|lstSeparator|1, 2, , 4|,|/}} 	
{{#invoke:ListFunctions|lstSeparator|1, 2, 3, 4|,|,}}	
=== lstCount ===
; 
: Counts all items in a list (excluded empty values).
:: input list — string
:: input separator — string or character
==== Examples ====
Code 	Result
{{#invoke:ListFunctions|lstCount|1, 2, 3, 4|,}} 	
{{#invoke:ListFunctions|lstCount|aaa, bbb, aaa, ccc|,}}	
{{#invoke:ListFunctions|lstCount|1, 2, , 4|,}} 	
{{#invoke:ListFunctions|lstCount|1, 2, 3, 4, 10|,}} 	
=== lstIndex ===
; 
: Retrieve the N-th element in a list (excluded empty values). If the index is negative, it returns the same value as the $list_len - abs($index).
:: input list — string
:: input separator — string or character
:: index — number
==== Examples ====
Code 	Result
{{#invoke:ListFunctions|lstIndex|1, 2, 3, 4|,|1}} 	
{{#invoke:ListFunctions|lstIndex|aaa, bbb, aaa, ccc|,|-2}}	
{{#invoke:ListFunctions|lstIndex|aaa, bbb, aaa, ccc|,|-1}}	
{{#invoke:ListFunctions|lstIndex|1, 2, , 4|,|3}} 	
=== lstSub ===
; 
: N/A
:: input list — string
:: input separator — string or character
:: output separator — string or character
:: start index — number
:: the result list's length — number
==== Examples ====
Code 	Result
{{#invoke:ListFunctions|lstSub|1, 2, 3, 4|,|/|1|3}} 	
{{#invoke:ListFunctions|lstSub|a, b, c, d, e, f|,|,|2|4}} 	
{{#invoke:ListFunctions|lstSub|a, b, c, d, e, f|,|,|-4|2}} 	
{{#invoke:ListFunctions|lstSub|a, b, c, d, e, f|,|,|-4|-2}}	
{{#invoke:ListFunctions|lstSub|1, 2, , 4|,|,|2|2}} 	
=== lstFind ===
; 
: N/A
:: item — string
:: input list — string
:: input separator — string or character
:: case sensitive — "cs" (turn on case sensitivity) (optional)
==== Examples ====
Code 	Result
{{#invoke:ListFunctions|lstFind|1|1, 2, 3, 4|,}} 	
{{#invoke:ListFunctions|lstFind||1, 2, 3, , 4|,}} 	
{{#invoke:ListFunctions|lstFind|aaa|AAA, aaa, BBB, bbb, ccc|,}} 	
{{#invoke:ListFunctions|lstFind|aaa|AAA, aaa, BBB, bbb, ccc|,|cs}}	
{{#invoke:ListFunctions|lstFind|aAa|AAA, aaa, BBB, bbb, ccc|,|cs}}	
=== lstApp ===
; 
: N/A
:: input list — string
:: input separator — string or character
:: item — string
==== Examples ====
Code 	Result
{{#invoke:ListFunctions|lstApp|1, 2, 3, 4|,|5}} 	
{{#invoke:ListFunctions|lstApp|1, 2, 3, , 4|,|10}}	
=== lstPrep ===
; 
: N/A
:: item — string
:: input separator — string or character
:: input list — string
==== Examples ====
Code 	Result
{{#invoke:ListFunctions|lstPrep|5|,|1, 2, 3, 4|,}} 	
{{#invoke:ListFunctions|lstPrep|10|,|1, 2, 3, , 4|,}}	
=== lstJoin ===
; 
: N/A
:: first input list — string
:: first input separator — string or character
:: second input list — string
:: second input separator — string or character
:: output separator — string or character
==== Examples ====
Code 	Result
{{#invoke:ListFunctions|lstJoin|5/6/7|/|1, 2, 3, 4|,|,}}	
{{#invoke:ListFunctions|lstJoin|10|,|1, 2, 3, , 4|,|,}} 	
=== lstUniq ===
; 
: N/A
:: mode — "cnt" (turns on "count" mode) (optional)
:: input list — string
:: input separator — string or character
:: output separator — string or character
:: case sensitive — "cs" (turn on case sensitivity) (optional)
==== Examples ====
Code 	Result
{{#invoke:ListFunctions|lstUniq||1/2/3/4|/|,}} 	
{{#invoke:ListFunctions|lstUniq|cnt|1/2/3/4|/|,}} 	
{{#invoke:ListFunctions|lstUniq||AAA, aaa, BBB, ccc, CCC|,|,}} 	
{{#invoke:ListFunctions|lstUniq|cnt|AAA, aaa, BBB, ccc, CCC|,|,}} 	
{{#invoke:ListFunctions|lstUniq||AAA, aaa, BBB, bbb, ccc, ccc|,|,|cs}} 	
{{#invoke:ListFunctions|lstUniq|cnt|AAA, aaa, BBB, bbb, ccc, ccc|,|,|cs}}	
=== lstSrt ===
; 
: N/A
:: mode — "cnt" (turns on "count" mode) (optional)
:: input list — string
:: input separator — string or character
:: output separator — string or character
:: numeric — "y" (if the list is numeric) (optional)
:: reversed — "y" (reverse list) (optional)
==== Examples ====
Code 	Result
{{#invoke:ListFunctions|lstSrt|1, 5, 2, 8, 99, 33, 4, 3, 7, 0|,|/}} 	
{{#invoke:ListFunctions|lstSrt|1, 5, 2, 8, 99, 33, 4, 3, 7, 0|,|/|y}} 	
{{#invoke:ListFunctions|lstSrt|1, 5, 2, 8, 99, 33, 4, 3, 7, 0|,|/||y}} 	
{{#invoke:ListFunctions|lstSrt|1, 5, 2, 8, 99, 33, 4, 3, 7, 0|,|/|y|y}}	
=== lstMap ===
; 
: N/A
:: input list — string
:: input separator — string or character
:: token — string or character
:: pattern — string
:: output separator — string or character
:: mode — "np" (no preprocess, decreases the time to invoke the function) (optional)
==== Examples ====
Code 	Result
{{#invoke:ListFunctions|lstMap|1, 2, 3|,|@@@@|Number: @@@@|/|np}} 	
{{#invoke:ListFunctions|lstMap|AjaxBatchDelete, AjaxRC, AjaxPoll, AjaxUndo|,|@@@@|[[@@@@]]|,|np}} 	
{{#invoke:ListFunctions|lstMap|first, second, third|,|@@@@|{{L10n|l10n|@@@@}}|/|np}} 	
{{#invoke:ListFunctions|lstMap|first, second, third|,|@@@@|{{L10n|l10n|@@@@}}|/}} 	
{{#invoke:ListFunctions|lstMap|first, second, third|,|@@@@|{{((}}L10n{{!}}l10n{{!}}@@@@{{))}}|/|np}}	
{{#invoke:ListFunctions|lstMap|first, second, third|,|@@@@|{{((}}L10n{{!}}l10n{{!}}@@@@{{))}}|/}}