;(function(e){functionn(e){e.delimeter=e.delimiter||t.delimiter;e.header=typeofe.header==="undefined"?t.header:e.header;if(e.delimiter.length>1)e.delimiter=e.delimiter[0];returne}functionr(e,t){functionu(e){returne?{fields:[],rows:[]}:[[]]}functiona(){return{i:0,line:1,field:0,fieldVal:"",ch:"",inQuotes:false,parsed:u(t.header)}}functionf(){if(o.i<r.length-1){if(r[o.i+1]=='"'&&o.inQuotes){o.fieldVal+='"';o.i++}elseif(r[o.i+1]!=i.delimiter&&o.inQuotes)returng("Unescaped quote in field value")}o.inQuotes=!o.inQuotes}functionl(){c()}functionc(){o.fieldVal+=o.ch}functionh(){if(o.ch==i.delimiter){p()}elseif(o.ch=="\n"){p();d()}else{c()}}functionp(){if(i.header){if(o.line==1){o.parsed.fields.push(o.fieldVal)}else{vare=o.parsed.rows[o.parsed.rows.length-1];vart=o.parsed.fields[o.field];if(t)e[t]=o.fieldVal;elseg("Too many fields; expected "+o.parsed.fields.length+" fields, found extra value: '"+o.fieldVal+"'")}}elseo.parsed[o.parsed.length-1].push(o.fieldVal);o.fieldVal="";o.field++}functiond(){v();if(i.header){m();if(o.line>0)o.parsed.rows.push({})}elseo.parsed.push([]);o.line++;o.field=0}functionv(){if(i.header){if(o.line==1){if(o.parsed.fields.length==1&&o.parsed.fields[0].length==0){o.parsed.fields=[];o.line--}}else{vare=o.parsed.rows[o.parsed.rows.length-1];if(!e[o.parsed.fields[0]])o.parsed.rows.splice(o.parsed.rows.length-1,1)}}else{vare=o.parsed[o.parsed.length-1];if(e.length==0||e[0].length==0)o.parsed.splice(o.parsed.length-1,1)}}functionm(){if(!i.header)returntrue;if(o.parsed.rows.length==0)returntrue;vare=o.parsed.fields.length;vart=Object.keys(o.parsed.rows[o.parsed.rows.length-1]).length;if(e!=t)returng("Too few fields; expected "+e+" fields, parsed "+t);returntrue}functiong(e){s.push({message:e,line:o.line,row:i.header?o.parsed.rows.length-1:o.parsed.length-1,index:o.i});returnfalse}varn=this;varr=e;vari=t;vars=[];varo=a();this.parse=function(e){if(typeofe==="object")n.setConfig(e);elseif(typeofe==="string")n.setInput(e);s=[];o=a();for(o.i=0;o.i<r.length;o.i++){o.ch=r[o.i];if(o.ch=='"')f();elseif(o.inQuotes)l();elseh()}p();v();m();if(o.inQuotes)g("Unescaped or mismatched quotes");returnn.getParsed()};this.getDelimiter=function(){returnt.delimiter};this.setDelimiter=function(e){e=e||",";i.delimiter=e[0]};this.setConfig=function(e){if(typeofe.header!=="undefined"&&e.header!=t.header||typeofe.delimiter!=="undefined"&&e.delimiter!=t.delimiter){o.parsed=u(e.header)}i=e};this.getInput=function(){returnr};this.setInput=function(e){r=e};this.getParsed=function(){returno.parsed};this.getErrors=function(){returns}}vart={delimiter:",",header:true};e.parse=function(e,t){t=n(t);vari=newr(e,t);return{results:i.parse(),errors:i.getErrors()}}})(jQuery)
;(function(e){functionn(e){e.delimeter=e.delimiter||t.delimiter;e.header=typeofe.header==="undefined"?t.header:e.header;if(e.delimiter=='"'||e.delimiter=="\n")e.delimiter=t.delimiter;if(e.delimiter.length>1)e.delimiter=e.delimiter[0];returne}functionr(e,t){functionu(e){returne?{fields:[],rows:[]}:[[]]}functiona(){return{i:0,line:1,field:0,fieldVal:"",ch:"",inQuotes:false,parsed:u(t.header)}}functionf(){if(o.i<r.length-1){if(r[o.i+1]=='"'&&o.inQuotes){o.fieldVal+='"';o.i++}elseif(r[o.i+1]!=i.delimiter&&o.inQuotes)returng("Unescaped quote in field value")}o.inQuotes=!o.inQuotes}functionl(){c()}functionc(){o.fieldVal+=o.ch}functionh(){if(o.ch==i.delimiter){p()}elseif(o.ch=="\n"){p();d()}else{c()}}functionp(){if(i.header){if(o.line==1){o.parsed.fields.push(o.fieldVal)}else{vare=o.parsed.rows[o.parsed.rows.length-1];vart=o.parsed.fields[o.field];if(t)e[t]=o.fieldVal;elseg("Too many fields; expected "+o.parsed.fields.length+" fields, found extra value: '"+o.fieldVal+"'")}}elseo.parsed[o.parsed.length-1].push(o.fieldVal);o.fieldVal="";o.field++}functiond(){v();if(i.header){m();if(o.line>0)o.parsed.rows.push({})}elseo.parsed.push([]);o.line++;o.field=0}functionv(){if(i.header){if(o.line==1){if(o.parsed.fields.length==1&&o.parsed.fields[0].length==0){o.parsed.fields=[];o.line--}}else{vare=o.parsed.rows[o.parsed.rows.length-1];if(!e[o.parsed.fields[0]])o.parsed.rows.splice(o.parsed.rows.length-1,1)}}else{vare=o.parsed[o.parsed.length-1];if(e.length==0||e[0].length==0)o.parsed.splice(o.parsed.length-1,1)}}functionm(){if(!i.header)returntrue;if(o.parsed.rows.length==0)returntrue;vare=o.parsed.fields.length;vart=Object.keys(o.parsed.rows[o.parsed.rows.length-1]).length;if(e!=t)returng("Too few fields; expected "+e+" fields, parsed "+t);returntrue}functiong(e){s.push({message:e,line:o.line,row:i.header?o.parsed.rows.length-1:o.parsed.length-1,index:o.i});returnfalse}varn=this;varr=e;vari=t;vars=[];varo=a();this.parse=function(e){if(typeofe==="object")n.setConfig(e);elseif(typeofe==="string")n.setInput(e);s=[];o=a();for(o.i=0;o.i<r.length;o.i++){o.ch=r[o.i];if(o.ch=='"')f();elseif(o.inQuotes)l();elseh()}p();v();m();if(o.inQuotes)g("Unescaped or mismatched quotes");returnn.getParsed()};this.getDelimiter=function(){returnt.delimiter};this.setDelimiter=function(e){vart=",";e=e?e=='"'||e=="\n"?t:e:t;i.delimiter=e[0]};this.setConfig=function(e){if(typeofe.header!=="undefined"&&e.header!=t.header||typeofe.delimiter!=="undefined"&&e.delimiter!=t.delimiter){o.parsed=u(e.header)}i=e};this.getInput=function(){returnr};this.setInput=function(e){r=e};this.getParsed=function(){returno.parsed};this.getErrors=function(){returns}}vart={delimiter:",",header:true};e.parse=function(e,t){t=n(t);vari=newr(e,t);return{results:i.parse(),errors:i.getErrors()}}})(jQuery);