Module:BaseConvert: Difference between revisions

Content deleted Content added
clean whitespace so diff with sandbox works
update from Module:BaseConvert/sandbox per talk; this removes globals
 
Line 3:
local digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
 
local function normalizeFullWidthChars(s)
return mw.ustring.gsub(s, '[!-~]', function(s)
return mw.ustring.char(mw.ustring.codepoint(s, 1) - 0xFEE0)
Line 9:
end
 
local function _convert(n, base, from, precision, width, default, prefix, suffix)
n = tostring(n)
n = '' .. n -- convert to a string
 
-- strip off any leading '0x' (unless x is a valid digit in the input base)
Line 69:
end
 
local fracPart = table.concat(tf, '')
 
-- remove trailing zeros if not needed
Line 106:
setmetatable(p, {
__index = function(t, k)
local from, base = k:match('^([0-9]+)to([0-9]+)$')
if not from then return nil end
return function(frame)
local args = frame.args
return _convert(mw.text.trim(args[1]), base, from, args['.precision'], args['.width'],
args['.default'], args['.prefix'], args['.suffix'])
end
end