Module:Device

require('strict') local getArgs = require('Module:Arguments').getArgs local data = mw.loadData('Module:Device/data')

local function hasPrefix(str, prefix) return string.sub(str, 1, #prefix) == prefix end

local function warning(frame, message) return frame:callParserFunction('#info: ' .. message, { 'warning' }) end

local p = { devices = data.devices }

function p.osForDevice(device, firmware) local result for _, value in ipairs(data.osForDevice) do		if hasPrefix(device, value[1]) then result = value[2] break end end

if result == 'iOS' or result == 'iPadOS' then -- Handle iPadOS and iPhone OS edge cases -- Parse out major firmware version local major = 13 if firmware ~= nil then major = tonumber(firmware:match("^([^.]+)\.")) or tonumber(firmware) or 13 end

-- iPadOS prior to 13.0 was iOS if hasPrefix(device, 'iPad') and major < 13 then result = 'iOS' end

-- iOS prior to 4.0 was iPhone OS		if (hasPrefix(device, 'iPhone') or hasPrefix(device, 'iPod')) and major < 4 then result = 'iPhone OS' end -- Apple Vision Pro if hasPrefix(device, 'RealityDevice') then result = 'visionOS' end end

return result end

function p.deviceName(device) return (data.devices[device] or {}).name end

function p.deviceLink(device) local info = data.devices[device] if info == nil then return nil end return  .. info.name ..  end

function p.osForDeviceTemplate(frame) local args = getArgs(frame) return p.osForDevice(args[1] or , args[2]) or warning(frame, 'Unknown device: ' .. (args[1] or )) end

function p.deviceNameTemplate(frame) local args = getArgs(frame) return p.deviceName(args[1]) or warning(frame, 'Unknown device: ' .. (args[1] or '')) end

function p.deviceLinkTemplate(frame) local args = getArgs(frame) return p.deviceLink(args[1]) or warning(frame, 'Unknown device: ' .. (args[1] or '')) end

return p