UNPKG

ze-react-component-library

Version:
44 lines (37 loc) 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _underscore = _interopRequireDefault(require("underscore")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } var _default = function _default(data, config) { var groupedData = _underscore.default.groupBy(data, function (i) { return config.rows.map(function (r) { return _typeof(i[r]) === "object" ? i[r]._id : i[r]; }).join(""); }); var result = []; Object.entries(groupedData).forEach(function (_a) { var key = _a[0], array = _a[1]; var resultItem = { _id: key }; config.rows.forEach(function (r) { resultItem[r] = array[0][r]; }); array.forEach(function (arrayItem) { var newKey = config.cols.map(function (c) { return _typeof(arrayItem[c]) === "object" ? arrayItem[c]._id : arrayItem[c]; }).join(""); config.values.forEach(function (vKey) { resultItem["" + newKey + vKey] = arrayItem[vKey]; }); }); result.push(resultItem); }); return result; }; exports.default = _default;