Fast and powerful CSV (delimited text) parser that gracefully handles large files and malformed input
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.

8 lines
20 KiB

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Papa={})}(this,(function(e){"use strict";
/* @license
Papa Parse
v5.3.1
https://github.com/mholt/PapaParse
License: MIT
*/var t,i="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==i?i:{},r={},n=0,s="papa-worker",a=i&&i.document&&i.document.currentScript&&i.document.currentScript.src,o=!i.document&&!!i.postMessage,h=o&&i.name===s,u=function(e,t){var o=(t=t||{}).dynamicTyping||!1;q(o)&&(t.dynamicTypingFunction=o,o={});if(t.dynamicTyping=o,t.transform=!!q(t.transform)&&t.transform,t.worker&&p){var h=function(){if(!p)return!1;var e=a,t=new i.Worker(e,{name:s,type:void 0});return t.onmessage=L,t.id=n++,r[t.id]=t,t}();return h.userStep=t.step,h.userChunk=t.chunk,h.userComplete=t.complete,h.userError=t.error,t.step=q(t.step),t.chunk=q(t.chunk),t.complete=q(t.complete),t.error=q(t.error),delete t.worker,void h.postMessage({input:e,config:t,workerId:h.id})}var u=null;if(1===e&&"undefined"==typeof PAPA_BROWSER_CONTEXT)return(u=new A(t)).getStream();"string"==typeof e?u=t.download?new x(t):new R(t):!0===e.readable&&q(e.read)&&q(e.on)?u=new T(t):(i.File&&e instanceof File||e instanceof Object)&&(u=new O(t));return u.stream(e)},f=function(e,t){var i=!1,r=!0,n=",",s="\r\n",a='"',o=a+a,h=!1,u=null,f=!1;!function(){if("object"!=typeof t)return;"string"!=typeof t.delimiter||c.filter((function(e){return-1!==t.delimiter.indexOf(e)})).length||(n=t.delimiter);("boolean"==typeof t.quotes||"function"==typeof t.quotes||Array.isArray(t.quotes))&&(i=t.quotes);"boolean"!=typeof t.skipEmptyLines&&"string"!=typeof t.skipEmptyLines||(h=t.skipEmptyLines);"string"==typeof t.newline&&(s=t.newline);"string"==typeof t.quoteChar&&(a=t.quoteChar);"boolean"==typeof t.header&&(r=t.header);if(Array.isArray(t.columns)){if(0===t.columns.length)throw new Error("Option columns is empty");u=t.columns}void 0!==t.escapeChar&&(o=t.escapeChar+a);"boolean"==typeof t.escapeFormulae&&(f=t.escapeFormulae)}();var d=new RegExp(I(a),"g");"string"==typeof e&&(e=JSON.parse(e));if(Array.isArray(e)){if(!e.length||Array.isArray(e[0]))return l(null,e,h);if("object"==typeof e[0])return l(u||Object.keys(e[0]),e,h)}else if("object"==typeof e)return"string"==typeof e.data&&(e.data=JSON.parse(e.data)),Array.isArray(e.data)&&(e.fields||(e.fields=e.meta&&e.meta.fields),e.fields||(e.fields=Array.isArray(e.data[0])?e.fields:"object"==typeof e.data[0]?Object.keys(e.data[0]):[]),Array.isArray(e.data[0])||"object"==typeof e.data[0]||(e.data=[e.data])),l(e.fields||[],e.data||[],h);throw new Error("Unable to serialize unrecognized input");function l(e,t,i){var a="";"string"==typeof e&&(e=JSON.parse(e)),"string"==typeof t&&(t=JSON.parse(t));var o=Array.isArray(e)&&e.length>0,h=!Array.isArray(t[0]);if(o&&r){for(var u=0;u<e.length;u++)u>0&&(a+=n),a+=p(e[u],u);t.length>0&&(a+=s)}for(var f=0;f<t.length;f++){var d=o?e.length:t[f].length,l=!1,c=o?0===Object.keys(t[f]).length:0===t[f].length;if(i&&!o&&(l="greedy"===i?""===t[f].join("").trim():1===t[f].length&&0===t[f][0].length),"greedy"===i&&o){for(var g=[],m=0;m<d;m++){var _=h?e[m]:m;g.push(t[f][_])}l=""===g.join("").trim()}if(!l){for(var y=0;y<d;y++){y>0&&!c&&(a+=n);var v=o&&h?e[y]:y;a+=p(t[f][v],y)}f<t.length-1&&(!i||d>0&&!c)&&(a+=s)}}return a}function p(e,t){if(null==e)return"";if(e.constructor===Date)return JSON.stringify(e).slice(1,25);!0===f&&"string"==typeof e&&null!==e.match(/^[=+\-@].*$/)&&(e="'"+e);var r=e.toString().replace(d,o);return"boolean"==typeof i&&i||"function"==typeof i&&i(e,t)||Array.isArray(i)&&i[t]||function(e,t){for(var i=0;i<t.length;i++)if(e.indexOf(t[i])>-1)return!0;return!1}(r,c)||r.indexOf(n)>-1||" "===r.charAt(0)||" "===r.charAt(r.length-1)?a+r+a:r}},d=String.fromCharCode(30),l=String.fromCharCode(31),c=["\r","\n",'"',"\ufeff"],p=!o&&!!i.Worker&&a,g=10485760,m=5242880,_=j,y=F,v=x,k=O,b=R,C=T,w="undefined"==typeof PAPA_BROWSER_CONTEXT?A:void 0;if(i.jQuery){var E=i.jQuery;E.fn.parse=function(e){var t=e.config||{},r=[];return this.each((function(e){if(!("INPUT"===E(this).prop("tagName").toUpperCase()&&"file"===E(this).attr("type").toLowerCase()&&i.FileReader)||!this.files||0===this.files.length)return!0;for(var n=0;n<this.files.length;n++)r.push({file:this.files[n],inputElem:this,instanceConfig:E.extend({},t)})})),n()