From a7eb6343be9b9e06b9c28c908899c52b1a7d4ee5 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Wed, 14 Nov 2018 11:37:57 +0100 Subject: [PATCH] Return unique row as data on step function (#500) --- papaparse.js | 7 ++++--- tests/test-cases.js | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/papaparse.js b/papaparse.js index 0edec76..8676056 100755 --- a/papaparse.js +++ b/papaparse.js @@ -1649,10 +1649,11 @@ if (!Array.isArray) } /** 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, @@ -1667,7 +1668,7 @@ if (!Array.isArray) /** 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 bfc1d04..44521e5 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -1735,7 +1735,7 @@ var CUSTOM_TESTS = [ run: function(callback) { Papa.parse('A,b,c', { step: function(response) { - callback(response.data[0]); + callback(response.data); } }); } @@ -1972,7 +1972,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); }, @@ -2002,7 +2002,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); }, @@ -2021,7 +2021,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();