Update csv.js

This commit is contained in:
Aleksandr Statciuk 2022-02-20 07:05:50 +03:00
parent 3d1e8cadc3
commit 66c18bf64d

View file

@ -22,15 +22,17 @@ const csv2jsonOptions = {
logo: nullable,
subdivision: nullable,
city: nullable,
network: nullable
network: nullable,
website: nullable
}
}
const json2csv = new Parser({
transforms: [flattenArray],
transforms: [flattenArray, formatBool],
formatters: {
string: stringQuoteOnlyIfNecessary()
}
},
eol: '\r\n'
})
const csv = {}
@ -66,6 +68,18 @@ function flattenArray(item) {
return item
}
function formatBool(item) {
for (let prop in item) {
if (item[prop] === false) {
item[prop] = 'FALSE'
} else if (item[prop] === true) {
item[prop] = 'TRUE'
}
}
return item
}
function listParser(value) {
return value.split(';').filter(i => i)
}