@tidyjs/tidy
Version:
Tidy up your data with JavaScript, inspired by dplyr and the tidyverse
24 lines (21 loc) • 856 B
JavaScript
import { autodetectByMap, makeByMap, isMatch } from './innerJoin.js';
function leftJoin(itemsToJoin, options) {
const _leftJoin = (items) => {
if (!itemsToJoin.length)
return items;
const byMap = (options == null ? void 0 : options.by) == null ? autodetectByMap(items, itemsToJoin) : makeByMap(options.by);
const joinObjectKeys = Object.keys(itemsToJoin[0]);
const joined = items.flatMap((d) => {
const matches = itemsToJoin.filter((j) => 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;
}
export { leftJoin };
//# sourceMappingURL=leftJoin.js.map