Module:CSVExport

From WikiProducers
Revision as of 08:40, 16 August 2025 by Eddymunoz (talk | contribs) (Created page with "local p = {} local function q(s) if not s then return '' end s = tostring(s) if s:find('[,\n"]') then s = '"' .. s:gsub('"','""') .. '"' end return s end function p.dataURI(frame) local a = frame:getParent().args local header = 'Name,Title,Organization,Phone,Email,Website,Street,City,State,ZIP,Country,LinkedIn,Instagram,X' local row = table.concat({ q(a.name), q(a.title), q(a.org), q(a.phone), q(a.email), q(a.website), q(a.street), q(a.city), q(a....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Documentation for this module may be created at Module:CSVExport/doc

local p = {}

local function q(s)
  if not s then return '' end
  s = tostring(s)
  if s:find('[,\n"]') then s = '"' .. s:gsub('"','""') .. '"' end
  return s
end

function p.dataURI(frame)
  local a = frame:getParent().args
  local header = 'Name,Title,Organization,Phone,Email,Website,Street,City,State,ZIP,Country,LinkedIn,Instagram,X'
  local row = table.concat({
    q(a.name), q(a.title), q(a.org), q(a.phone), q(a.email), q(a.website),
    q(a.street), q(a.city), q(a.state), q(a.zip), q(a.country),
    q(a.linkedin), q(a.instagram), q(a.x)
  }, ',')
  local csv = header .. '\r\n' .. row .. '\r\n'
  return mw.uri.encode(csv, 'PATH')
end

return p