Skip to content

Commit

Permalink
try to be less messy
Browse files Browse the repository at this point in the history
  • Loading branch information
quazardous committed Jan 8, 2017
1 parent 97a8903 commit d38a7ea
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/readify.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ const readdir = promisify(fs.readdir, fs);

/* sorting on Win and node v0.8.0 */
const sortFiles = currify((attr, order, array) => {
const cmpCallbacks = {
'numeric': (a, b) => (+a - +b),
'local_string': (a, b) => a.localeCompare(b.attr),
'default': (a, b) => (a > b ? 1 : -1),
};
switch (order) {
case 'asc':
// nothing
Expand All @@ -45,20 +50,20 @@ const sortFiles = currify((attr, order, array) => {
var cmp;
switch (attr) {
case 'size':
cmp = (a, b) => (+a - +b);
cmp = cmpCallbacks.numeric;
break;
case 'date':
cmp = (a, b) => (a > b ? 1 : -1);
cmp = cmpCallbacks['default'];
break;
case 'owner':
cmp = (a, b) => (a > b ? 1 : -1);
cmp = cmpCallbacks['default'];
break;
case 'name':
cmp = (a, b) => a.localeCompare(b.attr);
cmp = cmpCallbacks.local_string;
break;
default:
attr = 'name';
cmp = (a, b) => a.localeCompare(b.attr);
cmp = cmpCallbacks.local_string;
}
return sort((a, b) => {
var res = cmp(a[attr], b[attr]);
Expand Down

0 comments on commit d38a7ea

Please sign in to comment.