42 lines
1.2 KiB
Java
42 lines
1.2 KiB
Java
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var tslib_1 = require("tslib");
|
|
function get(row, path) {
|
|
var e_1, _a;
|
|
if (!path.includes('.'))
|
|
return row[path];
|
|
var attrs = path.split('.');
|
|
var result = row;
|
|
try {
|
|
for (var attrs_1 = tslib_1.__values(attrs), attrs_1_1 = attrs_1.next(); !attrs_1_1.done; attrs_1_1 = attrs_1.next()) {
|
|
var attr = attrs_1_1.value;
|
|
try {
|
|
result = result[attr];
|
|
}
|
|
catch (_b) {
|
|
result = undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
finally {
|
|
try {
|
|
if (attrs_1_1 && !attrs_1_1.done && (_a = attrs_1.return)) _a.call(attrs_1);
|
|
}
|
|
finally { if (e_1) throw e_1.error; }
|
|
}
|
|
return result;
|
|
}
|
|
function project(rows, options) {
|
|
var fields = options.fields, _a = options.as, as = _a === void 0 ? [] : _a;
|
|
return rows.map(function (row) {
|
|
var result = {};
|
|
fields.forEach(function (item, index) {
|
|
result[as[index] || item] = get(row, item);
|
|
});
|
|
return result;
|
|
});
|
|
}
|
|
exports.project = project;
|