;(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(u.i-1)||u.i==0;vart=u.i<r.length-1&&d(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{S("Quotes","UnexpectedQuotes","Unexpected quotes")}}functionc(){h()}functionh(){u.fieldVal+=u.ch}functionp(){if(u.ch==i.delimiter)m();elseif(u.ch=="\r"&&u.i<r.length-1&&r[u.i+1]=="\n"){y();u.i++}elseif(u.ch=="\n")y();elseh()}functiond(e){if(e>=r.length)returnfalse;vart=r[e];if(t==i.delimiter||t=="\n"||t=="\r"&&e<r.length-1&&r[e+1]=="\n")returntrue;elsereturnfalse}functionv(e){if(e>=r.length)returnfalse;if(e<r.length-1)returnr[e]=="\n"||r[e]=="\r"&&r[e+1]=="\n";elsereturnr[e]=="\n"}functionm(){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=b(u.fieldVal);e[t]=u.fieldVal}else{if(typeofe.__parsed_extra==="undefined")e.__parsed_extra=[];e.__parsed_extra.push(u.fieldVal)}}}else{if(i.dynamicTyping)u.fieldVal=b(u.fieldVal);u.parsed[u.parsed.length-1].push(u.fieldVal)}u.fieldVal="";u.field++}functiong(){m();vare=w();if(!e&&i.header)E()}functiony(){g();if(i.header&&u.lineNum>0)u.parsed.rows.push({});elseu.parsed.push([]);u.lineNum++;u.line="";u.field=0}functionb(e){vart=o.floats.test(e);returnt?parseFloat(e):e}functionw(){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}functionE(){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(t<e)returnS("FieldMismatch","TooFewFields","Too few fields: expected "+e+" fields but parsed "+t);elseif(t>e)returnS("FieldMismatch","TooManyFields","Too many fields: expected "+e+" fields but parsed "+t);returntrue}functionS(e,t,n){s.push({type:e,code:t,message:n,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()}g();if(u.inQuotes)S("Quotes","MissingQuotes","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);