Modul:LargeNum
Moduldokumentasjon
[opprett]
local libUtil = require 'libraryUtil'
local h = {}
function h._property( property, from, trailing )
libUtil.checkType( 'LargeNum.property', 1, property, 'string' )
libUtil.checkType( 'LargeNum.property', 2, from, 'string', true )
libUtil.checkType( 'LargeNum.property', 3, trailing, 'string', true )
local entityId = nil
if not from or from == '' then
entityId = mw.wikibase.getEntityIdForCurrentPage()
elseif mw.ustring.find( from, '^Q%d+$') then
entityId = from
else
entityId = mw.wikibase.getEntityIdForTitle( from )
end
mw.logObject(entityId)
if not entityId then
return ''
end
local statements = mw.wikibase.getBestStatements( entityId, property )
--do return mw.dumpObject(statements) end
local seq = {}
for _,v in ipairs( statements ) do
local mainsnak = v.mainsnak
if mainsnak.snaktype == 'value' then
local t = {}
local str = mw.wikibase.renderSnak( mainsnak )
local unit = mw.ustring.match( str, '%d%s([^%d%s][^%d]*)$' )
local mantissa = mw.ustring.match( str, '^[-+]?([%d%s]+)' )
local fraction = mw.ustring.match( str, ',([%d]+)' )
local exponent = mw.ustring.match( str, '%s*[eE]([-+]?[%d]+)' )
if mantissa then
mantissa = mw.ustring.gsub( mantissa, '%s$', '' )
mantissa = mw.ustring.gsub( mantissa, '%s', ' ' )
table.insert( t, mantissa )
end
if fraction then
fraction = mw.ustring.gsub( fraction, '%s$', '' )
if #t > 0 then
table.insert( t, ' ' )
end
table.insert( t, ',' )
table.insert( t, mw.ustring.sub( fraction, 1, 3 ) )
for i = 3,mw.ustring.len( fraction ),3 do
table.insert( t, " " )
table.insert( t, mw.ustring.sub( fraction, i+1, i+3 ) )
end
end
if trailing then
table.insert( t, trailing )
end
if exponent then
if #t > 0 then
table.insert( t, ' ' )
end
table.insert( t, exponent )
end
if unit then
if #t > 0 then
table.insert( t, ' ' )
end
table.insert( t, unit )
end
table.insert( seq, table.concat( t, '' ) )
end
end
return table.concat( seq, '; ')
end
function h.property( frame )
return h._property( frame.args[1], frame.args['from'], frame.args['trailing'] )
end
return h