Browse Source

Return unique row as data on step function (#500)

pull/581/head
Sergi Almacellas Abellana 6 years ago committed by GitHub
parent
commit
a7eb6343be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      papaparse.js
  2. 8
      tests/test-cases.js

7
papaparse.js

@ -1649,10 +1649,11 @@ if (!Array.isArray) @@ -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) @@ -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 = [];
}

8
tests/test-cases.js

@ -1735,7 +1735,7 @@ var CUSTOM_TESTS = [ @@ -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 = [ @@ -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 = [ @@ -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 = [ @@ -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();

Loading…
Cancel
Save