Wikipedia:Lua/Modul/Sort/cellNum/en
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
- 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.234E56for 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
1then 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
ltrorrtl - 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:
2025-01-27 - optional parameter
1– required version, or keywordwikidataor keyword~
- Version ID:
- Returns:
- empty, if minimal version condition not matched
- local version otherwise, or registered version on Wikidata (
2025-01-27) when keywordwikidata - empty, if keyword
~and a registered version on Wikidata is the same as local; otherwise local version ID ()
Features
- 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
×10the letterEwill be copied, which yields to a common format for many programming languages.
Functions for Lua modules (API)
All 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.htmlobject, 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
cellobject - Sort.failsafe(atleast)
- Version ID
- atleast
optional
nil or required version or"~"or"wikidata"
- atleast
- returns: string or false
Dependencies
- Sort/cell – Library with basic functions on table attributes
Internationalisation and local project adaption
The 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.
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.