|
|
|
;(function(e){"use strict";function u(r,i){var s=t?i:g(i);var o=s.worker&&Papa.WORKERS_SUPPORTED&&n;if(o){var u=d();u.userStep=s.step;u.userChunk=s.chunk;u.userComplete=s.complete;u.userError=s.error;s.step=b(s.step);s.chunk=b(s.chunk);s.complete=b(s.complete);s.error=b(s.error);delete s.worker;u.postMessage({input:r,config:s,workerId:u.id})}else{if(typeof r==="string"){if(s.download){var a=new f(s);a.stream(r)}else{var h=new c(s);var p=h.parse(r);return p}}else if(e.File&&r instanceof File||r instanceof Object){if(s.step||s.chunk){var a=new l(s);a.stream(r)}else{var h=new c(s);if(t){var v=new FileReaderSync;var m=v.readAsText(r,s.encoding);return h.parse(m)}else{v=new FileReader;v.onload=function(e){var t=new c(s);var n=t.parse(e.target.result)};v.onerror=function(){if(b(s.error))s.error(v.error,r)};v.readAsText(r,s.encoding)}}}}}function a(t,n){function a(){if(typeof n!=="object")return;if(typeof n.delimiter==="string"&&n.delimiter.length==1&&e.Papa.BAD_DELIMITERS.indexOf(n.delimiter)==-1){o=n.delimiter}if(typeof n.quotes==="boolean"||n.quotes instanceof Array)s=n.quotes;if(typeof n.newline==="string")u=n.newline}function f(e){if(typeof e!=="object")return[];var t=[];for(var n in e)t.push(n);return t}function l(e,t){var n="";if(typeof e==="string")e=JSON.parse(e);if(typeof t==="string")t=JSON.parse(t);var r=e instanceof Array&&e.length>0;var i=!(t[0]instanceof Array);if(r){for(var s=0;s<e.length;s++){if(s>0)n+=o;n+=c(e[s],s)}if(t.length>0)n+=u}for(var a=0;a<t.length;a++){var f=r?e.length:t[a].length;for(var l=0;l<f;l++){if(l>0)n+=o;var h=r&&i?e[l]:l;n+=c(t[a][h],l)}if(a<t.length-1)n+=u}return n}function c(t,n){if(typeof t==="undefined"||t===null)return"";t=t.toString().replace(/"/g,'""');var r=typeof s==="boolean"&&s||s instanceof Array&&s[n]||h(t,e.Papa.BAD_DELIMITERS)||t.indexOf(o)>-1||t.charAt(0)==" "||t.charAt(t.length-1)==" ";return r?'"'+t+'"':t}function h(e,t){for(var n=0;n<t.length;n++)if(e.indexOf(t[n])>-1)return true;return false}var r="";var i=[];var s=false;var o=",";var u="\r\n";a();if(typeof t==="string")t=JSON.parse(t);if(t instanceof Array){if(!t.length||t[0]instanceof Array)return l(null,t);else if(typeof t[0]==="object")return l(f(t[0]),t)}else if(typeof t==="object"){if(typeof t.data==="string")t.data=JSON.parse(t.data);if(t.data instanceof Array){if(!t.fields)t.fields=t.data[0]instanceof Array?t.fields:f(t.data[0]);if(!(t.data[0]instanceof Array)&&typeof t.data[0]!=="object")t.data=[t.data]}return l(t.fields||[],t.data||[])}throw"exception: Unable to serialize unrecognized input"}function f(n){function m(){if(h){g();return}a=new XMLHttpRequest;if(!t){a.onload=g;a.onerror=w}a.open("GET",f,!t);if(n.step||n.chunk){var e=r+v.chunkSize-1;if(i&&e>i)e=i;a.setRequestHeader("Range","bytes="+r+"-"+e)}try{a.send()}catch(s){w(s.message)}if(t&&a.status==0)w();else r+=v.chunkSize}function g(){if(a.readyState!=4)return;if(a.status<200||a.status>=400){w();return}o+=u+a.responseText;u="";h=!n.step&&!n.chunk||r>E(a);if(!h){var i=o.lastIndexOf("\r");if(i==-1)i=o.lastIndexOf("\n");if(i!=-1){u=o.substring(i+1);o=o.substring(0,i)}else{l();return}}var f=d.parse(o);o="";if(f&&f.data)s+=f.data.length;var c=h||v.preview&&s>=v.preview;if(t){e.postMessage({results:f,workerId:Papa.WORKER_ID,finished:c})}else if(b(n.chunk)){n.chunk(f,d);f=undefined}if(b(p)&&c)p(f);if(!c&&(!f||!f.meta.paused))l()}function w(r){var i=a.statusText||r;if(b(n.error))n.error(i);else if(t&&n.error){e.postMessage({workerId:Papa.WORKER_ID,error:i,finished:false})}}function E(e){var t=e.getResponseHeader("Content-Range");return parseInt(t.substr(t.lastIndexOf("/")+1))}function S(e){v=y(e);p=v.complete;v.complete=undefined;v.chunkSize=parseInt(v.chunkSize);d=new c(v);d.streamer=this}n=n||{};if(!n.chunkSize)n.chunkSize=Papa.RemoteChunkSize;var r=0,i=0,s=0;var o="";var u="";var a,f,l,h;var p,d,v;S(n);this.resume=function(){paused=false;l()};this.finished=function(){return h};this.pause=function(){paused=true};this.abort=function(){h=true;if(b(p))p({data:[],errors:[],meta:{aborted:true}})};this.stream=function(e){f=e;if(t){l=function(){m();g()}}else{l=functi
|