<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FJohnuniq%2Funit</id>
	<title>Module:Sandbox/Johnuniq/unit - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FJohnuniq%2Funit"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/Johnuniq/unit&amp;action=history"/>
	<updated>2026-08-03T10:01:04Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Sandbox/Johnuniq/unit&amp;diff=145634&amp;oldid=prev</id>
		<title>imported&gt;Johnuniq: fix for changes in Module:Convert/sandbox</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/Johnuniq/unit&amp;diff=145634&amp;oldid=prev"/>
		<updated>2016-05-11T03:46:31Z</updated>

		<summary type="html">&lt;p&gt;fix for changes in &lt;a href=&quot;/research/Module:Convert/sandbox&quot; title=&quot;Module:Convert/sandbox&quot;&gt;Module:Convert/sandbox&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- Test the helper function in Module:Convert to get unit information.&lt;br /&gt;
-- Usage: {{#invoke:sandbox/Johnuniq/unit|main}}&lt;br /&gt;
-- See [[Module talk:Sandbox/Johnuniq/unit]].&lt;br /&gt;
&lt;br /&gt;
local function collection()&lt;br /&gt;
	-- Return a table to hold items.&lt;br /&gt;
	return {&lt;br /&gt;
		n = 0,&lt;br /&gt;
		add = function (self, item)&lt;br /&gt;
			self.n = self.n + 1&lt;br /&gt;
			self[self.n] = item&lt;br /&gt;
		end,&lt;br /&gt;
		join = function (self, sep)&lt;br /&gt;
			return table.concat(self, sep)&lt;br /&gt;
		end,&lt;br /&gt;
	}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local tests = {&lt;br /&gt;
	-- unitcode value flags (L=link, N=name, U=us, S=sort)&lt;br /&gt;
	&amp;#039;kg&amp;#039;,&lt;br /&gt;
	&amp;#039;kg 12.3 L&amp;#039;,&lt;br /&gt;
	&amp;#039;m&amp;#039;,&lt;br /&gt;
	&amp;#039;m -1 S&amp;#039;,&lt;br /&gt;
	&amp;#039;m 12 L S&amp;#039;,&lt;br /&gt;
	&amp;#039;km L&amp;#039;,&lt;br /&gt;
	&amp;#039;ft 99 L&amp;#039;,&lt;br /&gt;
	&amp;#039;km3 L&amp;#039;,&lt;br /&gt;
	&amp;#039;km3 12.3 N&amp;#039;,&lt;br /&gt;
	&amp;#039;km3 12.3 L N&amp;#039;,&lt;br /&gt;
	&amp;#039;km3 12.3 L N U&amp;#039;,&lt;br /&gt;
	&amp;#039;km3 12.3 L N U S&amp;#039;,&lt;br /&gt;
	&amp;#039;foo&amp;#039;,&lt;br /&gt;
	&amp;#039;foo L S&amp;#039;,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local function make_args(text)&lt;br /&gt;
	local flags = { L=&amp;#039;link&amp;#039;, N=&amp;#039;name&amp;#039;, U=&amp;#039;us&amp;#039;, S=&amp;#039;sort&amp;#039; }&lt;br /&gt;
	local unitcode, options&lt;br /&gt;
	local show = collection()&lt;br /&gt;
	show:add(&amp;#039;unit(&amp;#039;)&lt;br /&gt;
	for item in text:gmatch(&amp;#039;%S+&amp;#039;) do&lt;br /&gt;
		if unitcode then&lt;br /&gt;
			local k, v&lt;br /&gt;
			k = flags[item]&lt;br /&gt;
			if k then&lt;br /&gt;
				if item == &amp;#039;S&amp;#039; then&lt;br /&gt;
					v = &amp;#039;on&amp;#039;&lt;br /&gt;
				else&lt;br /&gt;
					v = &amp;#039;true&amp;#039;&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				k = &amp;#039;value&amp;#039;&lt;br /&gt;
				v = tonumber(item)&lt;br /&gt;
			end&lt;br /&gt;
			if options then&lt;br /&gt;
				show:add(&amp;#039;, &amp;#039;)&lt;br /&gt;
			else&lt;br /&gt;
				options = {}&lt;br /&gt;
				show:add(&amp;#039;, {&amp;#039;)&lt;br /&gt;
			end&lt;br /&gt;
			options[k] = v&lt;br /&gt;
			show:add(k .. &amp;#039;=&amp;#039; .. v)&lt;br /&gt;
		else&lt;br /&gt;
			unitcode = item&lt;br /&gt;
			show:add(&amp;quot;&amp;#039;&amp;quot; .. item .. &amp;quot;&amp;#039;&amp;quot;)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if options then&lt;br /&gt;
		show:add(&amp;#039;}&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
	show:add(&amp;#039;)&amp;#039;)&lt;br /&gt;
	return unitcode, options, show:join()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function main(frame)&lt;br /&gt;
	local get_unit = require(&amp;#039;Module:Convert/sandbox&amp;#039;)._unit&lt;br /&gt;
	local results = collection()&lt;br /&gt;
	for _, item in ipairs(tests) do&lt;br /&gt;
		local unitcode, options, show = make_args(item)&lt;br /&gt;
		local unit = get_unit(unitcode, options)&lt;br /&gt;
		results:add(&amp;#039;&amp;#039;)&lt;br /&gt;
		results:add(&amp;#039;&amp;gt; &amp;#039; .. show)&lt;br /&gt;
		results:add(string.format(&amp;#039;%40s %9s %s&amp;#039;,&lt;br /&gt;
			unit.text,&lt;br /&gt;
			unit.unknown and &amp;#039;(unknown)&amp;#039; or &amp;#039;&amp;#039;,&lt;br /&gt;
			unit.sortspan or &amp;#039;&amp;#039;&lt;br /&gt;
		))&lt;br /&gt;
	end&lt;br /&gt;
	return &amp;#039;&amp;lt;pre&amp;gt;\n&amp;#039; .. mw.text.nowiki(results:join(&amp;#039;\n&amp;#039;)) .. &amp;#039;\n&amp;lt;/pre&amp;gt;\n&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return { main = main }&lt;/div&gt;</summary>
		<author><name>imported&gt;Johnuniq</name></author>
	</entry>
</feed>