feat: support boolean and null in JSON to CSV

This commit is contained in:
jeiea 2022-08-17 02:12:39 +09:00
parent 037590f831
commit 69e59916e2
2 changed files with 16 additions and 2 deletions

View file

@ -114,8 +114,11 @@ class JSONToCSV extends Operation {
* @returns {string}
*/
escapeCellContents(data, force=false) {
if (typeof data === "number") data = data.toString();
if (force && typeof data !== "string") data = JSON.stringify(data);
if (data !== "string") {
const isPrimitive = data == null || typeof data !== "object";
if (isPrimitive) data = `${data}`;
else if (force) data = JSON.stringify(data);
}
// Double quotes should be doubled up
data = data.replace(/"/g, '""');