Files
metabuilder/packages/data_table/seed/scripts/export/escape_csv.lua
JohnDoe6345789 d65962eb98 Implement data export and filtering modules with single-function files
- Added CSV export functionality with escape handling.
- Implemented JSON export functionality.
- Created utility functions for retrieving column labels and row values.
- Established a filtering system with state management and filter application.
- Refactored sorting logic into dedicated modules for better maintainability.
- Deprecated old filtering and sorting files, redirecting to new module structure.
- Introduced form field builders and validation utilities, also refactored into single-function files.
2025-12-30 12:16:09 +00:00

29 lines
563 B
Lua

-- Escape a value for CSV
-- Single function module for data table export
---@class EscapeCsv
local M = {}
---Escape a value for CSV
---@param value any Value to escape
---@return string Escaped CSV string
function M.escapeCsv(value)
if value == nil then
return ""
end
local str = tostring(value)
-- Check if escaping is needed
if string.find(str, '[,"\r\n]') then
-- Escape double quotes by doubling them
str = string.gsub(str, '"', '""')
-- Wrap in double quotes
str = '"' .. str .. '"'
end
return str
end
return M