parse(data) {
    const processedData = this.preprocessData(data, this.opts.fields);

    const fields = this.opts.fields || this.preprocessFieldsInfo(processedData
      .reduce((fields, item) => {
        Object.keys(item).forEach((field) => {
          if (!fields.includes(field)) {
            fields.push(field)
          }
        });

        return fields
      }, []));

    const header = this.opts.header ? this.getHeader(fields) : '';
    const rows = this.processData(processedData, fields);
    const csv = (this.opts.withBOM ? '\ufeff' : '')
      + header
      + ((header && rows) ? this.opts.eol : '')
      + rows;

    return csv;
  }
Main function that converts json to csv.

@param {Array|Object} data Array of JSON objects to be converted to CSV
@returns {String} The CSV formated data as a string