From 85c23a5985dee38edb346164131496c721174351 Mon Sep 17 00:00:00 2001 From: Khaled Mohamed Date: Fri, 30 Jun 2017 23:28:35 -0400 Subject: [PATCH] =?UTF-8?q?feat(supporting-array-as-root):=20supporting=20?= =?UTF-8?q?passing=20in=20array=20as=20the=20root=20object=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close issue #5 --- lib/translate-json-object.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/translate-json-object.js b/lib/translate-json-object.js index 4da4532..1ea92f9 100644 --- a/lib/translate-json-object.js +++ b/lib/translate-json-object.js @@ -61,6 +61,13 @@ function TranslateJSONObject() { return Promise.reject(serviceType + ' doesn\'t support the language code you specified [' + language + '], please try another language code (ISO-639-1)'); } + var ARRAY_ROOT_TYPE = _.isArray(srcObj); + if (ARRAY_ROOT_TYPE) { + srcObj = { + arrayType: srcObj + }; + } + function recurisveTranslateObject(destObj, srcObj) { // Loop through the entire object collection _.forEach(srcObj, loopHandler); @@ -113,12 +120,16 @@ function TranslateJSONObject() { // Recursivly loop through an object recurisveTranslateObject(destObj, { - data: srcObj + ROOT: srcObj }, language); return new Promise(function (resolve, reject) { Promise.all(promises).then(function () { - resolve(destObj.data); + if (ARRAY_ROOT_TYPE) { + resolve(destObj.ROOT.arrayType); + } else { + resolve(destObj.ROOT); + } }).catch(reject); }); }