You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if(typeofdata[subKey]==='object'&&data[subKey]!==null&&typeofdata[subKey].length==='undefined'&&_.keys(data[subKey]).length>0){// If we have another nested document
15
+
if(_.isObject(data[subKey])&&!_.isNull(data[subKey])&&_.isUndefined(data[subKey].length)&&_.keys(data[subKey]).length>0){// If we have another nested document
16
16
subKeys[indx]=retrieveSubHeading(newKey,data[subKey]);// Recur on the subdocument to retrieve the full key name
17
17
}else{
18
18
subKeys[indx]=(options.DELIMITER.WRAP||'')+(newKey||'')+(options.DELIMITER.WRAP||'');// Set the key name since we don't have a sub document
@@ -22,21 +22,19 @@ var retrieveSubHeading = function (heading, data) {
22
22
};
23
23
24
24
// Retrieve the headings for all documents and return it. This checks that all documents have the same schema.
25
-
varretrieveHeading=function(data){
26
-
returnfunction(cb){// Returns a function that takes a callback - the function is passed to async.parallel
27
-
varkeys=_.keys(data);// Retrieve the current data keys
28
-
_.each(keys,function(key,indx){// for each key
29
-
if(typeofdata[key]==='object'){
30
-
// if the data at the key is a document, then we retrieve the subHeading starting with an empty string heading and the doc
31
-
keys[indx]=retrieveSubHeading('',data[key]);
32
-
}
33
-
});
34
-
// Retrieve the unique array of headings (keys)
35
-
keys=_.uniq(keys);
36
-
// If we have more than 1 unique list, then not all docs have the same schema - report an error
37
-
if(keys.length>1){thrownewError('Not all documents have the same schema.',keys);}
38
-
returncb(null,_.flatten(keys).join(options.DELIMITER.FIELD));// Return headings back
39
-
};
25
+
varretrieveHeading=function(data,cb){
26
+
varkeys=_.keys(data);// Retrieve the current data keys
27
+
_.each(keys,function(key,indx){// for each key
28
+
if(_.isObject(data[key])){
29
+
// if the data at the key is a document, then we retrieve the subHeading starting with an empty string heading and the doc
30
+
keys[indx]=retrieveSubHeading('',data[key]);
31
+
}
32
+
});
33
+
// Retrieve the unique array of headings (keys)
34
+
keys=_.uniq(keys);
35
+
// If we have more than 1 unique list, then not all docs have the same schema - report an error
36
+
if(keys.length>1){thrownewError('Not all documents have the same schema.',keys);}
37
+
returncb(null,_.flatten(keys).join(options.DELIMITER.FIELD));// Return headings back
40
38
};
41
39
42
40
// Convert the given data with the given keys
@@ -62,11 +60,9 @@ var convertData = function (data, keys) {
62
60
};
63
61
64
62
// Generate the CSV representing the given data.
65
-
vargenerateCsv=function(data){
66
-
returnfunction(cb){// Returns a function that takes a callback - the function is passed to async.parallel
67
-
// Reduce each JSON document in data to a CSV string and append it to the CSV accumulator
0 commit comments