diff --git a/JsonExcel.vue b/JsonExcel.vue index fd04dd4..4f9b985 100644 --- a/JsonExcel.vue +++ b/JsonExcel.vue @@ -106,7 +106,7 @@ export default { return; } - let json = this.getProcessedJson(data, this.downloadFields); + let json = await this.getProcessedJson(data, this.downloadFields); if (this.type === "html") { // this is mainly for testing return this.export( @@ -247,18 +247,21 @@ export default { --------------- Get only the data to export, if no fields are set return all the data */ - getProcessedJson(data, header) { + async getProcessedJson(data, header) { let keys = this.getKeys(data, header); let newData = []; let _self = this; - data.map(function (item, index) { + await data.reduce(async function (prev, current) { + await prev; let newItem = {}; for (let label in keys) { let property = keys[label]; - newItem[label] = _self.getValue(property, item); + newItem[label] = await _self.getValue(property, current); } newData.push(newItem); - }); + + return true; + }, []); return newData; }, @@ -291,7 +294,7 @@ export default { return parseData; }, - getValue(key, item) { + async getValue(key, item) { const field = typeof key !== "object" ? key : key.field; let indexes = typeof field !== "string" ? [] : field.split("."); let value = this.defaultValue; @@ -302,7 +305,7 @@ export default { else value = this.parseValue(item[field]); if (key.hasOwnProperty("callback")) - value = this.getValueFromCallback(value, key.callback); + value = await this.getValueFromCallback(value, key.callback); return value; }, @@ -335,9 +338,9 @@ export default { return this.parseValue(nestedItem); }, - getValueFromCallback(item, callback) { + async getValueFromCallback(item, callback) { if (typeof callback !== "function") return this.defaultValue; - const value = callback(item); + const value = await callback(item); return this.parseValue(value); }, parseValue(value) { diff --git a/dist/vue-json-excel.cjs.js b/dist/vue-json-excel.cjs.js index 48b0d55..6bff9d7 100644 --- a/dist/vue-json-excel.cjs.js +++ b/dist/vue-json-excel.cjs.js @@ -271,7 +271,7 @@ var script = { return; } - let json = this.getProcessedJson(data, this.downloadFields); + let json = await this.getProcessedJson(data, this.downloadFields); if (this.type === "html") { // this is mainly for testing return this.export( @@ -412,18 +412,21 @@ var script = { --------------- Get only the data to export, if no fields are set return all the data */ - getProcessedJson(data, header) { + async getProcessedJson(data, header) { let keys = this.getKeys(data, header); let newData = []; let _self = this; - data.map(function (item, index) { + await data.reduce(async function (prev, current) { + await prev; let newItem = {}; for (let label in keys) { let property = keys[label]; - newItem[label] = _self.getValue(property, item); + newItem[label] = await _self.getValue(property, current); } newData.push(newItem); - }); + + return true; + }, []); return newData; }, @@ -456,7 +459,7 @@ var script = { return parseData; }, - getValue(key, item) { + async getValue(key, item) { const field = typeof key !== "object" ? key : key.field; let indexes = typeof field !== "string" ? [] : field.split("."); let value = this.defaultValue; @@ -467,7 +470,7 @@ var script = { else value = this.parseValue(item[field]); if (key.hasOwnProperty("callback")) - value = this.getValueFromCallback(value, key.callback); + value = await this.getValueFromCallback(value, key.callback); return value; }, @@ -500,9 +503,9 @@ var script = { return this.parseValue(nestedItem); }, - getValueFromCallback(item, callback) { + async getValueFromCallback(item, callback) { if (typeof callback !== "function") return this.defaultValue; - const value = callback(item); + const value = await callback(item); return this.parseValue(value); }, parseValue(value) { @@ -619,7 +622,11 @@ var __vue_render__ = function() { return _c( "div", { attrs: { id: _vm.idName }, on: { click: _vm.generate } }, - [_vm._t("default", [_vm._v(" Download " + _vm._s(_vm.name) + " ")])], + [ + _vm._t("default", function() { + return [_vm._v(" Download " + _vm._s(_vm.name) + " ")] + }) + ], 2 ) }; diff --git a/dist/vue-json-excel.esm.js b/dist/vue-json-excel.esm.js index 2d9535d..5d6d24a 100644 --- a/dist/vue-json-excel.esm.js +++ b/dist/vue-json-excel.esm.js @@ -269,7 +269,7 @@ var script = { return; } - let json = this.getProcessedJson(data, this.downloadFields); + let json = await this.getProcessedJson(data, this.downloadFields); if (this.type === "html") { // this is mainly for testing return this.export( @@ -410,18 +410,21 @@ var script = { --------------- Get only the data to export, if no fields are set return all the data */ - getProcessedJson(data, header) { + async getProcessedJson(data, header) { let keys = this.getKeys(data, header); let newData = []; let _self = this; - data.map(function (item, index) { + await data.reduce(async function (prev, current) { + await prev; let newItem = {}; for (let label in keys) { let property = keys[label]; - newItem[label] = _self.getValue(property, item); + newItem[label] = await _self.getValue(property, current); } newData.push(newItem); - }); + + return true; + }, []); return newData; }, @@ -454,7 +457,7 @@ var script = { return parseData; }, - getValue(key, item) { + async getValue(key, item) { const field = typeof key !== "object" ? key : key.field; let indexes = typeof field !== "string" ? [] : field.split("."); let value = this.defaultValue; @@ -465,7 +468,7 @@ var script = { else value = this.parseValue(item[field]); if (key.hasOwnProperty("callback")) - value = this.getValueFromCallback(value, key.callback); + value = await this.getValueFromCallback(value, key.callback); return value; }, @@ -498,9 +501,9 @@ var script = { return this.parseValue(nestedItem); }, - getValueFromCallback(item, callback) { + async getValueFromCallback(item, callback) { if (typeof callback !== "function") return this.defaultValue; - const value = callback(item); + const value = await callback(item); return this.parseValue(value); }, parseValue(value) { @@ -617,7 +620,11 @@ var __vue_render__ = function() { return _c( "div", { attrs: { id: _vm.idName }, on: { click: _vm.generate } }, - [_vm._t("default", [_vm._v(" Download " + _vm._s(_vm.name) + " ")])], + [ + _vm._t("default", function() { + return [_vm._v(" Download " + _vm._s(_vm.name) + " ")] + }) + ], 2 ) }; diff --git a/dist/vue-json-excel.umd.js b/dist/vue-json-excel.umd.js index bd2c0dc..92d7551 100644 --- a/dist/vue-json-excel.umd.js +++ b/dist/vue-json-excel.umd.js @@ -275,7 +275,7 @@ return; } - let json = this.getProcessedJson(data, this.downloadFields); + let json = await this.getProcessedJson(data, this.downloadFields); if (this.type === "html") { // this is mainly for testing return this.export( @@ -416,18 +416,21 @@ --------------- Get only the data to export, if no fields are set return all the data */ - getProcessedJson(data, header) { + async getProcessedJson(data, header) { let keys = this.getKeys(data, header); let newData = []; let _self = this; - data.map(function (item, index) { + await data.reduce(async function (prev, current) { + await prev; let newItem = {}; for (let label in keys) { let property = keys[label]; - newItem[label] = _self.getValue(property, item); + newItem[label] = await _self.getValue(property, current); } newData.push(newItem); - }); + + return true; + }, []); return newData; }, @@ -460,7 +463,7 @@ return parseData; }, - getValue(key, item) { + async getValue(key, item) { const field = typeof key !== "object" ? key : key.field; let indexes = typeof field !== "string" ? [] : field.split("."); let value = this.defaultValue; @@ -471,7 +474,7 @@ else value = this.parseValue(item[field]); if (key.hasOwnProperty("callback")) - value = this.getValueFromCallback(value, key.callback); + value = await this.getValueFromCallback(value, key.callback); return value; }, @@ -504,9 +507,9 @@ return this.parseValue(nestedItem); }, - getValueFromCallback(item, callback) { + async getValueFromCallback(item, callback) { if (typeof callback !== "function") return this.defaultValue; - const value = callback(item); + const value = await callback(item); return this.parseValue(value); }, parseValue(value) { @@ -623,7 +626,11 @@ return _c( "div", { attrs: { id: _vm.idName }, on: { click: _vm.generate } }, - [_vm._t("default", [_vm._v(" Download " + _vm._s(_vm.name) + " ")])], + [ + _vm._t("default", function() { + return [_vm._v(" Download " + _vm._s(_vm.name) + " ")] + }) + ], 2 ) }; diff --git a/package.json b/package.json index 86de058..47d11bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-json-excel", - "version": "0.3.0", + "version": "0.4.0", "description": "Download your JSON as an excel or CSV file directly from the browser", "main": "dist/vue-json-excel.umd.js", "module": "dist/vue-json-excel.esm.js", @@ -41,4 +41,4 @@ "rollup-plugin-vue": "^4.7.2", "vue-template-compiler": "^2.6.10" } -} \ No newline at end of file +}