https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AChange%2Fsandbox Module:Change/sandbox - Revision history 2025-05-29T04:08:23Z Revision history for this page on the wiki MediaWiki 1.45.0-wmf.2 https://en.wikipedia.org/w/index.php?title=Module:Change/sandbox&diff=1149260702&oldid=prev Lemondoge: Simplification 2023-04-11T03:46:23Z <p>Simplification</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 03:46, 11 April 2023</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 119:</td> <td colspan="2" class="diff-lineno">Line 119:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if dsp == 'row2' then</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if dsp == 'row2' then</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> return style .. '|' .. s .. pre2 .. n2 .. suf2 .. s</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> return style .. '|' .. s .. pre2 .. n2 .. suf2 .. s</div></td> </tr> <tr> <td colspan="2" class="diff-empty diff-side-deleted"></td> <td class="diff-marker"><a class="mw-diff-movedpara-right" title="Paragraph was moved. Click to jump to old location." href="#movedpara_6_0_lhs">&#x26AB;</a></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_1_0_rhs"></a> .. '\n|' .. style .. '|' .. pcrf, errorflag</div></td> </tr> <tr> <td colspan="2" class="diff-empty diff-side-deleted"></td> <td class="diff-marker"><a class="mw-diff-movedpara-right" title="Paragraph was moved. Click to jump to old location." href="#movedpara_4_0_lhs">&#x26AB;</a></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_1_1_rhs"></a> <ins style="font-weight: bold; text-decoration: none;">elseif</ins> inv == 'off' then</div></td> </tr> <tr> <td colspan="2" class="diff-empty diff-side-deleted"></td> <td class="diff-marker"><a class="mw-diff-movedpara-right" title="Paragraph was moved. Click to jump to old location." href="#movedpara_6_2_lhs">&#x26AB;</a></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_1_2_rhs"></a> return style .. '|' .. s .. pre1 .. <ins style="font-weight: bold; text-decoration: none;">n1</ins> .. suf1 .. s</div></td> </tr> <tr> <td colspan="2" class="diff-empty diff-side-deleted"></td> <td class="diff-marker"><a class="mw-diff-movedpara-right" title="Paragraph was moved. Click to jump to old location." href="#movedpara_6_3_lhs">&#x26AB;</a></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_1_3_rhs"></a> .. '\n|' .. style .. '|' .. s .. pre2 .. <ins style="font-weight: bold; text-decoration: none;">n2</ins> .. suf2 .. s</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> .. '\n|' .. style .. '|' .. pcrf, errorflag</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> .. '\n|' .. style .. '|' .. pcrf, errorflag</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> else</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> else</div></td> </tr> <tr> <td colspan="2" class="diff-empty diff-side-deleted"></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> return style .. '|' .. s .. pre1 .. n2 .. suf1 .. s</div></td> </tr> <tr> <td class="diff-marker"><a class="mw-diff-movedpara-left" title="Paragraph was moved. Click to jump to new location." href="#movedpara_1_1_rhs">&#x26AB;</a></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_4_0_lhs"></a> <del style="font-weight: bold; text-decoration: none;"> if</del> inv == 'off' then</div></td> <td colspan="2" class="diff-empty diff-side-added"></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> <del style="font-weight: bold; text-decoration: none;">return</del> style .. '|' .. s .. <del style="font-weight: bold; text-decoration: none;">pre1</del> .. n1 .. <del style="font-weight: bold; text-decoration: none;">suf1</del> .. s</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> <ins style="font-weight: bold; text-decoration: none;">.. '\n|' ..</ins> style .. '|' .. s .. <ins style="font-weight: bold; text-decoration: none;">pre2</ins> .. n1 .. <ins style="font-weight: bold; text-decoration: none;">suf2</ins> .. s</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> </del> .. '\n|' .. style .. '|' .. <del style="font-weight: bold; text-decoration: none;">s</del> <del style="font-weight: bold; text-decoration: none;">.. pre2 .. n2 .. suf2 .. s</del></div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> .. '\n|' .. style .. '|' .. <ins style="font-weight: bold; text-decoration: none;">pcrf,</ins> <ins style="font-weight: bold; text-decoration: none;">errorflag</ins></div></td> </tr> <tr> <td class="diff-marker"><a class="mw-diff-movedpara-left" title="Paragraph was moved. Click to jump to new location." href="#movedpara_1_0_rhs">&#x26AB;</a></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_6_0_lhs"></a><del style="font-weight: bold; text-decoration: none;"> </del> .. '\n|' .. style .. '|' .. pcrf, errorflag</div></td> <td colspan="2" class="diff-empty diff-side-added"></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> else</div></td> <td colspan="2" class="diff-empty diff-side-added"></td> </tr> <tr> <td class="diff-marker"><a class="mw-diff-movedpara-left" title="Paragraph was moved. Click to jump to new location." href="#movedpara_1_2_rhs">&#x26AB;</a></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_6_2_lhs"></a><del style="font-weight: bold; text-decoration: none;"> </del> return style .. '|' .. s .. pre1 .. <del style="font-weight: bold; text-decoration: none;">n2</del> .. suf1 .. s</div></td> <td colspan="2" class="diff-empty diff-side-added"></td> </tr> <tr> <td class="diff-marker"><a class="mw-diff-movedpara-left" title="Paragraph was moved. Click to jump to new location." href="#movedpara_1_3_rhs">&#x26AB;</a></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_6_3_lhs"></a><del style="font-weight: bold; text-decoration: none;"> </del> .. '\n|' .. style .. '|' .. s .. pre2 .. <del style="font-weight: bold; text-decoration: none;">n1</del> .. suf2 .. s</div></td> <td colspan="2" class="diff-empty diff-side-added"></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> .. '\n|' .. style .. '|' .. pcrf, errorflag</div></td> <td colspan="2" class="diff-empty diff-side-added"></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> end</div></td> <td colspan="2" class="diff-empty diff-side-added"></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td> </tr> <!-- diff cache key enwiki:diff:1.41:old-1149260663:rev-1149260702:wikidiff2=table:1.14.1:ff290eae --> </table> Lemondoge https://en.wikipedia.org/w/index.php?title=Module:Change/sandbox&diff=1149260663&oldid=prev Lemondoge: Create sandbox version of Module:Change 2023-04-11T03:45:52Z <p>Create sandbox version of <a href="/wiki/Module:Change" title="Module:Change">Module:Change</a></p> <p><b>New page</b></p><div>-- This implements {{change}}<br /> local p = {}<br /> <br /> local function ntsh(outvalue)<br /> local sortkey = &#039;0000000000000000000&#039;<br /> if outvalue == nil then<br /> return &#039;&lt;span style=&quot;display:none&quot; data-sort-value=&quot;&#039; .. sortkey .. &#039;♠&quot;&gt;&lt;/span&gt;&#039;<br /> end<br /> <br /> -- This code was copied from [[Template:Convert]] <br /> if outvalue == 0 then<br /> sortkey = &#039;5000000000000000000&#039;<br /> else<br /> local mag = math.floor(math.log10(math.abs(outvalue)) + 1e-14)<br /> local prefix<br /> if outvalue &gt; 0 then<br /> prefix = 7000 + mag<br /> else<br /> prefix = 2999 - mag<br /> outvalue = outvalue + 10^(mag+1)<br /> end<br /> sortkey = string.format(&#039;%d&#039;, prefix) .. string.format(&#039;%015.0f&#039;, math.floor(outvalue * 10^(14-mag)))<br /> end<br /> return &#039;&lt;span style=&quot;display:none&quot; data-sort-value=&quot;&#039; .. sortkey .. &#039;♠&quot;&gt;&lt;/span&gt;&#039;<br /> end<br /> <br /> local function trim(s)<br /> return s:match(&#039;^%s*(.-)%s*$&#039;)<br /> end<br /> <br /> local function isnotempty(s)<br /> return s and trim(s) ~= &#039;&#039;<br /> end<br /> <br /> function change(args)<br /> local rnd = require(&#039;Module:Math&#039;)._round<br /> local prec_format = require(&#039;Module:Math&#039;)._precision_format<br /> local lang = mw.getContentLanguage()<br /> local function formatnum(num)<br /> return lang:parseFormattedNumber(num) and lang:formatNum(lang:parseFormattedNumber(num)) or num<br /> end<br /> <br /> local errorflag = nil<br /> <br /> local dsp = args[&#039;disp&#039;] or &#039;row&#039;<br /> local inv = args[&#039;invert&#039;] or &#039;off&#039;<br /> local srt = args[&#039;sort&#039;] or ((isnotempty(args[&#039;pre&#039;]) or isnotempty(args[&#039;sort&#039;])) and &#039;on&#039; or &#039;off&#039;)<br /> local n1 = (inv == &#039;on&#039;) and tonumber(lang:parseFormattedNumber(args[&#039;2&#039;])) or tonumber(lang:parseFormattedNumber(args[&#039;1&#039;]))<br /> local n2 = (inv == &#039;on&#039;) and tonumber(lang:parseFormattedNumber(args[&#039;1&#039;])) or tonumber(lang:parseFormattedNumber(args[&#039;2&#039;]))<br /> local dec = args[&#039;dec&#039;] or &#039;2&#039;<br /> local s = ((args[&#039;italics&#039;] or &#039;off&#039;) == &#039;on&#039; and &quot;&#039;&#039;&quot; or &quot;&quot;)<br /> .. ((args[&#039;bold&#039;] or &#039;off&#039;) == &#039;on&#039; and &quot;&#039;&#039;&#039;&quot; or &quot;&quot;)<br /> <br /> local pc, pcr, pcrf = &#039;NA&#039;, &#039;NA&#039;<br /> <br /> if n1 and n2 and n1 ~= 0 then<br /> pc = 100*(n2/n1 - 1)<br /> pcr = rnd(pc, dec)<br /> if pcr &gt; 0 then<br /> pcrf = &#039;&lt;span style=&quot;color:green&quot;&gt;&#039; ..<br /> s .. &#039;+&#039; .. prec_format(pc, dec) .. &#039;%&#039; .. s .. &#039;&lt;/span&gt;&#039;<br /> elseif pcr &lt; 0 then<br /> pcrf = &#039;&lt;span style=&quot;color:red&quot;&gt;&#039; ..<br /> s .. prec_format(pc, dec) .. &#039;%&#039; .. s .. &#039;&lt;/span&gt;&#039;<br /> else<br /> pcrf = s .. prec_format(0, dec) .. &#039;%&#039; .. s<br /> end<br /> pcrf = ntsh(pcr) .. pcrf<br /> else<br /> pcrf = ntsh(nil) .. s .. &#039;NA&#039; .. s<br /> if n1 == nil or n2 == nil then<br /> errorflag = 1<br /> end<br /> end<br /> <br /> if dsp == &#039;out&#039; then<br /> return pcrf, errorflag<br /> else<br /> local pre1 = args[&#039;pre1&#039;] or args[&#039;pre&#039;] or &#039;&#039;<br /> local pre2 = args[&#039;pre2&#039;] or args[&#039;pre&#039;] or &#039;&#039;<br /> local suf1 = args[&#039;suf1&#039;] or args[&#039;suf&#039;] or &#039;&#039;<br /> local suf2 = args[&#039;suf2&#039;] or args[&#039;suf&#039;] or &#039;&#039;<br /> <br /> local rspn = &#039;rowspan=&#039; .. (args[&#039;rowspan&#039;] or &#039;1&#039;) .. &#039; &#039;<br /> local algn = &#039;text-align:&#039; .. (args[&#039;align&#039;] or &#039;right&#039;) .. &#039;;&#039;<br /> local bg = &#039;background-color:&#039; .. (args[&#039;bgcolour&#039;] or args[&#039;bgcolor&#039;] or &#039;inherit&#039;) .. &#039;;&#039;<br /> <br /> if rspn == &#039;rowspan=1 &#039; then rspn = &#039;&#039; end<br /> if bg == &#039;background-color:inherit;&#039; then bg = &#039;&#039; end<br /> local style = rspn .. &#039;style=&quot;&#039; .. algn .. bg .. &#039;&quot;&#039;<br /> <br /> local sk1, sk2 = &#039;&#039;, &#039;&#039;<br /> <br /> if srt == &#039;on&#039; then<br /> sk1 = ntsh(n1)<br /> sk2 = ntsh(n2)<br /> end<br /> <br /> if n1 ~= nil then<br /> if n1 &lt; 0 then<br /> n1 = &#039;−&#039; .. formatnum(-1*n1)<br /> else<br /> n1 = formatnum(n1)<br /> end<br /> else<br /> n1 = (inv == &#039;on&#039;) and (args[&#039;2&#039;] or &#039;&#039;) or (args[&#039;1&#039;] or &#039;&#039;)<br /> end<br /> <br /> if n2 ~= nil then<br /> if n2 &lt; 0 then<br /> n2 = &#039;−&#039; .. formatnum(-1*n2)<br /> else<br /> n2 = formatnum(n2)<br /> end<br /> else<br /> n2 = (inv == &#039;on&#039;) and (args[&#039;1&#039;] or &#039;&#039;) or (args[&#039;2&#039;] or &#039;&#039;)<br /> end<br /> <br /> if dsp == &#039;row2&#039; then<br /> return style .. &#039;|&#039; .. s .. pre2 .. n2 .. suf2 .. s<br /> .. &#039;\n|&#039; .. style .. &#039;|&#039; .. pcrf, errorflag<br /> else<br /> if inv == &#039;off&#039; then<br /> return style .. &#039;|&#039; .. s .. pre1 .. n1 .. suf1 .. s<br /> .. &#039;\n|&#039; .. style .. &#039;|&#039; .. s .. pre2 .. n2 .. suf2 .. s<br /> .. &#039;\n|&#039; .. style .. &#039;|&#039; .. pcrf, errorflag<br /> else<br /> return style .. &#039;|&#039; .. s .. pre1 .. n2 .. suf1 .. s<br /> .. &#039;\n|&#039; .. style .. &#039;|&#039; .. s .. pre2 .. n1 .. suf2 .. s<br /> .. &#039;\n|&#039; .. style .. &#039;|&#039; .. pcrf, errorflag<br /> end<br /> end<br /> end<br /> end<br /> <br /> function p.main(frame)<br /> local res, eflag = change((frame.args[1] or frame.args[2]) and frame.args or frame:getParent().args)<br /> if eflag then<br /> res = res .. frame:expandTemplate{title = &#039;change/error&#039;}<br /> end<br /> return res<br /> end<br /> <br /> return p</div> Lemondoge