code: function toCSVString(data, params) {
      if (data.length === 0) {
        return '';
      }
      params = params || {};
  
      var header = params.headers || [],
          plainObject = isPlainObject(data[0]),
          keys = plainObject && (params.order || keysIndex(data)),
          oData,
          i;
  
      // Defaults
      var escape = params.escape || '"',
          delimiter = params.delimiter || ',';
  
      // Dealing with headers polymorphism
      if (!header.length)
        if (plainObject && params.headers !== false)
          header = keys;
  
      // Should we append headers
      oData = (header.length ? [header] : []).concat(
        plainObject ?
          data.map(function(e) { return objectToArray(e, keys); }) :
          data
      );
  
      // Converting to string
      return oData.map(function(row) {
        return row.map(function(item) {
  
          // Wrapping escaping characters
          var i = ('' + (typeof item === 'undefined' ? '' : item)).replace(
            new RegExp(rescape(escape), 'g'),
            escape + escape
          );
  
          // Escaping if needed
          return ~i.indexOf(delimiter) || ~i.indexOf(escape) || ~i.indexOf('\n') ?
            escape + i + escape :
            i;
        }).join(delimiter);
      }).join('\n');
    }
docs: Converting an array of arrays into a CSV string