Wikipedia:Lua/Modul/Sort/cellNum/en
Vorlagenprogrammierung | Diskussionen | Lua | Test | Unterseiten | |||
Modul | Deutsch | English
|
Modul: | Dokumentation |
Sort/cellNum
– Module with functions for generation of sortable number values in tables and for advanced number formatting.
Functions for templates
Bearbeiten- f
- Format number.
- Parameters of template transclusion around:
- none
- Parameters of
#invoke
– all optional:- n
- (Base) Number (mantissa)
- Typographic minus sign permitted.
- Dot
.
as decimal separator expected, but local project decimal separator is valid as well. - Machine readable format
1.234E56
for exponential representation (base 10) is also possible. This will trigger presentation with the same exponential number. - Grouping (thousands or other) separator not recommended, since disambiguous interpretation may occur. Dot
.
as decimal separator will precede. - Default:
0
- exp
- Exponent (to the power of ten).
- Integer number expected.
- Typographic minus sign permitted.
- This will trigger presentation with exponential number (so-called “scientific notation”).
- pre
- Short prefix.
- Appended to value without line break; normal whitespace.
- plus
- Positive Values (including zero) presented with preceding plus sign.
- post
- Short postfix.
- Appended to value without line break; normal whitespace.
- pad
- Attempt to align decimal separators based on left or right edge.
- Positive integer number: Count of digits following decimal separator to align (for left-to-right scripting: right-aligned).
- Negative integer number: Count of digits preceding the value (for left-to-right scripting: left-aligned).
- cell
- If
1
then precede required table syntax for sortable number values. - Otherwise create
<span>
if necessary. - class
- Universal attribute: space separated list of class names
- style
- Universal attribute: CSS declaration
- URL and quotation marks
"
are not permitted. - id
- Universal attribute: fragment ID
- lang
- Universal attribute: language code
- Only if not matching page language
- dir
- Universal attribute: writing direction, either
ltr
orrtl
- Only if not matching page language
- cssNum
- Page name of a TemplateStyles page, for general formatting
- cssNumExp
- Page name of a TemplateStyles page, for formatting with exponential numbers
- Returns: Wikitext.
- On invalid input an error message will be returned.
- failsafe
-
- Version ID:
2024-09-19
- optional parameter
1
– required version, or keywordwikidata
or keyword~
- Version ID:
- Returns:
- empty, if minimal version condition not matched
- local version otherwise, or registered version on Wikidata (
2024-06-01
) when keywordwikidata
- empty, if keyword
~
and a registered version on Wikidata is the same as local; otherwise local version ID (2024-06-01
)
Features
Bearbeiten- Presentation
-
- Always typographic minus sign.
- Always local project decimal separator.
- Grouping separator (thousands or other) symbol according to local project customization.
- Multiplication sign between mantissa and 10 according to local project customization and might be improved against · which is difficult to recognized.
- Parameter format
-
- Both simple ASCII and typographic minus sign possible.
- Both dot or local project decimal separator possible.
- Syntax error in input(e.g. n-dash rather than typographic minus, or letter „O“ than digit zero) will be marked.
- Sorting
-
- Preceding text or typographic minus sign do not influence sorting order.
- All cells with simple figures or other templates in family can be combined.
- Padding
-
- It will be tried to arrange decimal separators one below the other integrated for the entire column.
- For each cell in column the same position is provided, and the individual whitespace to be probaly inserted for each cell and number will be computed.
- Copy & Paste
- On copy & paste of single numbers or entire tables the local project optical presentation will be replaced by machine-readable international data format. That does permit to insert easily values into other templates or external calculation programs:
- ASCII hyphen rather than typographic minus sign
- Dot as decimal separator
- No (thousands) grouping
- Rather than the term
×10
the letterE
will be copied, which yields to a common format for many programming languages.
Functions for Lua modules (API)
BearbeitenAll functions described above can be used by other modules:
local lucky, Sort = pcall( require, "Module:Sort/cellNum" )
if type( Sort ) == "table" then
Sort = Sort.Sort()
else
-- failure; Sort is the error message
return "<span class=\"error\">" .. Sort .. "</span>"
end
Subsequently there are available:
- Sort.f(arglist)
- Reduce enhanced JSON data to strict JSON and analyse for errors.
- arglist – table with parameters; as for
f
Components, every string will get trimmed:- n – number|string; parsed as in template
- exp – number|string; parsed as in template
- pre – string
- plus – boolean|string
- string – parsed as in template;
1
→true
- string – parsed as in template;
- post – string
- pad – number|string
- cell – string|boolean|table
- string – parsed as in template;
1
→true
- table –
mw.html
object, which will be attributed and filled with content.
- string – parsed as in template;
- class – string
- style – string|table, plain code or property name mapping
- id – string
- lang – string
- dir – string
- cssNum – string|title
- cssNumExp – string|title
- frame – object with
frame
, if at hand; otherwisenil
- arglist – table with parameters; as for
- returns: string with wikitext or attribution of
cell
object - Sort.failsafe(atleast)
- Version ID
- atleast
optional
nil or required version or"~"
or"wikidata"
- atleast
- returns: string or false
Dependencies
Bearbeiten- Sort/cell – Library with basic functions on table attributes
Internationalisation and local project adaption
BearbeitenThe module is working for all languages and number formattings, even for right -to-left scripting. Grouping (thousands or other) is derived automatically from local project; mostly 3, but some cultures use 4 or 5.
Adaption to local decimal separator and adaption of (thousands) grouping separator is to be done by TemplateStyles:
A second one is configuring multiplication sign and 10n appearance:
Local page names can be provided via cssNum
and cssNumExp
assignments.