Module:IATA and ICAO code/sandbox2

require('Module:No globals'); local p = {}

local airportLink local master = mw.loadData("Module:IATA and ICAO code/data/sandbox2")

local IATA_airport = master.IATA local ICAO_airport = master.ICAO local wikilink_label = master.WikiName

function p.main(frame) local code = mw.text.trim(frame.args[1] or ''):upper --exemple of data { 'AAA', 'NTGA', 'Anaa Airport', 'Anaa' },

if 3 ~= #code and 4 ~= #code then											--accepts only three-letter codes (IATA) and 4-letter codes (ICAO) return table.concat ({'&#x3c;span style=\"font-size:100%; font-style:normal;\" class=\"error\"&#x3e;error: invalid code: ', code, ', must be an ICAO or IATA code&#x3c;/span&#x3e;'}); end

if IATA_airport[code] then airportLink= table.concat ({, wikilink_label[code], })	-- make wikilink from iata code elseif ICAO_airport[code] then airportLink = table.concat ({, wikilink_label[code], })	-- make wikilink from icao code else airportLink = table.concat ({'&#x3c;span style=\"font-size:100%; font-style:normal;\" class=\"error\"&#x3e;error: data missing for code: &#x3c;b&#x3e;', code, '&#x3c;/b&#x3e;&#x3c;/span&#x3e;'}); end

return airportLink end

return p