Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sort(list) {
const { sort } = this.props;
const typeof_sort = typeof sort;
if (typeof_sort === 'function') { return sort(list); }
if (['string', 'undefined'].includes(typeof_sort)) {
const sort_str = sort? sort : 'lastModified';
const parts = sort_str.split(/\s+/);
const field = parts[0];
let dir = parts.length > 1? parts[1] : '';
if (field === 'lastModified') {
dir = (dir === 'asc')? 'asc' : 'desc';
} else {
dir = (dir === 'desc')? 'desc' : 'asc';
}
JS.sortByField(list, field, dir);
return list;
}
logger.warn('invalid sort. done nothing. should be a string or function');
return list;
}