diff --git a/bower.json b/bower.json index 6418fa8..4aebbb3 100644 --- a/bower.json +++ b/bower.json @@ -31,6 +31,6 @@ "tests" ], "dependencies": { - "jquery": ">=1.5" + "jquery": ">=1.6.0" } } diff --git a/jquery.parse.js b/jquery.parse.js index 38bc747..a9c77e7 100644 --- a/jquery.parse.js +++ b/jquery.parse.js @@ -1,6 +1,6 @@ /* Papa Parse - v2.0.4 + v2.0.5 https://github.com/mholt/jquery.parse */ @@ -476,12 +476,15 @@ _state.errors.length = 0; } - if (_config.header && _state.lineNum > 0) + if (_config.header) { - if (streaming()) - _state.parsed.rows = [ {} ]; - else - _state.parsed.rows.push({}); + if (_state.lineNum > 0) + { + if (streaming()) + _state.parsed.rows = [ {} ]; + else + _state.parsed.rows.push({}); + } } else { diff --git a/jquery.parse.min.js b/jquery.parse.min.js index 21c7e6f..793e74f 100644 --- a/jquery.parse.min.js +++ b/jquery.parse.min.js @@ -1,6 +1,6 @@ /* Papa Parse - v2.0.4 + v2.0.5 https://github.com/mholt/jquery.parse */ -;(function(e){"use strict";function t(e){return typeof e==="function"}function n(e,t){function a(n){var r=s+n.target.result;s="";if(r>=t.chunkSize){var u=r.lastIndexOf("\n");if(u<0)u=r.lastIndexOf("\r");if(u>-1){s=r.substring(u+1);r=r.substring(0,u)}}var a=o.parse(r);if(i>=e.size)return f(n);else if(a.errors.abort)return;else c()}function f(n){if(typeof t.onComplete==="function")t.onComplete(undefined,e,t.inputElem,n)}function l(){if(typeof t.onFileError==="function")t.onFileError(u.error,e,t.inputElem)}function c(){if(i1){f+=Math.abs(p-s);s=p}}l/=c.results.length;if((typeof i==="undefined"||f1.99){i=f;n=a}}u.delimiter=n;return!!n}function p(){var e=a.i>0&&g(a.i-1)||a.i==0;var t=a.i=i.length)return false;var t=i[e];if(t==u.delimiter||t=="\n"||t=="\r"&&e=i.length)return false;if(e0){if(S())a.parsed.rows=[{}];else a.parsed.rows.push({})}else{if(S())a.parsed=[[]];else if(!u.header)a.parsed.push([])}a.lineNum++;a.line="";a.field=0}function E(){if(o)return;b();var e=T();if(!e&&u.header)N();if(S()&&(!u.header||u.header&&a.parsed.rows.length>0)){var t=u.step(k());if(t===false)o=true}}function S(){return typeof u.step==="function"}function x(e){var t=l.floats.test(e);return t?parseFloat(e):e}function T(){if(l.empty.test(a.line)){if(u.header){if(a.lineNum==1){a.parsed.fields=[];a.lineNum--}else a.parsed.rows.splice(a.parsed.rows.length-1,1)}else a.parsed.splice(a.parsed.length-1,1);return true}return false}function N(){if(!u.header)return true;if(a.parsed.rows.length==0)return true;var e=a.parsed.fields.length;var t=0;var n=a.parsed.rows[a.parsed.rows.length-1];for(var r in n)if(n.hasOwnProperty(r))t++;if(te)return C("FieldMismatch","TooManyFields","Too many fields: expected "+e+" fields but parsed "+t);return true}function C(e,t,n,r){var i=u.header?a.parsed.rows.length?a.parsed.rows.length-1:undefined:a.parsed.length-1;var o=r||i;if(typeof a.errors[o]==="undefined")a.errors[o]=[];a.errors[o].push({type:e,code:t,message:n,line:a.lineNum,row:i,index:a.i+s});a.errors.length++;return false}function k(){return{results:a.parsed,errors:a.errors}}function L(e){n++;if(n>1&&S())s+=e.length;a=A();i=e}function A(){var e;if(u.header){e={fields:S()?a.parsed.fields||[]:[],rows:S()&&n>1?[{}]:[]}}else e=[[]];return{i:0,lineNum:S()?a.lineNum:1,field:0,fieldVal:"",line:"",ch:"",inQuotes:false,parsed:e,errors:{length:0}}}var t=this;var n=0;var i="";var s=0;var o=false;var u={};var a=A();var f={delimiter:"",header:true,dynamicTyping:true,preview:0};var l={floats:/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i,empty:/^\s*$/};e=c(e);u={delimiter:e.delimiter,header:e.header,dynamicTyping:e.dynamicTyping,preview:e.preview,step:e.step};this.parse=function(e){if(typeof e!=="string")return k();L(e);if(!u.delimiter&&!h(e)){C("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to comma","config");u.delimiter=","}for(a.i=0;a.i0&&a.lineNum>u.preview)break;a.ch=i[a.i];a.line+=a.ch;if(a.ch=='"')p();else if(a.inQuotes)d();else m()}if(o)C("Abort","ParseAbort","Parsing was aborted by the user's step function","abort");else{E();if(a.inQuotes)C("Quotes","MissingQuotes","Unescaped or mismatched quotes")}return k()};this.getOptions=function(){return{delimiter:u.delimiter,header:u.header,dynamicTyping:u.dynamicTyping,preview:u.preview,step:u.step}}}e.fn.parse=function(r){function o(i){var s=a,o;if(t(r.error))o=function(){r.error(c.error,i.file,i.inputElem)};if(t(r.complete))s=function(e,t,n,i){r.complete(e,t,n,i);a()};if(t(r.before)){var f=r.before(i.file,i.inputElem);if(typeof f==="object")i.instanceConfig=e.extend(i.instanceConfig,f);else if(f==="skip")return a();else if(f===false){u("AbortError",i.file,i.inputElem);return}}if(i.instanceConfig.step){var l=new n(i.file,{inputElem:i.inputElem,config:e.extend({},i.instanceConfig)});l.stream(s,o)}else{var c=new FileReader;c.onerror=o;c.onload=function(t){var n=t.target.result;var r=e.parse(n,i.instanceConfig);s(r,i.file,i.inputElem,t)};c.readAsText(i.file)}}function u(e,n,i){if(t(r.error))r.error({name:e},n,i)}function a(){s.splice(0,1);if(s.length>0)o(s[0])}var i=r.config||{};var s=[];this.each(function(t){var n=e(this).prop("tagName").toUpperCase()=="INPUT"&&e(this).attr("type")=="file"&&window.FileReader;if(!n)return true;var r=e.extend({},i);if(!this.files||this.files.length==0){u("NoFileError",undefined,this);return true}for(var a=0;a0)o(s[0])});return this};e.parse=function(e,t){var n=new r(t);return n.parse(e)}})(jQuery); \ No newline at end of file +;(function(e){"use strict";function t(e){return typeof e==="function"}function n(e,t){function a(n){var r=s+n.target.result;s="";if(r>=t.chunkSize){var u=r.lastIndexOf("\n");if(u<0)u=r.lastIndexOf("\r");if(u>-1){s=r.substring(u+1);r=r.substring(0,u)}}var a=o.parse(r);if(i>=e.size)return f(n);else if(a.errors.abort)return;else c()}function f(n){if(typeof t.onComplete==="function")t.onComplete(undefined,e,t.inputElem,n)}function l(){if(typeof t.onFileError==="function")t.onFileError(u.error,e,t.inputElem)}function c(){if(i1){f+=Math.abs(p-s);s=p}}l/=c.results.length;if((typeof i==="undefined"||f1.99){i=f;n=a}}u.delimiter=n;return!!n}function p(){var e=a.i>0&&g(a.i-1)||a.i==0;var t=a.i=i.length)return false;var t=i[e];if(t==u.delimiter||t=="\n"||t=="\r"&&e=i.length)return false;if(e0){if(S())a.parsed.rows=[{}];else a.parsed.rows.push({})}}else{if(S())a.parsed=[[]];else if(!u.header)a.parsed.push([])}a.lineNum++;a.line="";a.field=0}function E(){if(o)return;b();var e=T();if(!e&&u.header)N();if(S()&&(!u.header||u.header&&a.parsed.rows.length>0)){var t=u.step(k());if(t===false)o=true}}function S(){return typeof u.step==="function"}function x(e){var t=l.floats.test(e);return t?parseFloat(e):e}function T(){if(l.empty.test(a.line)){if(u.header){if(a.lineNum==1){a.parsed.fields=[];a.lineNum--}else a.parsed.rows.splice(a.parsed.rows.length-1,1)}else a.parsed.splice(a.parsed.length-1,1);return true}return false}function N(){if(!u.header)return true;if(a.parsed.rows.length==0)return true;var e=a.parsed.fields.length;var t=0;var n=a.parsed.rows[a.parsed.rows.length-1];for(var r in n)if(n.hasOwnProperty(r))t++;if(te)return C("FieldMismatch","TooManyFields","Too many fields: expected "+e+" fields but parsed "+t);return true}function C(e,t,n,r){var i=u.header?a.parsed.rows.length?a.parsed.rows.length-1:undefined:a.parsed.length-1;var o=r||i;if(typeof a.errors[o]==="undefined")a.errors[o]=[];a.errors[o].push({type:e,code:t,message:n,line:a.lineNum,row:i,index:a.i+s});a.errors.length++;return false}function k(){return{results:a.parsed,errors:a.errors}}function L(e){n++;if(n>1&&S())s+=e.length;a=A();i=e}function A(){var e;if(u.header){e={fields:S()?a.parsed.fields||[]:[],rows:S()&&n>1?[{}]:[]}}else e=[[]];return{i:0,lineNum:S()?a.lineNum:1,field:0,fieldVal:"",line:"",ch:"",inQuotes:false,parsed:e,errors:{length:0}}}var t=this;var n=0;var i="";var s=0;var o=false;var u={};var a=A();var f={delimiter:"",header:true,dynamicTyping:true,preview:0};var l={floats:/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i,empty:/^\s*$/};e=c(e);u={delimiter:e.delimiter,header:e.header,dynamicTyping:e.dynamicTyping,preview:e.preview,step:e.step};this.parse=function(e){if(typeof e!=="string")return k();L(e);if(!u.delimiter&&!h(e)){C("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to comma","config");u.delimiter=","}for(a.i=0;a.i0&&a.lineNum>u.preview)break;a.ch=i[a.i];a.line+=a.ch;if(a.ch=='"')p();else if(a.inQuotes)d();else m()}if(o)C("Abort","ParseAbort","Parsing was aborted by the user's step function","abort");else{E();if(a.inQuotes)C("Quotes","MissingQuotes","Unescaped or mismatched quotes")}return k()};this.getOptions=function(){return{delimiter:u.delimiter,header:u.header,dynamicTyping:u.dynamicTyping,preview:u.preview,step:u.step}}}e.fn.parse=function(r){function o(i){var s=a,o;if(t(r.error))o=function(){r.error(c.error,i.file,i.inputElem)};if(t(r.complete))s=function(e,t,n,i){r.complete(e,t,n,i);a()};if(t(r.before)){var f=r.before(i.file,i.inputElem);if(typeof f==="object")i.instanceConfig=e.extend(i.instanceConfig,f);else if(f==="skip")return a();else if(f===false){u("AbortError",i.file,i.inputElem);return}}if(i.instanceConfig.step){var l=new n(i.file,{inputElem:i.inputElem,config:e.extend({},i.instanceConfig)});l.stream(s,o)}else{var c=new FileReader;c.onerror=o;c.onload=function(t){var n=t.target.result;var r=e.parse(n,i.instanceConfig);s(r,i.file,i.inputElem,t)};c.readAsText(i.file)}}function u(e,n,i){if(t(r.error))r.error({name:e},n,i)}function a(){s.splice(0,1);if(s.length>0)o(s[0])}var i=r.config||{};var s=[];this.each(function(t){var n=e(this).prop("tagName").toUpperCase()=="INPUT"&&e(this).attr("type")=="file"&&window.FileReader;if(!n)return true;var r=e.extend({},i);if(!this.files||this.files.length==0){u("NoFileError",undefined,this);return true}for(var a=0;a0)o(s[0])});return this};e.parse=function(e,t){var n=new r(t);return n.parse(e)}})(jQuery); \ No newline at end of file diff --git a/parse.jquery.json b/parse.jquery.json index 9dcd6fd..38fb742 100644 --- a/parse.jquery.json +++ b/parse.jquery.json @@ -1,6 +1,6 @@ { "name": "parse", - "version": "2.0.4", + "version": "2.0.5", "title": "Papa Parse", "description": "Papa is a powerful CSV (delimited text) parser that streams large files and gracefully handles malformed input.", "keywords": [