diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..358e9e5
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,3 @@
+_gitignore/
+bower_components/
+node_modules/
\ No newline at end of file
diff --git a/README.md b/README.md
index 2013ae0..4ec37a1 100644
--- a/README.md
+++ b/README.md
@@ -3,19 +3,18 @@ Parse CSV with Javascript
[![mholt on Gratipay](http://img.shields.io/badge/tips-accepted-brightgreen.svg?style=flat)](https://www.gratipay.com/mholt/)
-Papa Parse (formerly the jQuery Parse Plugin) is a robust and powerful CSV (character-separated values) parser with these features:
+Papa Parse is the fastest CSV (or delimited text) parser for JavaScript. It is reliable and correct according to [RFC 4180](https://tools.ietf.org/html/rfc4180), and it comes with these features:
- Easy to use
- Parse CSV files directly (local or over the network)
- Stream large files (even via HTTP)
- Reverse parsing (converts JSON to CSV)
-- Auto-detect the delimiter
+- Auto-detect delimiter
- Worker threads to keep your web page reactive
- Header row support
- Pause, resume, abort
- Can convert numbers and booleans to their types
-- Graceful and robust error handling
-- Minor jQuery integration to get files from `` elements
+- Small jQuery integration to get files from `` elements
Papa Parse has **no dependencies** - not even jQuery.
@@ -30,7 +29,7 @@ Homepage & Demo
Papa Parse for Node
--------------------
-[Rich Harris](https://github.com/Rich-Harris) forked this project to make **[Baby Parse](https://github.com/Rich-Harris/BabyParse)** which runs in Node.js environments.
+[Rich Harris](https://github.com/Rich-Harris) forked this project to make **[Baby Parse](https://github.com/Rich-Harris/BabyParse)** which runs in Node.js environments. However, it is using an older version of the parser which is very slow and has some bugs.
```bash
$ npm install babyparse
@@ -40,6 +39,7 @@ $ npm install babyparse
Use it just like Papa Parse. However:
+- It is not up to date with the latest parser, so it is slower and has bugs.
- Files are not supported; strings only (you can use Node's file facilities to load file contents yourself)
- Some config options are unavailable:
- worker
@@ -70,10 +70,3 @@ Contributing
------------
To discuss a new feature or ask a question, open an issue. To fix a bug, submit a pull request to be credited with the [contributors](https://github.com/mholt/PapaParse/graphs/contributors)! Remember, a pull request, *with test*, is best.You may also discuss on Twitter with [#PapaParse](https://twitter.com/search?q=%23PapaParse&src=typd&f=realtime) or directly to me, [@mholt6](https://twitter.com/mholt6).
-
-
-
-Origins
--------
-
-Papa Parse is the result of a successful experiment by [SmartyStreets](http://smartystreets.com) which matured into an independent, fully-featured Javascript library.
diff --git a/bower.json b/bower.json
index dce4c4e..3e66396 100644
--- a/bower.json
+++ b/bower.json
@@ -1,11 +1,12 @@
{
"name": "Papa-Parse",
+ "version": "4.0.0",
"main": "papaparse.js",
"homepage": "http://papaparse.com",
"authors": [
"Matthew Holt"
],
- "description": "Papa Parse is a powerful CSV (delimited text) parser for the browser. (A port for Node.js is available as Baby Parse.)",
+ "description": "Fast and powerful CSV (delimited text) parser for the browser that converts CSV to JSON and JSON to CSV. Supports web workers and streaming large files.",
"keywords": [
"csv",
"parse",
@@ -21,8 +22,10 @@
"file",
"filereader",
"stream",
+ "worker",
"workers",
"ajax",
+ "thread",
"threading",
"multi-threaded"
],
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..9a1ceec
--- /dev/null
+++ b/package.json
@@ -0,0 +1,39 @@
+{
+ "name": "papaparse",
+ "version": "4.0.0",
+ "description": "Fast and powerful CSV parser for the browser that supports web workers and streaming large files. Converts CSV to JSON and JSON to CSV.",
+ "keywords": [
+ "csv",
+ "parser",
+ "parse",
+ "parsing",
+ "delimited",
+ "text",
+ "data",
+ "auto-detect",
+ "comma",
+ "tab",
+ "pipe",
+ "file",
+ "filereader",
+ "stream",
+ "worker",
+ "workers",
+ "thread",
+ "threading",
+ "multi-threaded",
+ "jquery-plugin"
+ ],
+ "homepage": "http://papaparse.com",
+ "author": {
+ "name": "Matthew Holt",
+ "url": "https://twitter.com/mholt6"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "http://opensource.org/licenses/MIT"
+ }
+ ],
+ "main": "papaparse.js"
+}
\ No newline at end of file
diff --git a/papaparse.min.js b/papaparse.min.js
index 8f50256..7d6ddca 100644
--- a/papaparse.min.js
+++ b/papaparse.min.js
@@ -1,6 +1,6 @@
/*
Papa Parse
- v3.1.4
+ v4.0.0
https://github.com/mholt/PapaParse
*/
-;(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;s0)n+=o;n+=c(e[s],s)}if(t.length>0)n+=u}for(var a=0;a0)n+=o;var h=r&&i?e[l]:l;n+=c(t[a][h],l)}if(a-1||t.charAt(0)==" "||t.charAt(t.length-1)==" ";return r?'"'+t+'"':t}function h(e,t){for(var n=0;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 p(){if(l){d();return}u=new XMLHttpRequest;if(!t){u.onload=d;u.onerror=v}u.open("GET",a,!t);if(n.step){var e=r+n.chunkSize-1;if(i&&e>i)e=i;u.setRequestHeader("Range","bytes="+r+"-"+e)}u.send();if(t&&u.status==0)v();else r+=n.chunkSize}function d(){if(u.readyState!=4)return;if(u.status<200||u.status>=400){v();return}s+=o+u.responseText;o="";l=!n.step||r>m(u);if(!l){var i=s.lastIndexOf("\n");if(i<0)i=s.lastIndexOf("\r");if(i>-1){o=s.substring(i+1);s=s.substring(0,i)}else{f();return}}var a=h.parse(s);s="";if(t){e.postMessage({results:a,workerId:Papa.WORKER_ID,finished:l})}else if(b(n.chunk)){console.log("CHUNKED");n.chunk(a);a=undefined}if(!l&&!a.meta.paused)f()}function v(){if(b(n.error))n.error(u.statusText);else if(t&&n.error){e.postMessage({workerId:Papa.WORKER_ID,error:u.statusText,finished:false})}}function m(e){var t=e.getResponseHeader("Content-Range");return parseInt(t.substr(t.lastIndexOf("/")+1))}n=n||{};if(!n.chunkSize)n.chunkSize=Papa.RemoteChunkSize;var r=0,i=0;var s="";var o="";var u,a,f,l;var h=new c(y(n));h.streamer=this;this.resume=function(){f()};this.finished=function(){return l};this.stream=function(e){a=e;if(t){f=function(){p();d()}}else{f=function(){p()}}f()}}function l(n){function f(){if(!l)d()}function d(){var e=Math.min(r+n.chunkSize,i.size);var t=a.readAsText(s.call(i,r,e),n.encoding);if(!p)v({target:{result:t}})}function v(s){r+=n.chunkSize;o+=u+s.target.result;u="";l=r>=i.size;if(!l){var a=o.lastIndexOf("\n");if(a<0)a=o.lastIndexOf("\r");if(a>-1){u=o.substring(a+1);o=o.substring(0,a)}else{f();return}}var c=h.parse(o);o="";if(t){e.postMessage({results:c,workerId:Papa.WORKER_ID,finished:l})}else if(b(n.chunk)){n.chunk(c,i);c=undefined}if(!c||!c.meta.paused)f()}function m(){if(b(n.error))n.error(a.error,i);else if(t&&n.error){e.postMessage({workerId:Papa.WORKER_ID,error:a.error,file:i,finished:false})}}n=n||{};if(!n.chunkSize)n.chunkSize=Papa.LocalChunkSize;var r=0;var i;var s;var o="";var u="";var a,f,s,l;var h=new c(y(n));h.streamer=this;var p=typeof FileReader!=="undefined";this.stream=function(e){i=e;s=i.slice||i.webkitSlice||i.mozSlice;if(p){a=new FileReader;a.onload=v;a.onerror=m}else a=new FileReaderSync;f()};this.finished=function(){return l};this.resume=function(){f()}}function c(e){function c(){if(f&&u){w("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+Papa.DefaultDelimiter+"'");u=false}if(p())d();return v()}function p(){return e.header&&a.length==0}function d(){if(!f)return;for(var e=0;p()&&e=a.length){if(!n["__parsed_extra"])n["__parsed_extra"]=[];n["__parsed_extra"].push(f.data[t][r])}else n[a[r]]=f.data[t][r]}}if(e.header){f.data[t]=n;if(r>a.length)w("FieldMismatch","TooManyFields","Too many fields: expected "+a.length+" fields but parsed "+r,t);else if(r1){a+=Math.abs(p-s);s=p}}f/=l.data.length;if((typeof i==="undefined"||a1.99){i=a;r=u}}e.delimiter=r;return{successful:!!r,bestDelimiter:r}}function g(e){var n=t.test(e);return n?parseFloat(e):e}function w(e,t,n,r){f.errors.push({type:e,code:t,message:n,row:r})}var t=/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i;var n=this;var r=0;var i;var s;var o=false;var u;var a=[];var f={data:[],errors:[],meta:{}};if(b(e.step)){var l=e.step;e.step=function(t){f=t;if(p())c();else{r+=t.data.length;if(e.preview&&r>e.preview)s.abort();else l(c(),n)}}}this.parse=function(t){u=false;if(!e.delimiter){var r=m(t);if(r.successful)e.delimiter=r.bestDelimiter;else{u=true;e.delimiter=Papa.DefaultDelimiter}f.meta.delimiter=e.delimiter}var a=y(e);if(e.preview&&e.header)a.preview++;i=t;s=new h(a);f=s.parse(i);c();if(b(e.complete)&&!o&&(!n.streamer||n.streamer.finished()))e.complete(f);return o?{meta:{paused:true}}:f||{meta:{paused:false}}};this.pause=function(){o=true;s.abort();i=i.substr(s.getCharIndex())};this.resume=function(){o=false;s=new h(e);s.parse(i);if(!o){if(n.streamer&&!n.streamer.finished())n.streamer.resume();else if(b(e.complete))e.complete(f)}};this.abort=function(){s.abort();if(b(e.complete))e.complete(f);i=""}}function h(e){function y(){while(f0&&m>=u)break;if(a=='"')S();else if(l)x();else T();w()}return E()}function w(){f++;a=n[f]}function E(){if(g)j("Abort","ParseAbort","Parsing was aborted by the user's step function");if(l)j("Quotes","MissingQuotes","Unescaped or mismatched quotes");O();if(!b(s))return q()}function S(){if(H()&&!P())l=!l;else{k();if(l&&P())f++;else j("Quotes","UnexpectedQuotes","Unexpected quotes")}}function x(){if(_(f)||D(f))c++;k()}function T(){if(a==r)L();else if(_(f)){A();w()}else if(D(f))A();else if(N())C();else k()}function N(){if(!i)return false;var e=f==0||D(f-1)||_(f-2);return e&&n[f]===i}function C(){while(!_(f)&&!D(f)&&f=n.length||t==r||t=="\r"||t=="\n"}function j(e,t,n){p.push({type:e,code:t,message:n,line:c,row:d,index:f})}function F(e){n=e;l=false;f=0,m=0,c=1;I();h=[[""]];a=n[f]}function I(){h=[];p=[];d=0;v=0}function q(){return{data:h,errors:p,meta:{lines:c,delimiter:r,aborted:g,truncated:u>0&&f-1)r=",";if(i===true)i="#";else if(typeof i!=="string"||i.length!=1||Papa.BAD_DELIMITERS.indexOf(i)>-1||i==r)i=false;this.parse=function(e){if(typeof e!=="string")throw"Input must be a string";F(e);return y()};this.abort=function(){g=true};this.getCharIndex=function(){return f}}function p(){var e="worker"+String(Math.random()).substr(2);document.write('');return document.getElementById(e).previousSibling.src}function d(){if(!Papa.WORKERS_SUPPORTED)return false;var t=new e.Worker(n);t.onmessage=v;t.id=i++;r[t.id]=t;return t}function v(e){var t=e.data;var n=r[t.workerId];if(t.error)n.userError(t.error,t.file);else if(t.results&&t.results.data){if(b(n.userStep)){for(var i=0;i-1)t.delimiter=s.delimiter;if(t.newline!="\n"&&t.newline!="\r"&&t.newline!="\r\n")t.newline=s.newline;if(typeof t.header!=="boolean")t.header=s.header;if(typeof t.dynamicTyping!=="boolean")t.dynamicTyping=s.dynamicTyping;if(typeof t.preview!=="number")t.preview=s.preview;if(typeof t.step!=="function")t.step=s.step;if(typeof t.complete!=="function")t.complete=s.complete;if(typeof t.error!=="function")t.error=s.error;if(typeof t.encoding!=="string")t.encoding=s.encoding;if(typeof t.worker!=="boolean")t.worker=s.worker;if(typeof t.download!=="boolean")t.download=s.download;if(typeof t.skipEmptyLines!=="boolean")t.skipEmptyLines=s.skipEmptyLines;if(typeof t.fastMode!=="boolean")t.fastMode=s.fastMode;return t}function y(e){if(typeof e!=="object")return e;var t=e instanceof Array?[]:{};for(var n in e)t[n]=y(e[n]);return t}function b(e){return typeof e==="function"}var t=!e.document,n;var r={},i=0;var s={delimiter:"",newline:"",header:false,dynamicTyping:false,preview:0,step:undefined,encoding:"",worker:false,comments:false,complete:undefined,error:undefined,download:false,chunk:undefined,skipEmptyLines:false,fastMode:false};e.Papa={};e.Papa.parse=u;e.Papa.unparse=a;e.Papa.RECORD_SEP=String.fromCharCode(30);e.Papa.UNIT_SEP=String.fromCharCode(31);e.Papa.BYTE_ORDER_MARK="";e.Papa.BAD_DELIMITERS=["\r","\n",'"',e.Papa.BYTE_ORDER_MARK];e.Papa.WORKERS_SUPPORTED=!!e.Worker;e.Papa.LocalChunkSize=1024*1024*10;e.Papa.RemoteChunkSize=1024*1024*5;e.Papa.DefaultDelimiter=",";e.Papa.Parser=h;e.Papa.ParserHandle=c;e.Papa.NetworkStreamer=f;e.Papa.FileStreamer=l;if(e.jQuery){var o=e.jQuery;o.fn.parse=function(t){function i(){if(r.length==0)return;var e=r[0];if(b(t.before)){var n=t.before(e.file,e.inputElem);if(typeof n==="object"){if(n.action=="abort"){s("AbortError",e.file,e.inputElem,n.reason);return}else if(n.action=="skip"){u();return}else if(typeof n.config==="object")e.instanceConfig=o.extend(e.instanceConfig,n.config)}else if(n=="skip"){u();return}}var i=e.instanceConfig.complete;e.instanceConfig.complete=function(t){if(b(i))i(t,e.file,e.inputElem);u()};Papa.parse(e.file,e.instanceConfig)}function s(e,n,r,i){if(b(t.error))t.error({name:e},n,r,i)}function u(){r.splice(0,1);i()}var n=t.config||{};var r=[];this.each(function(t){var i=o(this).prop("tagName").toUpperCase()=="INPUT"&&o(this).attr("type").toLowerCase()=="file"&&e.FileReader;if(!i||!this.files||this.files.length==0)return true;for(var s=0;s