Module:Authority control/auxiliary
Appearance
Wikipedia authority control |
---|
Usage
This contains auxiliary functions used by Module:Authority control. They are accessed by using the valid and customlink parameters in Module:Authority control/config. Please refer to the documentation for that module.
require('strict')
local p = {}
p.validateIsni = function(id) --Validate ISNI (and ORCID) and retuns it as a 16 characters string or returns false if it's invalid. See http://support.orcid.org/knowledgebase/articles/116780-structure-of-the-orcid-identifier
id = id:gsub( '[ %-]', '' ):upper()
if not id:match( '^%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d[%dX]$' ) then
return false
end
local total = 0
for i = 1, 15 do
local digit = id:byte( i ) - 48 --Get integer value
total = (total + digit) * 2
end
local remainder = total % 11
local result = (12 - remainder) % 11
local checkdigit
if result == 10 then
checkdigit = 'X'
else
checkdigit=tostring( result )
end
if checkdigit ~= string.char( id:byte( 16 ) ) then
return false
end
return id
end
p.splitLccn = function(id)
if id:match( '^%l%l?%l?%d%d%d%d%d%d%d%d%d?%d?$' ) then
id = id:gsub( '^(%l+)(%d+)(%d%d%d%d%d%d)$', '%1/%2/%3' )
end
if id:match( '^%l%l?%l?/%d%d%d?%d?/%d+$' ) then
return mw.text.split( id, '/' )
end
return false
end
return p