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.

29 lines
459 B

const lodashOrderBy = require('lodash.orderby')
/**
* order results by keys
*
* @param {object} options
* @param {object} results
*
* @return {object}
*
*/
function orderBy(options, results) {
options.forEach((key, index) => {
let direction = 'asc'
if (key.charAt(0) === '-') {
key = key.slice(1, key.length)
direction = 'desc'
}
results = lodashOrderBy(results, key, direction)
})
return results
}
module.exports = orderBy