l<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://climatewiki.earth/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://climatewiki.earth/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AConvert%2Fhelper"/>
	<link rel="alternate" type="text/html" href="https://climatewiki.earth/wiki/index.php?title=Module:Convert/helper&amp;action=history"/>
	<updated>2026-05-05T02:23:35Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.1</generator>
	<entry>
		<id>https://climatewiki.earth/wiki/index.php?title=Module:Convert/helper&amp;diff=10063&amp;oldid=prev</id>
		<title>BranchOut: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://climatewiki.earth/wiki/index.php?title=Module:Convert/helper&amp;diff=10063&amp;oldid=prev"/>
		<updated>2024-01-15T19:28:45Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:28, 15 January 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>BranchOut</name></author>
	</entry>
	<entry>
		<id>https://climatewiki.earth/wiki/index.php?title=Module:Convert/helper&amp;diff=10062&amp;oldid=prev</id>
		<title>Wikipedia&gt;Johnuniq: add horseRaceDistance for Template:Horse race distance</title>
		<link rel="alternate" type="text/html" href="https://climatewiki.earth/wiki/index.php?title=Module:Convert/helper&amp;diff=10062&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) == 'string' then&lt;br /&gt;
		return text:match('(%S.-)%s*$')&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 ''&lt;br /&gt;
	if text == '' or tonumber(text) then&lt;br /&gt;
		return text&lt;br /&gt;
	end&lt;br /&gt;
	return mw.text.killMarkers(text):gsub(',', '')&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local fractions = {&lt;br /&gt;
	['½'] = '1/2',&lt;br /&gt;
	['⅓'] = '1/3',&lt;br /&gt;
	['⅔'] = '2/3',&lt;br /&gt;
	['¼'] = '1/4',&lt;br /&gt;
	['¾'] = '3/4',&lt;br /&gt;
	['⅛'] = '1/8',&lt;br /&gt;
	['⅜'] = '3/8',&lt;br /&gt;
	['⅝'] = '5/8',&lt;br /&gt;
	['⅞'] = '7/8',&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local fractionNumbers = {&lt;br /&gt;
	['½'] = 1/2,&lt;br /&gt;
	['⅓'] = 1/3,&lt;br /&gt;
	['⅔'] = 2/3,&lt;br /&gt;
	['¼'] = 1/4,&lt;br /&gt;
	['¾'] = 3/4,&lt;br /&gt;
	['⅛'] = 1/8,&lt;br /&gt;
	['⅜'] = 3/8,&lt;br /&gt;
	['⅝'] = 5/8,&lt;br /&gt;
	['⅞'] = 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 ''&lt;br /&gt;
	if text == '' or tonumber(text) then&lt;br /&gt;
		return text  -- examples: '', '12', '12.3', '12.3e4', or negative&lt;br /&gt;
	end&lt;br /&gt;
	text = text:gsub('&amp;amp;nbsp;', ' '):gsub('  +', ' '):gsub(' *%+ *', '+'):gsub('&amp;amp;frasl;', '/'):gsub('⁄', '/')&lt;br /&gt;
	local integer, numerator, denominator, rest&lt;br /&gt;
	-- Look for a fraction of form '12 3/8' or '12+3/8' or '3/8'.&lt;br /&gt;
	integer, numerator, denominator = text:match('^(%d+)[ +](%d+)/(%d+)$')&lt;br /&gt;
	if integer then&lt;br /&gt;
		return integer .. '+' .. numerator .. '/' .. denominator&lt;br /&gt;
	end&lt;br /&gt;
	numerator, denominator = text:match('^(%d+)/(%d+)$')&lt;br /&gt;
	if numerator then&lt;br /&gt;
		return numerator .. '/' .. 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;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;')&lt;br /&gt;
	if numerator then&lt;br /&gt;
		integer = text:match('(%d+)&amp;lt;span class=&amp;quot;sr-only&amp;quot;&amp;gt;') or&lt;br /&gt;
			text:match('^(%d+)%s*&amp;amp;#x200B;&amp;lt;span') or  -- Template:Frac outputs zwsp since December 2017&lt;br /&gt;
			text:match('^(%d+)%s*&amp;lt;span')&lt;br /&gt;
		return (integer and (integer .. '+') or '') .. numerator .. '/' .. denominator&lt;br /&gt;
	end&lt;br /&gt;
	-- Look for a fraction of form '12¾' or '¾'.&lt;br /&gt;
	integer, rest = text:match('^(%d*)%s*(.*)')&lt;br /&gt;
	local expand = fractions[rest]&lt;br /&gt;
	if expand then&lt;br /&gt;
		return (integer == '' and integer or (integer .. '+')) .. 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 '12¾' or '¾'.&lt;br /&gt;
	local integer, expand = text:match('^(%d*)%s*(.*)')&lt;br /&gt;
	if integer == '' 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 == '' 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('Invalid number &amp;quot;' .. text .. '&amp;quot;', 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 .. 'm')&lt;br /&gt;
	end&lt;br /&gt;
	if furlongs then&lt;br /&gt;
		table.insert(show, furlongs .. 'f')&lt;br /&gt;
	end&lt;br /&gt;
	if yards then&lt;br /&gt;
		table.insert(show, yards .. 'y')&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;lt;span data-sort-value=&amp;quot;' ..&lt;br /&gt;
		tostring(meters) ..&lt;br /&gt;
		'&amp;amp;nbsp;!&amp;quot;&amp;gt;' ..&lt;br /&gt;
		table.concat(show, ' ') ..&lt;br /&gt;
		'&amp;lt;/span&amp;gt;'&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>Wikipedia&gt;Johnuniq</name></author>
	</entry>
</feed>