xero-hero
Version:
Heroic utilities to simplify and enable your progress with the [xero-node](https://www.npmjs.com/package/xero-node) SDK.
30 lines • 671 B
JavaScript
// src/utils/map.ts
var getKey = (item, property) => {
return typeof property === "function" ? property(item) : item[property];
};
var keyBy = (ar, property) => {
return (ar || []).reduce(
(accumulator, item) => {
const key = getKey(item, property);
accumulator[key] = item;
return accumulator;
},
{}
);
};
var groupBy = (ar, property) => {
return (ar || []).reduce(
(accumulator, item) => {
const key = getKey(item, property);
accumulator[key] = accumulator[key] || [];
accumulator[key].push(item);
return accumulator;
},
{}
);
};
export {
groupBy,
keyBy
};
//# sourceMappingURL=map.mjs.map