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.

7 lines
17 KiB

/*@license
Papa Parse
v4.4.0
https://github.com/mholt/PapaParse
License: MIT
*/
!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&"undefined"!=typeof exports?module.exports=t():e.Papa=t()}(this,function(){"use strict";var s,e,f="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==f?f:{},r=!f.document&&!!f.postMessage,o=r&&/(\?|&)papaworker(=|&|$)/.test(f.location.search),a=!1,h={},u=0,g={parse:function(e,t){var i=(t=t||{}).dynamicTyping||!1;z(i)&&(t.dynamicTypingFunction=i,i={});if(t.dynamicTyping=i,t.worker&&g.WORKERS_SUPPORTED){var n=function(){if(!g.WORKERS_SUPPORTED)return!1;if(!a&&null===g.SCRIPT_PATH)throw new Error("Script path cannot be determined automatically when Papa Parse is loaded asynchronously. You need to set Papa.SCRIPT_PATH manually.");var e=g.SCRIPT_PATH||s;e+=(-1!==e.indexOf("?")?"&":"?")+"papaworker";var t=new f.Worker(e);return t.onmessage=k,t.id=u++,h[t.id]=t}();return n.userStep=t.step,n.userChunk=t.chunk,n.userComplete=t.complete,n.userError=t.error,t.step=z(t.step),t.chunk=z(t.chunk),t.complete=z(t.complete),t.error=z(t.error),delete t.worker,void n.postMessage({input:e,config:t,workerId:n.id})}var r=null;"string"==typeof e?r=t.download?new l(t):new _(t):!0===e.readable&&z(e.read)&&z(e.on)?r=new m(t):(f.File&&e instanceof File||e instanceof Object)&&(r=new p(t));return r.stream(e)},unparse:function(e,t){var n=!1,f=!0,d=",",c="\r\n",r='"';!function(){if("object"!=typeof t)return;"string"==typeof t.delimiter&&1===t.delimiter.length&&-1===g.BAD_DELIMITERS.indexOf(t.delimiter)&&(d=t.delimiter);("boolean"==typeof t.quotes||t.quotes instanceof Array)&&(n=t.quotes);"string"==typeof t.newline&&(c=t.newline);"string"==typeof t.quoteChar&&(r=t.quoteChar);"boolean"==typeof t.header&&(f=t.header)}();var s=new RegExp(r,"g");"string"==typeof e&&(e=JSON.parse(e));if(e instanceof Array){if(!e.length||e[0]instanceof Array)return a(null,e);if("object"==typeof e[0])return a(i(e[0]),e)}else if("object"==typeof e)return"string"==typeof e.data&&(e.data=JSON.parse(e.data)),e.data instanceof Array&&(e.fields||(e.fields=e.meta&&e.meta.fields),e.fields||(e.fields=e.data[0]instanceof Array?e.fields:i(e.data[0])),e.data[0]instanceof Array||"object"==typeof e.data[0]||(e.data=[e.data])),a(e.fields||[],e.data||[]);throw"exception: Unable to serialize unrecognized input";function i(e){if("object"!=typeof e)return[];var t=[];for(var i in e)t.push(i);return t}function a(e,t){var i="";"string"==typeof e&&(e=JSON.parse(e)),"string"==typeof t&&(t=JSON.parse(t));var n=e instanceof Array&&0<e.length,r=!(t[0]instanceof Array);if(n&&f){for(var s=0;s<e.length;s++)0<s&&(i+=d),i+=l(e[s],s);0<t.length&&(i+=c)}for(var a=0;a<t.length;a++){for(var o=n?e.length:t[a].length,h=0;h<o;h++){0<h&&(i+=d);var u=n&&r?e[h]:h;i+=l(t[a][u],h)}a<t.length-1&&(i+=c)}return i}function l(e,t){if(null==e)return"";e=e.toString().replace(s,r+r);var i="boolean"==typeof n&&n||n instanceof Array&&n[t]||function(e,t){for(var i=0;i<t.length;i++)if(-1<e.indexOf(t[i]))return!0;return!1}(e,g.BAD_DELIMITERS)||-1<e.indexOf(d)||" "===e.charAt(0)||" "===e.charAt(e.length-1);return i?r+e+r:e}}};if(g.RECORD_SEP=String.fromCharCode(30),g.UNIT_SEP=String.fromCharCode(31),g.BYTE_ORDER_MARK="\ufeff",g.BAD_DELIMITERS=["\r","\n",'"',g.BYTE_ORDER_MARK],g.WORKERS_SUPPORTED=!r&&!!f.Worker,g.SCRIPT_PATH=null,g.LocalChunkSize=10485760,g.RemoteChunkSize=5242880,g.DefaultDelimiter=",",g.Parser=v,g.ParserHandle=i,g.NetworkStreamer=l,g.FileStreamer=p,g.StringStreamer=_,g.ReadableStreamStreamer=m,f.jQuery){var d=f.jQuery;d.fn.parse=function(o){var i=o.config||{},h=[];return this.each(function(e){if(!("INPUT"===d(this).prop("tagName").toUpperCase()&&"file"===d(this).attr("type").toLowerCase()&&f.FileReader)||!this.files||0===this.files.length)return!0;for(var t=0;t<this.files.length;t++)h.push({file:this.files[t],inputElem:this,instanceConfig:d.extend({},i)})}),e(),this;function e(){if(0!==h.length){var e,t,i,n,r=h[0];if(z(o.before)){var s=o.before(r.file,r.inputElem);if("object"==typeof s){if("abort"===s.action)return e="AbortError",t=r.file,i=r.inputElem,n=s.reason,void(z(o.error)&&o.error({name:e},t,i,n));