eslint-formatter-summary
Version:
ESLint summary formatter aggregating results by rule
20 lines (19 loc) • 650 B
JavaScript
;
export const lengthOfLongest = (prop, items) => items.reduce(
(length, item) => typeof item[prop] !== "undefined" ? Math.max(length, (item[prop] ?? 0).toString().length) : length,
0
);
export const padNumber = (num, len) => num.toString().padStart(len);
export const sum = (prop, array) => array.reduce((count, obj) => count + obj[prop], 0);
export const sortBy = (prop, items, direction) => {
items.sort((a, b) => {
if (a[prop] < b[prop]) {
return direction === "asc" ? -1 : 1;
}
if (a[prop] > b[prop]) {
return direction === "asc" ? 1 : -1;
}
return 0;
});
};
//# sourceMappingURL=utils.js.map