You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
6 lines
14 KiB
6 lines
14 KiB
/*! |
|
Papa Parse |
|
v4.0.7 |
|
https://github.com/mholt/PapaParse |
|
*/ |
|
!function(a){"use strict";function b(b,c){var g=p?c:l(c),h=g.worker&&Papa.WORKERS_SUPPORTED&&o;if(h){var j=i();j.userStep=g.step,j.userChunk=g.chunk,j.userComplete=g.complete,j.userError=g.error,g.step=n(g.step),g.chunk=n(g.chunk),g.complete=n(g.complete),g.error=n(g.error),delete g.worker,j.postMessage({input:b,config:g,workerId:j.id})}else if("string"==typeof b){if(!g.download){var k=new f(g),m=k.parse(b);return m}var q=new d(g);q.stream(b)}else if(a.File&&b instanceof File||b instanceof Object)if(g.step||g.chunk){var q=new e(g);q.stream(b)}else{var k=new f(g);if(p){var r=new FileReaderSync,s=r.readAsText(b,g.encoding);return k.parse(s)}r=new FileReader,r.onload=function(a){{var b=new f(g);b.parse(a.target.result)}},r.onerror=function(){n(g.error)&&g.error(r.error,b)},r.readAsText(b,g.encoding)}}function c(b,c){function d(){"object"==typeof c&&("string"==typeof c.delimiter&&1==c.delimiter.length&&-1==a.Papa.BAD_DELIMITERS.indexOf(c.delimiter)&&(j=c.delimiter),("boolean"==typeof c.quotes||c.quotes instanceof Array)&&(i=c.quotes),"string"==typeof c.newline&&(k=c.newline))}function e(a){if("object"!=typeof a)return[];var b=[];for(var c in a)b.push(c);return b}function f(a,b){var c="";"string"==typeof a&&(a=JSON.parse(a)),"string"==typeof b&&(b=JSON.parse(b));var d=a instanceof Array&&a.length>0,e=!(b[0]instanceof Array);if(d){for(var f=0;f<a.length;f++)f>0&&(c+=j),c+=g(a[f],f);b.length>0&&(c+=k)}for(var h=0;h<b.length;h++){for(var i=d?a.length:b[h].length,l=0;i>l;l++){l>0&&(c+=j);var m=d&&e?a[l]:l;c+=g(b[h][m],l)}h<b.length-1&&(c+=k)}return c}function g(b,c){if("undefined"==typeof b||null===b)return"";b=b.toString().replace(/"/g,'""');var d="boolean"==typeof i&&i||i instanceof Array&&i[c]||h(b,a.Papa.BAD_DELIMITERS)||b.indexOf(j)>-1||" "==b.charAt(0)||" "==b.charAt(b.length-1);return d?'"'+b+'"':b}function h(a,b){for(var c=0;c<b.length;c++)if(a.indexOf(b[c])>-1)return!0;return!1}var i=!1,j=",",k="\r\n";if(d(),"string"==typeof b&&(b=JSON.parse(b)),b instanceof Array){if(!b.length||b[0]instanceof Array)return f(null,b);if("object"==typeof b[0])return f(e(b[0]),b)}else if("object"==typeof b)return"string"==typeof b.data&&(b.data=JSON.parse(b.data)),b.data instanceof Array&&(b.fields||(b.fields=b.data[0]instanceof Array?b.fields:e(b.data[0])),b.data[0]instanceof Array||"object"==typeof b.data[0]||(b.data=[b.data])),f(b.fields||[],b.data||[]);throw"exception: Unable to serialize unrecognized input"}function d(b){function c(){if(l)return void d();if(i=new XMLHttpRequest,p||(i.onload=d,i.onerror=e),i.open("GET",j,!p),b.step||b.chunk){var a=s+r.chunkSize-1;t&&a>t&&(a=t),i.setRequestHeader("Range","bytes="+s+"-"+a)}try{i.send()}catch(c){e(c.message)}p&&0==i.status?e():s+=r.chunkSize}function d(){if(4==i.readyState){if(i.status<200||i.status>=400)return void e();if(v+=w+i.responseText,w="",l=!b.step&&!b.chunk||s>g(i),!l){var c=v.lastIndexOf("\r");if(-1==c&&(c=v.lastIndexOf("\n")),-1==c)return void k();w=v.substring(c+1),v=v.substring(0,c)}var d=q.parse(v);v="",d&&d.data&&(u+=d.data.length);var f=l||r.preview&&u>=r.preview;p?a.postMessage({results:d,workerId:Papa.WORKER_ID,finished:f}):n(b.chunk)&&(b.chunk(d,q),d=void 0),n(o)&&f&&o(d),f||d&&d.meta.paused||k()}}function e(c){var d=i.statusText||c;n(b.error)?b.error(d):p&&b.error&&a.postMessage({workerId:Papa.WORKER_ID,error:d,finished:!1})}function g(a){var b=a.getResponseHeader("Content-Range");return parseInt(b.substr(b.lastIndexOf("/")+1))}function h(a){r=m(a),o=r.complete,r.complete=void 0,r.chunkSize=parseInt(r.chunkSize),q=new f(r),q.streamer=this}b=b||{},b.chunkSize||(b.chunkSize=Papa.RemoteChunkSize);var i,j,k,l,o,q,r,s=0,t=0,u=0,v="",w="";h(b),this.resume=function(){paused=!1,k()},this.finished=function(){return l},this.pause=function(){paused=!0},this.abort=function(){l=!0,n(o)&&o({data:[],errors:[],meta:{aborted:!0}})},this.stream=function(a){j=a,(k=p?function(){c(),d()}:function(){c()})()}}function e(b){function c(){l||r.preview&&!(v<r.preview)||d()}function d(){var a=Math.min(s+r.chunkSize,i.size),c=k.readAsText(j.call(i,s,a),b.encoding);y||e({target:{result:c}})}function e(d){if(s+=r.chunkSize,t+=u+d.target.result,u="",l=s>=i.size,!l){var e=t.lastIndexOf("\r");if(-1==e&&(e=t.lastIndexOf("\n")),-1==e)return void c();u=t.substring(e+1),t=t.substring(0,e)}var f=q.parse(t);t="",f&&f.data&&(v+=f.data.length);var g=l||r.preview&&v>=r.preview;if(p)a.postMessage({results:f,workerId:Papa.WORKER_ID,finished:g});else if(n(b.chunk)){if(b.chunk(f,x,i),w)return;f=void 0}n(o)&&g&&o(f),g||f&&f.meta.paused||c()}function g(){n(b.error)?b.error(k.error,i):p&&b.error&&a.postMessage({workerId:Papa.WORKER_ID,error:k.error,file:i,finished:!1})}function h(a){r=m(a),o=r.complete,r.complete=void 0,r.chunkSize=parseInt(r.chunkSize),q=new f(r),q.streamer=this}b=b||{},b.chunkSize||(b.chunkSize=Papa.LocalChunkSize);var i,j,k,c,j,l,o,q,r,s=0,t="",u="",v=0,w=!1,x=this;h(b);var y="undefined"!=typeof FileReader;this.stream=function(a){i=a,j=i.slice||i.webkitSlice||i.mozSlice,y?(k=new FileReader,k.onload=e,k.onerror=g):k=new FileReaderSync,c()},this.finished=function(){return l},this.pause=function(){w=!0},this.resume=function(){w=!1,c()},this.abort=function(){l=!0,n(o)&&o({data:[],errors:[],meta:{aborted:!0}})}}function f(a){function b(){if(u&&o&&(j("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+Papa.DefaultDelimiter+"'"),o=!1),a.skipEmptyLines)for(var b=0;b<u.data.length;b++)1==u.data[b].length&&""==u.data[b][0]&&u.data.splice(b--,1);return c()&&d(),e()}function c(){return a.header&&0==t.length}function d(){if(u){for(var a=0;c()&&a<u.data.length;a++)for(var b=0;b<u.data[a].length;b++)t.push(u.data[a][b]);u.data.splice(0,1)}}function e(){if(!u||!a.header&&!a.dynamicTyping)return u;for(var b=0;b<u.data.length;b++){for(var c={},d=0;d<u.data[b].length;d++){if(a.dynamicTyping){var e=u.data[b][d];u.data[b][d]="true"==e?!0:"false"==e?!1:i(e)}a.header&&(d>=t.length?(c.__parsed_extra||(c.__parsed_extra=[]),c.__parsed_extra.push(u.data[b][d])):c[t[d]]=u.data[b][d])}a.header&&(u.data[b]=c,d>t.length?j("FieldMismatch","TooManyFields","Too many fields: expected "+t.length+" fields but parsed "+d,b):d<t.length&&j("FieldMismatch","TooFewFields","Too few fields: expected "+t.length+" fields but parsed "+d,b))}return a.header&&u.meta&&(u.meta.fields=t),u}function f(b){for(var c,d,e,f=[","," ","|",";",Papa.RECORD_SEP,Papa.UNIT_SEP],h=0;h<f.length;h++){var i=f[h],j=0,k=0;e=void 0;for(var l=new g({delimiter:i,preview:10}).parse(b),m=0;m<l.data.length;m++){var n=l.data[m].length;k+=n,"undefined"!=typeof e?n>1&&(j+=Math.abs(n-e),e=n):e=n}k/=l.data.length,("undefined"==typeof d||d>j)&&k>1.99&&(d=j,c=i)}return a.delimiter=c,{successful:!!c,bestDelimiter:c}}function h(a){a=a.substr(0,1048576);var b=a.split("\r");if(1==b.length)return"\n";for(var c=0,d=0;d<b.length;d++)"\n"==b[d][0]&&c++;return c>=b.length/2?"\r\n":"\r"}function i(a){var b=p.test(a);return b?parseFloat(a):a}function j(a,b,c,d){u.errors.push({type:a,code:b,message:c,row:d})}var k,l,o,p=/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i,q=this,r=0,s=!1,t=[],u={data:[],errors:[],meta:{}};if(n(a.step)){var v=a.step;a.step=function(d){if(u=d,c())b();else{if(b(),0==u.data.length)return;r+=d.data.length,a.preview&&r>a.preview?l.abort():v(u,q)}}}this.parse=function(c){if(a.newline||(a.newline=h(c)),o=!1,!a.delimiter){var d=f(c);d.successful?a.delimiter=d.bestDelimiter:(o=!0,a.delimiter=Papa.DefaultDelimiter),u.meta.delimiter=a.delimiter}var e=m(a);return a.preview&&a.header&&e.preview++,k=c,l=new g(e),u=l.parse(k),b(),!n(a.complete)||s||q.streamer&&!q.streamer.finished()||a.complete(u),s?{meta:{paused:!0}}:u||{meta:{paused:!1}}},this.pause=function(){s=!0,l.abort(),k=k.substr(l.getCharIndex())},this.resume=function(){s=!1,l=new g(a),l.parse(k),s||(q.streamer&&!q.streamer.finished()?q.streamer.resume():n(a.complete)&&a.complete(u))},this.abort=function(){l.abort(),n(a.complete)&&a.complete(u),k=""}}function g(a){a=a||{};var b=a.delimiter,c=a.newline,d=a.comments,e=a.step,f=a.preview,g=a.fastMode;if(("string"!=typeof b||1!=b.length||Papa.BAD_DELIMITERS.indexOf(b)>-1)&&(b=","),d===b)throw"Comment character same as delimiter";d===!0?d="#":("string"!=typeof d||Papa.BAD_DELIMITERS.indexOf(d)>-1)&&(d=!1),"\n"!=c&&"\r"!=c&&"\r\n"!=c&&(c="\n");var h=0,i=!1;this.parse=function(a){function j(){return u.push(a.substr(h)),s.push(u),h=n,r&&m(),l()}function k(b){s.push(u),u=[],h=b,y=a.indexOf(c,h)}function l(a){return{data:s,errors:t,meta:{delimiter:b,linebreak:c,aborted:i,truncated:!!a}}}function m(){e(l()),s=[],t=[]}if("string"!=typeof a)throw"Input must be a string";var n=a.length,o=b.length,p=c.length,q=d.length,r="function"==typeof e;h=0;var s=[],t=[],u=[];if(!a)return l();if(g){for(var v=a.split(c),w=0;w<v.length;w++)if(!d||v[w].substr(0,q)!=d){if(r){if(s=[v[w].split(b)],m(),i)return l()}else s.push(v[w].split(b));if(f&&w>=f)return s=s.slice(0,f),l(!0)}return l()}for(var x=a.indexOf(b,h),y=a.indexOf(c,h);;)if('"'!=a[h])if(d&&0===u.length&&a.substr(h,q)===d){if(-1==y)return l();h=y+p,y=a.indexOf(c,h),x=a.indexOf(b,h)}else if(-1!==x&&(y>x||-1===y))u.push(a.substring(h,x)),h=x+o,x=a.indexOf(b,h);else{if(-1===y)break;if(u.push(a.substring(h,y)),k(y+p),r&&(m(),i))return l();if(f&&s.length>=f)return l(!0)}else{var z=h;for(h++;;){var z=a.indexOf('"',z+1);if(-1===z)return t.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:s.length,index:h}),j();if(z===n-1)return u.push(a.substring(h,z).replace(/""/g,'"')),s.push(u),r&&m(),l();if('"'!=a[z+1]){if(a[z+1]==b){u.push(a.substring(h,z).replace(/""/g,'"')),h=z+1+o,x=a.indexOf(b,h),y=a.indexOf(c,h);break}if(a.substr(z+1,p)===c){if(u.push(a.substring(h,z).replace(/""/g,'"')),k(z+1+p),x=a.indexOf(b,h),r&&(m(),i))return l();if(f&&s.length>=f)return l(!0);break}}else z++}}return j()},this.abort=function(){i=!0},this.getCharIndex=function(){return h}}function h(){var a="worker"+String(Math.random()).substr(2);return document.write('<script id="'+a+'"></script>'),document.getElementById(a).previousSibling.src}function i(){if(!Papa.WORKERS_SUPPORTED)return!1;var b=new a.Worker(o);return b.onmessage=j,b.id=r++,q[b.id]=b,b}function j(a){var b=a.data,c=q[b.workerId];if(b.error)c.userError(b.error,b.file);else if(b.results&&b.results.data)if(n(c.userStep)){for(var d=0;d<b.results.data.length;d++)c.userStep({data:[b.results.data[d]],errors:b.results.errors,meta:b.results.meta});delete b.results}else n(c.userChunk)&&(c.userChunk(b.results,b.file),delete b.results);b.finished&&(n(q[b.workerId].userComplete)&&q[b.workerId].userComplete(b.results),q[b.workerId].terminate(),delete q[b.workerId])}function k(b){var c=b.data;if("undefined"==typeof Papa.WORKER_ID&&c&&(Papa.WORKER_ID=c.workerId),"string"==typeof c.input)a.postMessage({workerId:Papa.WORKER_ID,results:Papa.parse(c.input,c.config),finished:!0});else if(a.File&&c.input instanceof File||c.input instanceof Object){var d=Papa.parse(c.input,c.config);d&&a.postMessage({workerId:Papa.WORKER_ID,results:d,finished:!0})}}function l(a){"object"!=typeof a&&(a={});var b=m(a);return("string"!=typeof b.delimiter||1!=b.delimiter.length||Papa.BAD_DELIMITERS.indexOf(b.delimiter)>-1)&&(b.delimiter=s.delimiter),"\n"!=b.newline&&"\r"!=b.newline&&"\r\n"!=b.newline&&(b.newline=s.newline),"boolean"!=typeof b.header&&(b.header=s.header),"boolean"!=typeof b.dynamicTyping&&(b.dynamicTyping=s.dynamicTyping),"number"!=typeof b.preview&&(b.preview=s.preview),"function"!=typeof b.step&&(b.step=s.step),"function"!=typeof b.complete&&(b.complete=s.complete),"function"!=typeof b.error&&(b.error=s.error),"string"!=typeof b.encoding&&(b.encoding=s.encoding),"boolean"!=typeof b.worker&&(b.worker=s.worker),"boolean"!=typeof b.download&&(b.download=s.download),"boolean"!=typeof b.skipEmptyLines&&(b.skipEmptyLines=s.skipEmptyLines),"boolean"!=typeof b.fastMode&&(b.fastMode=s.fastMode),b}function m(a){if("object"!=typeof a)return a;var b=a instanceof Array?[]:{};for(var c in a)b[c]=m(a[c]);return b}function n(a){return"function"==typeof a}var o,p=!a.document,q={},r=0,s={delimiter:"",newline:"",header:!1,dynamicTyping:!1,preview:0,step:void 0,encoding:"",worker:!1,comments:!1,complete:void 0,error:void 0,download:!1,chunk:void 0,skipEmptyLines:!1,fastMode:!1};if(a.Papa={},a.Papa.parse=b,a.Papa.unparse=c,a.Papa.RECORD_SEP=String.fromCharCode(30),a.Papa.UNIT_SEP=String.fromCharCode(31),a.Papa.BYTE_ORDER_MARK="",a.Papa.BAD_DELIMITERS=["\r","\n",'"',a.Papa.BYTE_ORDER_MARK],a.Papa.WORKERS_SUPPORTED=!!a.Worker,a.Papa.LocalChunkSize=10485760,a.Papa.RemoteChunkSize=5242880,a.Papa.DefaultDelimiter=",",a.Papa.Parser=g,a.Papa.ParserHandle=f,a.Papa.NetworkStreamer=d,a.Papa.FileStreamer=e,a.jQuery){var t=a.jQuery;t.fn.parse=function(b){function c(){if(0==g.length)return void(n(b.complete)&&b.complete());var a=g[0];if(n(b.before)){var c=b.before(a.file,a.inputElem);if("object"==typeof c){if("abort"==c.action)return void d("AbortError",a.file,a.inputElem,c.reason);if("skip"==c.action)return void e();"object"==typeof c.config&&(a.instanceConfig=t.extend(a.instanceConfig,c.config))}else if("skip"==c)return void e()}var f=a.instanceConfig.complete;a.instanceConfig.complete=function(b){n(f)&&f(b,a.file,a.inputElem),e()},Papa.parse(a.file,a.instanceConfig)}function d(a,c,d,e){n(b.error)&&b.error({name:a},c,d,e)}function e(){g.splice(0,1),c()}var f=b.config||{},g=[];return this.each(function(){var b="INPUT"==t(this).prop("tagName").toUpperCase()&&"file"==t(this).attr("type").toLowerCase()&&a.FileReader;if(!b||!this.files||0==this.files.length)return!0;for(var c=0;c<this.files.length;c++)g.push({file:this.files[c],inputElem:this,instanceConfig:t.extend({},f)})}),c(),this}}p?a.onmessage=k:Papa.WORKERS_SUPPORTED&&(o=h())}(this); |