toCSV comma fix
All checks were successful
Build / Build NPM Project (push) Successful in 1m15s
Build / Tag Version (push) Successful in 13s
Build / Publish Documentation (push) Successful in 50s

This commit is contained in:
Zakary Timson 2025-04-06 21:37:01 -04:00
parent f9fc4fb7ff
commit a03567eba3
2 changed files with 2 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@ztimson/utils",
"version": "0.23.18",
"version": "0.23.19",
"description": "Utility library",
"author": "Zak Timson",
"license": "MIT",

View File

@ -81,7 +81,7 @@ export function toCsv(target: any, flatten=true) {
const value = dotNotation<any>(row, h);
if(value == null) return '';
if(typeof value == 'object') return `"${JSONSanitize(value).replaceAll('"', '""')}"`;
if(typeof value == 'string' && /[\n"]/g.test(value)) return `"${value.replaceAll('"', '""')}"`;
if(typeof value == 'string' && /[\n",]/g.test(value)) return `"${value.replaceAll('"', '""')}"`;
return value;
}).join(','))
].join('\n');