From eecc21f71eab44c597fc50766054e0d4541e3f23 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Thu, 3 May 2018 14:48:56 +0200 Subject: [PATCH] Return unique row as data on step function --- papaparse.js | 7 ++++--- tests/test-cases.js | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/papaparse.js b/papaparse.js index b7fa8db..633bdc7 100755 --- a/papaparse.js +++ b/papaparse.js @@ -1477,10 +1477,11 @@ } /** Returns an object with the results, errors, and meta. */ - function returnable(stopped) + function returnable(stopped, step) { + var isStep = step || false; return { - data: data, + data: isStep ? data[0] : data, errors: errors, meta: { delimiter: delim, @@ -1495,7 +1496,7 @@ /** Executes the user's step function and resets data & errors. */ function doStep() { - step(returnable()); + step(returnable(undefined, true)); data = []; errors = []; } diff --git a/tests/test-cases.js b/tests/test-cases.js index 773635e..dcbdce5 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -1465,7 +1465,7 @@ var CUSTOM_TESTS = [ run: function(callback) { Papa.parse('A,b,c', { step: function(response) { - callback(response.data[0]); + callback(response.data); } }); } @@ -1702,7 +1702,7 @@ var CUSTOM_TESTS = [ var updates = []; Papa.parse('A,b,c\nd,E,f\nG,h,i', { step: function(response, handle) { - updates.push(response.data[0]); + updates.push(response.data); handle.abort(); callback(updates); }, @@ -1732,7 +1732,7 @@ var CUSTOM_TESTS = [ var updates = []; Papa.parse('A,b,c\nd,E,f\nG,h,i', { step: function(response, handle) { - updates.push(response.data[0]); + updates.push(response.data); handle.pause(); callback(updates); }, @@ -1751,7 +1751,7 @@ var CUSTOM_TESTS = [ var first = true; Papa.parse('A,b,c\nd,E,f\nG,h,i', { step: function(response, h) { - updates.push(response.data[0]); + updates.push(response.data); if (!first) return; handle = h; handle.pause();