;(function(e){"use strict";functionn(e){e.delimiter=e.delimiter||t.delimiter;e.header=typeofe.header==="undefined"?t.header:e.header;e.dynamicTyping=typeofe.dynamicTyping==="undefined"?t.dynamicTyping:e.dynamicTyping;if(e.delimiter=='"'||e.delimiter=="\n")e.delimiter=t.delimiter;if(e.delimiter.length>1)e.delimiter=e.delimiter[0];returne}functionr(e,t){functiona(e){returne?{fields:[],rows:[]}:[[]]}functionf(){return{i:0,lineNum:1,field:0,fieldVal:"",line:"",ch:"",inQuotes:false,parsed:a(t.header)}}functionl(){vare=u.i>0&&d(r[u.i-1])||u.i==0;vart=u.i<r.length-1&&d(r[u.i+1])||u.i==r.length-1;varn=u.i<r.length-1&&r[u.i+1]=='"';if(u.inQuotes&&n){u.fieldVal+='"';u.i++}elseif(e||t){u.inQuotes=!u.inQuotes}else{E("Unexpected quotes")}}functionc(){h()}functionh(){u.fieldVal+=u.ch}functionp(){if(u.ch==i.delimiter)v();elseif(u.ch=="\r"&&u.i<r.length-1&&r[u.i+1]=="\n"){g();u.i++}elseif(u.ch=="\n")g();elseh()}functiond(e){returne==i.delimiter||e=="\n"}functionv(){if(i.header){if(u.lineNum==1)u.parsed.fields.push(u.fieldVal);else{vare=u.parsed.rows[u.parsed.rows.length-1];vart=u.parsed.fields[u.field];if(t){if(i.dynamicTyping)u.fieldVal=y(u.fieldVal);e[t]=u.fieldVal}else{if(typeofe.__parsed_extra==="undefined")e.__parsed_extra=[];e.__parsed_extra.push(u.fieldVal);E("Too many fields; expected "+u.parsed.fields.length+" fields, found extra value: '"+u.fieldVal+"'")}}}else{if(i.dynamicTyping)u.fieldVal=y(u.fieldVal);u.parsed[u.parsed.length-1].push(u.fieldVal)}u.fieldVal="";u.field++}functionm(){v();vare=b();if(!e&&i.header)w()}functiong(){m();if(i.header&&u.lineNum>0)u.parsed.rows.push({});elseu.parsed.push([]);u.lineNum++;u.line="";u.field=0}functiony(e){vart=o.floats.test(e);returnt?parseFloat(e):e}functionb(){if(o.empty.test(u.line)){if(i.header){if(u.lineNum==1){u.parsed.fields=[];u.lineNum--}elseu.parsed.rows.splice(u.parsed.rows.length-1,1)}elseu.parsed.splice(u.parsed.length-1,1);returntrue}returnfalse}functionw(){if(!i.header)returntrue;if(u.parsed.rows.length==0)returntrue;vare=u.parsed.fields.length;vart=0;varn=u.parsed.rows[u.parsed.rows.length-1];for(varrinn)if(n.hasOwnProperty(r))t++;if(e!=t)returnE("Too few fields; expected "+e+" fields, parsed "+t);returntrue}functionE(e){s.push({message:e,line:u.lineNum,row:i.header?u.parsed.rows.length-1:u.parsed.length-1,index:u.i});returnfalse}varn=this;varr=e;vari=t;vars=[];varo={floats:/^-?\d+(\.\d+)?$/,empty:/^\s*$/};varu=f();this.parse=function(e){if(typeofe==="object")n.setConfig(e);elseif(typeofe==="string")n.setInput(e);s=[];u=f();for(u.i=0;u.i<r.length;u.i++){u.ch=r[u.i];u.line+=u.ch;if(u.ch=='"')l();elseif(u.inQuotes)c();elsep()}m();if(u.inQuotes)E("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){u.parsed=a(e.header)}i=e};this.getInput=function(){returnr};this.setInput=function(e){r=e};this.getParsed=function(){returnu.parsed};this.getErrors=function(){returns}}vart={delimiter:",",header:true,dynamicTyping:false};e.parse=function(e,t){t=n(t);vari=newr(e,t);return{results:i.parse(),errors:i.getErrors()}}})(jQuery);