opt-table
Version:
A Responsive and Customizable Rich Table
31 lines • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.stableSort = exports.getComparator = void 0;
function getComparator(order, orderBy) {
return order === "desc"
? (a, b) => descendingComparator(a, b, orderBy)
: (a, b) => -descendingComparator(a, b, orderBy);
}
exports.getComparator = getComparator;
function descendingComparator(a, b, orderBy) {
if (b[orderBy] < a[orderBy]) {
return -1;
}
if (b[orderBy] > a[orderBy]) {
return 1;
}
return 0;
}
function stableSort(array, comparator) {
const stabilizedThis = array === null || array === void 0 ? void 0 : array.map((el, index) => [el, index]);
stabilizedThis === null || stabilizedThis === void 0 ? void 0 : stabilizedThis.sort((a, b) => {
const order = comparator(a[0], b[0]);
if (order !== 0) {
return order;
}
return a[1] - b[1];
});
return stabilizedThis === null || stabilizedThis === void 0 ? void 0 : stabilizedThis.map((el) => el[0]);
}
exports.stableSort = stableSort;
//# sourceMappingURL=table_utils.js.map