lib/parser.js
function toArray(str, options) {
  var opts = extend({delim: ','}, options);

  // Create a regular expression to parse the CSV values.
  var re = new RegExp(
    // Delimiters.
    '(\\' + opts.delim + '|\\n|^)' +

    // Quoted fields.
    '(?:"([^"]*(?:""[^"]*)*)"|' +

    // Standard fields.
    '([^"\\' + opts.delim + '\\n]*))', 'gi');

  // Create an array to hold our data. Give the array
  // a default empty first row.
  var arr = [[]];

  // Create an array to hold our individual pattern
  // matching groups.
  var match = null;
  var value;

  // Keep looping over the regular expression matches
  // until we can no longer find a match.
  while (match = re.exec(str)) {

    // Get the delimiter that was found.
    var matchedDelim = match[1];

    // Check to see if the given delimiter has a length
    // (is not the start of string) and if it matches
    // field delimiter. If it does not, then we can expect
    // this delimiter to be a row delimiter.
    if (matchedDelim.length && (matchedDelim != opts.delim)) {
      // Since we have reached a new row of data,
      // add an empty row to our data array.
      arr.push([]);
    }

    // Now that we have our delimiter out of the way,
    // let's check to see which kind of value we
    // captured (quoted or unquoted).
    if (match[2]) {

      // We found a quoted value. When we capture
      // this value, unescape any double quotes.
      value = match[2].replace(/""/g, '"');
    } else {

      // We found a non-quoted value.
      value = match[3];
    }

    // Now that we have our value string, let's add
    // it to the data array.
    arr[arr.length - 1].push(value);
  }

  // Return the parsed data.
  return arr;
}
function toArray(str, options) {
  var opts = extend({delim: ','}, options);

  // Create a regular expression to parse the CSV values.
  var re = new RegExp(
    // Delimiters.
    '(\\' + opts.delim + '|\\n|^)' +

    // Quoted fields.
    '(?:"([^"]*(?:""[^"]*)*)"|' +

    // Standard fields.
    '([^"\\' + opts.delim + '\\n]*))', 'gi');

  // Create an array to hold our data. Give the array
  // a default empty first row.
  var arr = [[]];

  // Create an array to hold our individual pattern
  // matching groups.
  var match = null;
  var value;

  // Keep looping over the regular expression matches
  // until we can no longer find a match.
  while (match = re.exec(str)) {

    // Get the delimiter that was found.
    var matchedDelim = match[1];

    // Check to see if the given delimiter has a length
    // (is not the start of string) and if it matches
    // field delimiter. If it does not, then we can expect
    // this delimiter to be a row delimiter.
    if (matchedDelim.length && (matchedDelim != opts.delim)) {
      // Since we have reached a new row of data,
      // add an empty row to our data array.
      arr.push([]);
    }

    // Now that we have our delimiter out of the way,
    // let's check to see which kind of value we
    // captured (quoted or unquoted).
    if (match[2]) {

      // We found a quoted value. When we capture
      // this value, unescape any double quotes.
      value = match[2].replace(/""/g, '"');
    } else {

      // We found a non-quoted value.
      value = match[3];
    }

    // Now that we have our value string, let's add
    // it to the data array.
    arr[arr.length - 1].push(value);
  }

  // Return the parsed data.
  return arr;
}
function toArray ( str , options ) { var opts = extend ( { delim : ',' } , options ) ; // Create a regular expression to parse the CSV values. var re = new RegExp ( // Delimiters. '(\\' + opts . delim + '|\\n|^)' + // Quoted fields. '(?:"([^"]*(?:""[^"]*)*)"|' + // Standard fields. '([^"\\' + opts . delim + '\\n]*))' , 'gi' ) ; // Create an array to hold our data. Give the array // a default empty first row. var arr = [ [ ] ] ; // Create an array to hold our individual pattern // matching groups. var match = null ; var value ; // Keep looping over the regular expression matches // until we can no longer find a match. while ( match = re . exec ( str ) ) { // Get the delimiter that was found. var matchedDelim = match [ 1 ] ; // Check to see if the given delimiter has a length // (is not the start of string) and if it matches // field delimiter. If it does not, then we can expect // this delimiter to be a row delimiter. if ( matchedDelim . length && ( matchedDelim != opts . delim ) ) { // Since we have reached a new row of data, // add an empty row to our data array. arr . push ( [ ] ) ; } // Now that we have our delimiter out of the way, // let's check to see which kind of value we // captured (quoted or unquoted). if ( match [ 2 ] ) { // We found a quoted value. When we capture // this value, unescape any double quotes. value = match [ 2 ] . replace ( / "" / g , '"' ) ; } else { // We found a non-quoted value. value = match [ 3 ] ; } // Now that we have our value string, let's add // it to the data array. arr [ arr . length - 1 ] . push ( value ) ; } // Return the parsed data. return arr ; }
Parse a delimited string into an array of arrays.

The default delimiter is `comma`, this can be
overriden by passed a different delimiter on
the `delim` option as a second argument.

This Function is from [Ben Nadel] by way of [Mr Data Converer]

@param  {String} `str`
@param  {Object} `options`
@return {Array}
Parse a delimited string into an array of arrays .