Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let buildExport = params => {
dataset.forEach(record => {
let row = []
for (let col in specification) {
let cell_value = record[col]
let cell_value = getValue(col.split('.'), record);

if (specification[col].cellFormat && typeof specification[col].cellFormat == 'function') {
cell_value = specification[col].cellFormat(record[col], record)
Expand Down Expand Up @@ -85,6 +85,23 @@ let buildExport = params => {

}

/**
* Gets nested values in nested objects.
* @param {String} path Path of value.
* @param {Object} obj Object to get the value from.
* @return Value for specified path.
*/
function getValue(path, obj){
if(path.length === 1){

return obj[path[0]];
}
else{

return getValue(path, obj[path.shift()]);
}
}

module.exports = {
buildExport
}