json2csv
Version: 
Convert JSON to CSV
18 lines (11 loc) • 415 B
JavaScript
const defaulStringFormatter = require('./string');
function objectFormatter(opts = { stringFormatter: defaulStringFormatter() }) {
  return (value) => {
    if (value === null) return '';
    value = JSON.stringify(value);
    if (value === undefined) return '';
    if (value[0] === '"') value = value.replace(/^"(.+)"$/,'$1');
    return opts.stringFormatter(value);
  }
}
module.exports = objectFormatter;