From 8acd19822221de94c3d0fdd16cf71aca11b40478 Mon Sep 17 00:00:00 2001 From: Obinna Agba Date: Mon, 11 Sep 2017 15:02:31 +0100 Subject: [PATCH] Fixed issues with '.' in column headers --- lib/json2xls.js | 12 +++--------- package.json | 3 ++- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/json2xls.js b/lib/json2xls.js index e0a7a07..fde5b6b 100644 --- a/lib/json2xls.js +++ b/lib/json2xls.js @@ -1,4 +1,5 @@ var nodeExcel = require('excel-export'); +var objectPath = require('object-path'); var transform = function(json,config) { var conf = transform.prepareJson(json,config); @@ -27,15 +28,8 @@ function getType(obj,type) { function getByString(object, path) { path = path.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties path = path.replace(/^\./, ''); // strip a leading dot - var a = path.split('.'); - while (a.length) { - var n = a.shift(); - if (n in object) { - object = (object[n]==undefined)?null:object[n]; - } else { - return null; - } - } + var defaultValue = object[path]; + object = objectPath.get(object, path, defaultValue); return object; } diff --git a/package.json b/package.json index b66d2ab..3cd77d4 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "author": "Rikkert Koppes