Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Special pages
Random page
Wiki Discord
Contents
Neighbors
Galaxy
> Hexia
> Norvan
> Pashah
> Taffeh
Creatures
> Insects
> Fishes
> Shore-Dwellers
Items
> Dishes
> Furniture
Game Systems
> Dress Up
> Luca Arbor
> Loomix Footprints
> Loomix Vehicle Services
> Loomix Homes
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Editing
Module
:
Array
Module
Discussion
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Once you make an edit, a temporary account will be created for you.
Learn more
.
Log in
or
create an account
to continue receiving notifications after this account expires, and to access other features.
Anti-spam check. Do
not
fill this in!
-- Source: https://genshin-impact.fandom.com/wiki/Module:Array local p = {} local lib = require('Module:Feature') function p.main(frame) local args = require('Module:Arguments').getArgs(frame, { wrapper = { 'Template:Array' } }) --mw.logObject(args,'args') --debug return p._main(args, frame) end function p._main(args, frame) local arrayString = args[1] or nil local separator = args[2] or args.delim or nil local form = args[3] or args['format'] or nil local join = args[4] or args.join or '' local dedupe = args['dedupe'] or nil local sort = args['sort'] or nil local sentence = args['sentence'] or nil local template = args['template'] or nil local prefix = args['prefix'] or '' local suffix = args['suffix'] or '' local sentence_last = args['sentence_last'] or ' and ' local sentence_join = args['sentence_join'] or ', ' local sub_separator = args.subsep or nil local split_opt = { removeEmpty = args['removeEmpty'] or nil, noTrim = args['noTrim'] or nil } -- argument validation if arrayString == nil then return '' end if separator == nil then return error('Second argument (separator) must not be empty.') end if separator == '' then return error('Second argument (separator) must not be empty string.') end if form == nil then return error('Third argument (format) must not be empty.') end if form:find('{item[%d%.]*}') == nil then return error('Third argument (format) does not include {item}.') end -- split string to array local array = lib.split(arrayString, separator, split_opt) local array2 = args.array2 and lib.split(args.array2, args.arraysep2 or separator, split_opt) or nil if array2 then local product = {} for _, item1 in ipairs(array) do for _, item2 in ipairs(array2) do table.insert(product, {item1, item2}) end end array = product end -- remove duplcates from array if dedupe == '1' then array = p._removeDuplicates(array) end -- sort array if sort ~= nil then array = p._sort(array, sort) end -- replace keywords in array for key, value in pairs(array) do local item = form local value2 if array2 then value2 = value[2] value = value[1] end item = item:gsub('{newline}', '\n') item = item:gsub('{index}', key) -- figure out sub-divisions if any function split(arr, index) if args['delim' .. index] then for v in lib.gsplit(arr.main, args['delim' .. index], split_opt) do local subarr = {main = v} split(subarr, tostring(tonumber(index)+1)) table.insert(arr, subarr) end else return end end local values = { main = value } split(values, '2') if value2 then item = item:gsub('{item2}', value2) end item = item:gsub('{item}', value) item = item:gsub('{item([%d%.]*)}', function(suffix) local val = values for index in lib.gsplit(suffix, '.') do if val[tonumber(index)] then val = val[tonumber(index)] else val = {main=''} break end end return val.main end ) array[key] = item end if args.debug then mw.logObject(array, 'input array') end -- create result array local result = '' -- join as sentence if sentence ~= nil then if #array == 0 then return '' elseif #array == 1 then result = array[1] elseif #array == 2 then result = array[1] .. sentence_last .. array[2] else local last = table.remove(array, #array) result = table.concat(array, sentence_join) .. ',' .. sentence_last .. last end -- join with join string else result = table.concat(array, join):gsub('{newline}', '\n'):gsub('{space}', ' ')--in case joining string contains keyword end result = prefix .. result .. suffix if template then if args.debug then mw.logObject(result, 'final result pre-preprocess') end if not args.nodpl then result = result :gsub('²{','{{') :gsub('}²','}}') :gsub('¦','|') end result = result :gsub('%^2{','{{') -- for use inside DPL :gsub('}%^2','}}') -- :gsub('¹','|') -- result = frame:preprocess(result) end if args.debug then mw.logObject(result, 'final result') end return result end function p._removeDuplicates(arr) local hash = {} local res = {} for _,v in ipairs(arr) do if (not hash[v]) then res[#res+1] = v hash[v] = true end end return res end function p._sort(arr, dir) local order = nil if (dir == -1 or dir == '-1') then order = function(tVal, a, b) return a > b end elseif (dir == 1 or dir == '1') then order = function(tVal, a, b) return a < b end else return arr end table.sort(arr, function(a, b) return order(t, a, b) end) return arr end return p
Summary:
Please note that all contributions to The Petit Planet Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see
Petit Planet Wiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Below are commonly used wikitext from
MediaWiki:Edittools
. Click on any to insert them in the edit box.
File Pages
==Summary==
==Licensing==
{{Fairuse}}
{{File|}}
Dynamic Page List
¦
²
«
»
²{¦}²
«»
«/»
«!----»
Array in DPL
¹
^2{
}^2
^2{¹}^2
Parser Functions
{{#if:||}}
{{#if:<condition>|<result if true>|<result if false>}}
{{#ifeq:|||}}
{{#ifeq:<text1>|<text2>|<result if text1=text2>|<result if text1≠text2>}}
{{#expr:}}
{{#expr:<mathematical expression>}}
{{#switch:||#default=}}
{{#switch:<text1>|<text2>=<result if text1=text2>|<text3>=<result if text1=text3>|#default=<result if no valid match>}}
{{#replace:||}}
{{#replace:<text1>|<plain text to find in text1>|<plain text to insert in place of the text found>}}
{{#titleparts:}}
{{#replace:<page name>}}
{{#tag:|}}
{{#tag:<name of html tag>|<content inside html tag>}}
Markup
{{}}
|
[]
[[]]
[[Category:]]
#REDIRECT [[]] [[Category:Redirect Pages]]
<code></code>
<includeonly></includeonly>
<noinclude></noinclude>
<nowiki></nowiki>
<!---->
<br>
§
Notices
{{Stub|}}
{{Stub Dialogue}}
{{Upcoming}}
{{Under Construction}}
{{Placeholder|}}
Magic Words
{{!}}
{{formatnum:}}
{{lc:}}
{{uc:}}
{{PAGENAME}}
{{FULLPAGENAME}}
{{ROOTPAGENAME}}
{{BASEPAGENAME}}
{{SUBPAGENAME}}
{{DISPLAYTITLE:|noreplace}}
__TOC__
__NOTOC__
__EXPECTUNUSEDCATEGORY__
__HIDDENCAT__
HTML Entities
—
,
­
Pages included on this page:
Template:Documentation/Header
(
edit
)
Template:Documentation/styles.css
(
edit
)
Template:Exists
(
edit
)
Template:Extension DPL
(
view source
)
Template:High Risk
(
edit
)
Template:MessageBox
(
edit
)
Template:Namespace
(
edit
)
Template:T
(
edit
)
Template:TOC Right
(
edit
)
Module:Arguments
(
edit
)
Module:Arguments/i18n
(
edit
)
Module:Array/doc
(
edit
)
Module:Common/i18n
(
edit
)
Module:Config
(
edit
)
Module:Documentation
(
edit
)
Module:Documentation/config
(
edit
)
Module:Documentation/i18n
(
edit
)
Module:Entrypoint
(
edit
)
Module:Exists
(
edit
)
Module:Fallbacklist
(
edit
)
Module:Feature
(
edit
)
Module:Formatting
(
edit
)
Module:I18n
(
edit
)
Module:Languages
(
edit
)
Module:Mbox
(
edit
)
Module:Mbox/i18n
(
edit
)
Module:Namespace detect
(
edit
)
Module:Namespace detect/config
(
edit
)
Module:Namespace detect/data
(
edit
)
Module:TableTools
(
edit
)
Module:Yesno
(
edit
)
This page is a member of 2 hidden categories:
Category:Pages using DynamicPageList4 parser function
Category:Pages using DynamicPageList4
Search
Search
Editing
Module
:
Array
Add topic