Module:LCCN: Difference between revisions

Content deleted Content added
force str conversion
unnecessary
 
(10 intermediate revisions by 3 users not shown)
Line 1:
require[[Module:No globals]]('strict')
local p = {}
 
Line 7:
 
local function pad(padlen, ...)
padlen = tonumber(padlen) or 0
if 1 > select('#', ...) then
return ("0"):rep(padlen)
Line 23 ⟶ 24:
return str
end
returnlocal pad(tonumber((...))strlen -= mw.ustring.len(str), select(2, ...)) .. str
if id1 > strlen then
return pad((...), select(2, ...))
end
return pad((tonumber((...)) or 0) - strlen, select(2, ...)) .. str
end
 
Line 31 ⟶ 36:
return str
end
returnlocal strstrlen .. pad(tonumber((...)) -= mw.ustring.len(str), select(2, ...))
if not1 left_part> strlen then
return pad((...), select(2, ...))
end
return str .. pad((tonumber((...)) or 0) - strlen , select(2, ...))
end
 
Line 41 ⟶ 50:
local args = frame:getParent().args
local id = blank_to_nil(args[1] or args.id)
if not id then
local title = blank_to_nil(args[2] or args.title or args.name)
error("Template:LCCN: You must provide an ID.")
local left_part, right_part, url
if id then
local letter_width = (id:match("^%s*[0-9][0-9]") and id:len() < 10) and 0 or 2
left_part = id:sub(1, letter_width + 2)
right_part = expr(padright(id, letter_width + 8, '.00000'):sub(letter_width + 3, letter_width + 8))
url = "https://lccn.loc.gov/" .. left_part .. padleft(right_part, 6, 0)
else
url = "https://lccn.loc.gov/Name?" .. mw.title.getCurrentTitle():partialUrl()
end
local title = blank_to_nil(args[2] or args.title or args.name)
 
local letter_width = (id:match("^%s*[0-9][0-9]") and id:len() < 10) and 0 or 2
local left_part, right_part= id:sub(1, urlletter_width + 2)
local right_part = expr(padright(id, letter_width + 8, '.00000'):sub(letter_width + 3, letter_width + 8))
local url = "https://lccnwww.loc.gov/item/" .. left_part .. padleft(right_part, 6, 0)
if args.long == "yes" then
return ("CatalogBibliographic record for [%s %s] at the United States [[LCCN (identifier)|Library of Congress]]"):format(
url, title or mw.title.getCurrentTitle().text)
end
if not left_part then
error("Template:LCCN: You must provide an ID.")
end
return ("[[LCCN (identifier)|LCCN]]&nbsp;[%s %s-%s]%s"):format(
url, left_part, right_part, title and ('&nbsp;&ndash;&nbsp;' .. title) or '')
title and ('&nbsp;&ndash;&nbsp;' .. title) or '')
end