Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function makeSorter (query, options) {
// The sort function (if $sort is set)
const sorter = query.$sort ? createSorter(query.$sort) : createSorter({
[options.idField]: 1
});
return function (result) {
const isPaginated = !!result[options.dataField];
let data = isPaginated ? result[options.dataField] : result;
if (sorter) {
data = data.sort(sorter);
}
const limit = typeof result.limit === 'number' ? result.limit : parseInt(query.$limit, 10);
if (limit && !isNaN(limit) && limit !== -1) {
data = data.slice(0, limit);
}