You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

20 lines
443 B

const _ = require('lodash');
function setup(comparator, should_execute) {
function middleware(req, res, next) {
// bail early if req/res don't pass conditions for execution or there's no data to sort
if (!should_execute(req, res) || _.isEmpty(res.data)) {
return next();
}
// sort operates on array in place
res.data.sort(comparator(req.clean));
next();
}
return middleware;
}
module.exports = setup;