@tidyjs/tidy
Version:
Tidy up your data with JavaScript, inspired by dplyr and the tidyverse
28 lines (23 loc) • 946 B
JavaScript
Object.defineProperty(exports, '__esModule', { value: true });
var innerJoin = require('./innerJoin.js');
function leftJoin(itemsToJoin, options) {
const _leftJoin = (items) => {
if (!itemsToJoin.length)
return items;
const byMap = (options == null ? void 0 : options.by) == null ? innerJoin.autodetectByMap(items, itemsToJoin) : innerJoin.makeByMap(options.by);
const joinObjectKeys = Object.keys(itemsToJoin[0]);
const joined = items.flatMap((d) => {
const matches = itemsToJoin.filter((j) => innerJoin.isMatch(d, j, byMap));
if (matches.length) {
return matches.map((j) => ({...d, ...j}));
}
const undefinedFill = Object.fromEntries(joinObjectKeys.filter((key) => d[key] == null).map((key) => [key, void 0]));
return {...d, ...undefinedFill};
});
return joined;
};
return _leftJoin;
}
exports.leftJoin = leftJoin;
//# sourceMappingURL=leftJoin.js.map
;