Module:Manufacturer

local mArguments --initialize lazily local checkType = require('libraryUtil').checkType local p = {}

--- Return matched manufacturer from string --- @param string s Match string --- @return table Manufacturer local function matchManufacturer( s ) local data = mw.loadJsonData( 'Module:Manufacturer/data.json' ) for i, manufacturer in ipairs( data ) do   	for j, value in pairs( manufacturer ) do if string.match( string.lower( value ), '^' .. string.lower( s ) .. '$' ) then return manufacturer end end end return nil end

function p.manufacturer( frame ) mArguments = require( 'Module:Arguments' ) local args = mArguments.getArgs( frame ) local s = args[1] -- Default to name key local type = args['type'] or 'name' if not s then return ' No text specified. '	end return p._manufacturer( s, type ) end

function p._manufacturer( s, type ) -- Return table for Lua if type == nil then type = 'table' end checkType('_manufacturer', 1, s, 'string') checkType('_manufacturer', 2, type, 'string')

local manufacturer = matchManufacturer( s ) if type == 'table' then -- Used for other Lua modules return manufacturer elseif manufacturer == nil or manufacturer[type] == nil then return ' No ' .. type .. ' found for ' .. s .. '. '	else -- Return string from matched manufacturer return manufacturer[type] end end

return p