Differenze tra le versioni di "Modulo:Wikilib/forms"

m
Added formSortValue
(Refactoring of Wikilib/tables module *** sovrascritto il testo esistente ***)
m (Added formSortValue)
--]]
f.getNdexForm = function(poke)
pokeif = string.lowertype(poke) or== 'number') then
return poke
end
 
poke = string.lower(poke)
if not alt[poke] then
return 0
trueName = type(trueName) == 'number' and string.tf(trueName) or trueName
return trueName .. f.toEmptyAbbr(extform)
end
 
--[[
 
This function returns the sorting key of Pokémon names, taking care of
alternative forms. The returned value is meant to be used as data-sort-value
in sortable tables.
 
The sorting key should be just the Pokémon name when it has no forms, or no
displayed link. Otherwise, the name should be used first, followed by the
form name.
 
Arguments:
- ndex: The ndex or the name of the base form Pokémon.
- abbr: The form abbreviation name.
- poke: The name of the Pokémon.
 
--]]
f.formSortValue = function(ndex, abbr, poke)
ndex = f.getNdexForm(type(ndex) == 'string' and ndex:lower() or ndex)
local data, value, name = alt[ndex], '${name}', poke
local formName
 
if data and data.links[abbr] ~= '' then
formName = data.names[abbr]
value = '${name}, ${form}'
end
 
return string.interp(value, {
name = name,
form = formName
})
end