Modul:ISBN
Utseende
Dokumentation [visa] [redigera] [historik] [rensa sidcachen]
Den här modulen används av mallen {{ISBN}}
.
p = {}
p.ISBN = function( frame )
local pframe = frame:getParent()
local args = pframe.args
local arg1 = args[ 1 ]
local arg = string.gsub(arg1,"%(.*%)","") -- remove possible parenthesis, e.g. "(inb.)", in the parameter value
if arg and arg ~= '' then
local link = '[[Special:Bokkällor/' .. arg1 .. '|ISBN ' .. arg1 .. ']]'
local copy = arg
copy = copy:gsub( '-', '' )
copy = copy:gsub( ' ', '' )
local length = copy:len()
if length == 10 then
local t = {}
for i = 1, length do
if copy:sub( i, i ) == 'X' then
t[ i ] = 10
else
t[ i ] = copy:sub( i, i )
end
end
local t2 = {}
local multiplier = 10
for i = 1, #t do
t2[ i ] = t[ i ] * multiplier
multiplier = multiplier -1
end
local sum = 0
for i = 1, #t2 do
sum = sum + t2[ i ]
end
local remainder = sum % 11
if remainder ~= 0 then
return link .. '[[Kategori:Sidor med felaktigt ISBN]]'
end
elseif length == 13 then
local t = {}
for i = 1, length do
t[ i ] = copy:sub( i, i )
end
local t2 = {}
for i = 1, #t do
if i % 2 == 0 then
t2[ i ] = t[ i ] * 3
else
t2[ i ] = t[ i ]
end
end
local sum = 0
for i = 1, #t2 do
sum = sum + t2[ i ]
end
local remainder = sum % 10
if remainder ~= 0 then
return link .. '[[Kategori:Sidor med felaktigt ISBN]]'
end
else
return link .. '[[Kategori:Sidor med felaktigt ISBN]]'
end
return link
else
return '<span class="error">[[Mall:ISBN]] anropad utan argument</span>[[Kategori:Sidor som anropar Mall:ISBN utan argument]]'
end
end
return p