![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/lavocat.quebec/private_html/node_modules/json2csv/lib/ |
'use strict';
const { Readable } = require('stream');
const JSON2CSVTransform = require('./JSON2CSVTransform');
class JSON2CSVAsyncParser {
constructor(opts, transformOpts) {
this.opts = opts;
this.transformOpts = transformOpts;
}
/**
* Main function that converts json to csv.
*
* @param {Stream|Array|Object} data Array of JSON objects to be converted to CSV
* @returns {Stream} A stream producing the CSV formated data as a string
*/
parse(data) {
if (typeof data === 'string' || ArrayBuffer.isView(data)) {
data = Readable.from(data, { objectMode: false });
} else if (Array.isArray(data)) {
data = Readable.from(data.filter(item => item !== null));
} else if (typeof data === 'object' && !(data instanceof Readable)) {
data = Readable.from([data]);
}
if (!(data instanceof Readable)) {
throw new Error('Data should be a JSON object, JSON array, typed array, string or stream');
}
return data.pipe(new JSON2CSVTransform(this.opts, { objectMode: data.readableObjectMode, ...this.transformOpts }));
}
}
module.exports = JSON2CSVAsyncParser;