svelte-ux
Version:
- Increment version in `package.json` and commit as `Version bump to x.y.z` - `npm run publish`
23 lines (22 loc) • 631 B
JavaScript
import { rollup } from 'd3-array';
import { get, isFunction } from 'lodash-es';
export default function (data, reduce, keys = [], emptyKey = 'Unknown') {
// TODO: Fix object[] type if needed
// if (keys.length === 0) {
// return data;
// }
const keyFuncs = keys.map((key) => {
if (isFunction(key)) {
return key;
}
else if (typeof key === 'string') {
return (d) => get(d, key) || emptyKey;
}
else {
return () => 'Overall';
}
});
// TODO: Improve types
// @ts-ignore
return rollup(data, reduce, ...keyFuncs);
}