<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://the-democratika.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AConvert%2Fhelper</id>
	<title>Module:Convert/helper - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://the-democratika.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AConvert%2Fhelper"/>
	<link rel="alternate" type="text/html" href="https://the-democratika.com/wiki/index.php?title=Module:Convert/helper&amp;action=history"/>
	<updated>2026-04-04T23:06:47Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://the-democratika.com/wiki/index.php?title=Module:Convert/helper&amp;diff=9063&amp;oldid=prev</id>
		<title>&gt;Johnuniq: add horseRaceDistance for Template:Horse race distance</title>
		<link rel="alternate" type="text/html" href="https://the-democratika.com/wiki/index.php?title=Module:Convert/helper&amp;diff=9063&amp;oldid=prev"/>
		<updated>2024-01-10T01:46:26Z</updated>

		<summary type="html">&lt;p&gt;add horseRaceDistance for &lt;a href=&quot;/wiki/index.php?title=Template:Horse_race_distance&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Template:Horse race distance (page does not exist)&quot;&gt;Template:Horse race distance&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- This module provides some functions to prepare template parameters&lt;br /&gt;
-- for use with Template:Convert.&lt;br /&gt;
-- This module is not used by Template:Convert or Module:Convert.&lt;br /&gt;
&lt;br /&gt;
local function stripToNil(text)&lt;br /&gt;
	-- If text is a non-empty string, return its trimmed content,&lt;br /&gt;
	-- otherwise return nothing (empty string or not a string).&lt;br /&gt;
	if type(text) == &amp;#039;string&amp;#039; then&lt;br /&gt;
		return text:match(&amp;#039;(%S.-)%s*$&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Remove commas and references (any strip markers) from a number.&lt;br /&gt;
-- First usage in Template:Infobox_UK_place/dist (June 2018)&lt;br /&gt;
local function cleanNumber(frame)&lt;br /&gt;
	local args = frame.args&lt;br /&gt;
	local text = stripToNil(args[1]) or &amp;#039;&amp;#039;&lt;br /&gt;
	if text == &amp;#039;&amp;#039; or tonumber(text) then&lt;br /&gt;
		return text&lt;br /&gt;
	end&lt;br /&gt;
	return mw.text.killMarkers(text):gsub(&amp;#039;,&amp;#039;, &amp;#039;&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local fractions = {&lt;br /&gt;
	[&amp;#039;½&amp;#039;] = &amp;#039;1/2&amp;#039;,&lt;br /&gt;
	[&amp;#039;⅓&amp;#039;] = &amp;#039;1/3&amp;#039;,&lt;br /&gt;
	[&amp;#039;⅔&amp;#039;] = &amp;#039;2/3&amp;#039;,&lt;br /&gt;
	[&amp;#039;¼&amp;#039;] = &amp;#039;1/4&amp;#039;,&lt;br /&gt;
	[&amp;#039;¾&amp;#039;] = &amp;#039;3/4&amp;#039;,&lt;br /&gt;
	[&amp;#039;⅛&amp;#039;] = &amp;#039;1/8&amp;#039;,&lt;br /&gt;
	[&amp;#039;⅜&amp;#039;] = &amp;#039;3/8&amp;#039;,&lt;br /&gt;
	[&amp;#039;⅝&amp;#039;] = &amp;#039;5/8&amp;#039;,&lt;br /&gt;
	[&amp;#039;⅞&amp;#039;] = &amp;#039;7/8&amp;#039;,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local fractionNumbers = {&lt;br /&gt;
	[&amp;#039;½&amp;#039;] = 1/2,&lt;br /&gt;
	[&amp;#039;⅓&amp;#039;] = 1/3,&lt;br /&gt;
	[&amp;#039;⅔&amp;#039;] = 2/3,&lt;br /&gt;
	[&amp;#039;¼&amp;#039;] = 1/4,&lt;br /&gt;
	[&amp;#039;¾&amp;#039;] = 3/4,&lt;br /&gt;
	[&amp;#039;⅛&amp;#039;] = 1/8,&lt;br /&gt;
	[&amp;#039;⅜&amp;#039;] = 3/8,&lt;br /&gt;
	[&amp;#039;⅝&amp;#039;] = 5/8,&lt;br /&gt;
	[&amp;#039;⅞&amp;#039;] = 7/8,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
-- Format regular input with fraction (MOS-confirmant) into Convert-format &amp;quot;12+3/8&amp;quot; (&amp;quot;+&amp;quot; added).&lt;br /&gt;
-- First usage in Template:NFL_predraft (August 2017)&lt;br /&gt;
local function number(frame)&lt;br /&gt;
	--[[ Preprocess a template parameter to translate a number to be used as&lt;br /&gt;
	input for {{convert}}.&lt;br /&gt;
	{{#invoke:convert/helper|number|12 3/8}} → 12+3/8&lt;br /&gt;
		Input				Output&lt;br /&gt;
		12					12&lt;br /&gt;
		12 3/8				12+3/8&lt;br /&gt;
		{{frac|12|3|8}}		12+3/8&lt;br /&gt;
		12{{frac|3|8}}		12+3/8&lt;br /&gt;
		12⅜					12+3/8&lt;br /&gt;
	Template:Fraction redirects to Template:Frac so either may be used in the input.&lt;br /&gt;
	]]&lt;br /&gt;
	local args = frame.args&lt;br /&gt;
	local text = stripToNil(args[1]) or &amp;#039;&amp;#039;&lt;br /&gt;
	if text == &amp;#039;&amp;#039; or tonumber(text) then&lt;br /&gt;
		return text  -- examples: &amp;#039;&amp;#039;, &amp;#039;12&amp;#039;, &amp;#039;12.3&amp;#039;, &amp;#039;12.3e4&amp;#039;, or negative&lt;br /&gt;
	end&lt;br /&gt;
	text = text:gsub(&amp;#039;&amp;amp;nbsp;&amp;#039;, &amp;#039; &amp;#039;):gsub(&amp;#039;  +&amp;#039;, &amp;#039; &amp;#039;):gsub(&amp;#039; *%+ *&amp;#039;, &amp;#039;+&amp;#039;):gsub(&amp;#039;&amp;amp;frasl;&amp;#039;, &amp;#039;/&amp;#039;):gsub(&amp;#039;⁄&amp;#039;, &amp;#039;/&amp;#039;)&lt;br /&gt;
	local integer, numerator, denominator, rest&lt;br /&gt;
	-- Look for a fraction of form &amp;#039;12 3/8&amp;#039; or &amp;#039;12+3/8&amp;#039; or &amp;#039;3/8&amp;#039;.&lt;br /&gt;
	integer, numerator, denominator = text:match(&amp;#039;^(%d+)[ +](%d+)/(%d+)$&amp;#039;)&lt;br /&gt;
	if integer then&lt;br /&gt;
		return integer .. &amp;#039;+&amp;#039; .. numerator .. &amp;#039;/&amp;#039; .. denominator&lt;br /&gt;
	end&lt;br /&gt;
	numerator, denominator = text:match(&amp;#039;^(%d+)/(%d+)$&amp;#039;)&lt;br /&gt;
	if numerator then&lt;br /&gt;
		return numerator .. &amp;#039;/&amp;#039; .. denominator&lt;br /&gt;
	end&lt;br /&gt;
	-- Look for an expanded fraction such as the result of {{frac|12|3|8}} or 12{{frac|3|8}} or {{frac|3|8}}.&lt;br /&gt;
	numerator, denominator = text:match(&amp;#039;&amp;lt;sup&amp;gt;(%d+)&amp;lt;/sup&amp;gt;/&amp;lt;sub&amp;gt;(%d+)&amp;lt;/sub&amp;gt;&amp;lt;/span&amp;gt;&amp;#039;)&lt;br /&gt;
	if numerator then&lt;br /&gt;
		integer = text:match(&amp;#039;(%d+)&amp;lt;span class=&amp;quot;sr-only&amp;quot;&amp;gt;&amp;#039;) or&lt;br /&gt;
			text:match(&amp;#039;^(%d+)%s*&amp;amp;#x200B;&amp;lt;span&amp;#039;) or  -- Template:Frac outputs zwsp since December 2017&lt;br /&gt;
			text:match(&amp;#039;^(%d+)%s*&amp;lt;span&amp;#039;)&lt;br /&gt;
		return (integer and (integer .. &amp;#039;+&amp;#039;) or &amp;#039;&amp;#039;) .. numerator .. &amp;#039;/&amp;#039; .. denominator&lt;br /&gt;
	end&lt;br /&gt;
	-- Look for a fraction of form &amp;#039;12¾&amp;#039; or &amp;#039;¾&amp;#039;.&lt;br /&gt;
	integer, rest = text:match(&amp;#039;^(%d*)%s*(.*)&amp;#039;)&lt;br /&gt;
	local expand = fractions[rest]&lt;br /&gt;
	if expand then&lt;br /&gt;
		return (integer == &amp;#039;&amp;#039; and integer or (integer .. &amp;#039;+&amp;#039;)) .. expand&lt;br /&gt;
	end&lt;br /&gt;
	return text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function distanceNumber(text)&lt;br /&gt;
	-- Return a number corresponding to text (0 if text is empty) or throw an error if invalid.&lt;br /&gt;
	text = text or 0&lt;br /&gt;
	if tonumber(text) then&lt;br /&gt;
		return tonumber(text)&lt;br /&gt;
	end&lt;br /&gt;
	-- Look for a fraction of form &amp;#039;12¾&amp;#039; or &amp;#039;¾&amp;#039;.&lt;br /&gt;
	local integer, expand = text:match(&amp;#039;^(%d*)%s*(.*)&amp;#039;)&lt;br /&gt;
	if integer == &amp;#039;&amp;#039; then&lt;br /&gt;
		integer = 0&lt;br /&gt;
	else&lt;br /&gt;
		integer = tonumber(integer)&lt;br /&gt;
	end&lt;br /&gt;
	if expand == &amp;#039;&amp;#039; then&lt;br /&gt;
		expand = 0&lt;br /&gt;
	else&lt;br /&gt;
		expand = fractionNumbers[expand]&lt;br /&gt;
	end&lt;br /&gt;
	if integer and expand then&lt;br /&gt;
		return integer + expand&lt;br /&gt;
	end&lt;br /&gt;
	error(&amp;#039;Invalid number &amp;quot;&amp;#039; .. text .. &amp;#039;&amp;quot;&amp;#039;, 0)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- First usage in Template:Horse_race_distance (January 2024)&lt;br /&gt;
local function horseRaceDistance(frame)&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local miles = stripToNil(args[1])&lt;br /&gt;
	local furlongs = stripToNil(args[2])&lt;br /&gt;
	local yards = stripToNil(args[3])&lt;br /&gt;
	local show = {}&lt;br /&gt;
	if miles then&lt;br /&gt;
		table.insert(show, miles .. &amp;#039;m&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
	if furlongs then&lt;br /&gt;
		table.insert(show, furlongs .. &amp;#039;f&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
	if yards then&lt;br /&gt;
		table.insert(show, yards .. &amp;#039;y&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
	miles = distanceNumber(miles)&lt;br /&gt;
	furlongs = distanceNumber(furlongs)&lt;br /&gt;
	yards = distanceNumber(yards)&lt;br /&gt;
	local meters = miles * 1609.344 + furlongs * 201.168 + yards * 0.9144&lt;br /&gt;
	return&lt;br /&gt;
		&amp;#039;&amp;lt;span data-sort-value=&amp;quot;&amp;#039; ..&lt;br /&gt;
		tostring(meters) ..&lt;br /&gt;
		&amp;#039;&amp;amp;nbsp;!&amp;quot;&amp;gt;&amp;#039; ..&lt;br /&gt;
		table.concat(show, &amp;#039; &amp;#039;) ..&lt;br /&gt;
		&amp;#039;&amp;lt;/span&amp;gt;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	number = number,&lt;br /&gt;
	cleanNumber = cleanNumber,&lt;br /&gt;
	horseRaceDistance = horseRaceDistance,&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>&gt;Johnuniq</name></author>
	</entry>
</feed>