ichigoo
Version:
Static site generator with React and GraphQL
49 lines (45 loc) • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
/**
* Gets a list of values indexed by field based on a list of entities
*
* @example
* const entities = [
* {
* id: 1,
* title: "Lorem Ipsum",
* views: 254,
* user_id: 123,
* },
* {
* id: 2,
* title: "Sic Dolor amet",
* views: 65,
* user_id: 456,
* },
* ];
* getValuesFromEntities(entities);
* // {
* // id: [1, 2],
* // title: ["Lorem Ipsum", "Sic Dolor amet"],
* // views: [254, 65],
* // user_id: [123, 456],
* // }
*/
var _default = function _default(entities) {
return entities.reduce(function (values, entity) {
Object.keys(entity).forEach(function (fieldName) {
if (!values[fieldName]) {
values[fieldName] = [];
}
if (entity[fieldName] != null) {
values[fieldName].push(entity[fieldName]);
}
});
return values;
}, {});
};
exports["default"] = _default;