Wikipedia:Lua/Modul/Sort/en
Erscheinungsbild
Vorlagenprogrammierung | Diskussionen | Lua | Test | Unterseiten | |||
Modul | Deutsch | English
|
Modul: | Dokumentation |
Sort
– module with auxilary functions to create sortable keys.
Functions for templates
- All functions evaluate the first parameter as term to be sorted.
- If there is no first parameter provided by
#invoke
the first parameter of surrounding template transclusion will be used.
- If there is no first parameter provided by
- Optional parameters of
#invoke
specify input and result format and further capabilities.
Return value is always the sort key.
Tlatin
Alphanumeric terms in latin based scripts are reduced to basic characters of ASCII set.
- Optional parameters
-
- v
- Variant
- Default: ISO (simplify all diacritic characters; ligatures of two letters)
DIN5007m2
(DIN 5007 Variante 2)
- Various typografic codes for spaces, horizontal dashes and invisible characters are reduced to ASCII.
- Multiple whitespace is reduced to single space.
Casing (upcased/downcased) will remain; that can be eliminated easily from result.
Tn
Numerical values.
- Remarks
- A sort key shall be inserted into a lexical set and correct order ensured by leading zero digits. Negative values are to be ordered in correct lexical sequence.
- Minus signs may precede as ASCII or Unicode (U+2212, 872210); leading plus sign will be ignored.
- Optional parameters
-
- d
- decimal separator
- Default: ASCII dot
- t
- grouping separator (one or two).
- Simultaneous request of dot and apostrophe is possible for German/Swiss segmentation.
- Default: none
- z
- number of leading digits, die links mit Nullen aufgefüllt werden
- Default: 15
- m
- Negative Werte zusammenhalten, aber nach Betrag sortieren
- Default: Alle Zahlen nach Wert aufsteigend
Siehe auch die Auskopplung Sort/N15 zur Performance-Optimierung.
failsafe
- Purpose
- Version ID (local):
2024-06-14
- Optional parameter:
1
– Minimum version orwikidata
{{#invoke:Sort|failsafe}}
yields2024-06-14
- With a parameter as ISO date it is compared whether the current module satisfies this version or later.
{{#invoke:Sort|failsafe|2001-01-01}}
returns: »2024-06-14
«{{#invoke:Sort|failsafe|2099-01-01}}
returns: »« – (empty), if minimal version condition not matched
- If keyword is
wikidata
, result is version ID registered on Wikidata (2024-06-14
) or local if not found there. - If keyword is
~
, result is empty if local and Wikidata version are the same: ().
- Returns:
- Empty, if minimal version condition not matched, or
~
and local version is synchronized. - Version ID if no parameter, or if
wikidata
, or local if not found there, or not synchronized.
- Empty, if minimal version condition not matched, or
Examples (test page)
A test page illustrates results on input formats.
Date and time
That is implemented by the module DateTime.
Functions for Lua modules (API)
All functions described above can be used by other modules:
local lucky, Sort = pcall( require, "Module:Sort" )
if type( Sort ) == "table" then
Sort = Sort.Sort()
else
-- In the event of errors, Sort is an error message.
return "<span class='error'>" .. Sort .. "</span>"
end
- Sort.lex( adjust, apply, adapt )
- Similar to Tlatin.
- adjust
- term (string)
- mandatory
- apply
- base script (string)
"latin"
"cyrillic"
"greek"
"uni"
- currently
latin
available only - adapt
- variant (string, optional)
"DIN5007m2"
- Sort.num( value, d, t, z, m )
- Similar to Tn.
- value
- numerical value (string, number)
- mandatory
- d
- decimal separator (string)
- t
- one or two grouping separators (string)
- z
- number of leading digits (number)
- m
- numerical values vertically aligned by amount (boolean)
- Sort.failsafe( atleast )
- Versioning interface similar to failsafe
- atleast
- optional
- nil or minimum version or
wikidata
or~
for synchronisation
- returns: Version ID as string or
false
Installation on other WMF projects
Follow the steps:
- Copy main module
Module:Sort
into your project.- If possible keep the name
Sort
. - If another name is required due to conflict or naming convention or non-latin script then choose a different one.
- If possible keep the name
- Register this module at d:Q24205172.
- Copy desired sub modules, and keep the chosen root name.
- Ready.
- Consider translation of doc page.
Usage
General library; no limitations.
Dependencies
No other than sub modules.
Sub modules
- Module:Sort/latin containing the collation table for latin based scripts.
- Module:Sort/latinDIN5007m2 containing the collation table for DIN 5007 Variante 2.
- Module:Sort/latinAT containing the collation table specific for Austrian.
- Module:Sort/latinCS containing the collation table specific for Czechoslovakian.
- Module:Sort/latinDA containing the collation table specific for Danish.
- Module:Sort/latinScand containing a collation table specific for scandinavian languages.
- Module:Sort/currency containing a collation table for currency symbols.
- Module:Sort/utf8max2bytes containing a collation table only reducing to 2 Bytes in UTF-8.
- Module:Sort/N15 containing a performance optimized version for numeriscal values.
- Module:Sort/unquote supports discarding of quotation marks.
Envisioned
- Module:Sort/cyrillic – containing collation table for cyrillic based scripts (Ukrainian etc.).
- Module:Sort/greek – containing collation table for greek scripts (polytonic).
- Module:Sort/uni – containing collation table for all (letter based?) script systems.
Internationalisation
Not necessary.