Skip to content

Commit

Permalink
feature(package) superstat v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Apr 14, 2020
1 parent baa9231 commit f415897
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
27 changes: 12 additions & 15 deletions lib/readdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,29 @@ const {readdir} = require('fs').promises;

const tryToCatch = require('try-to-catch');
const superstat = require('superstat');
const currify = require('currify');

const noop = function() {};

const {assign} = Object;
const stat = currify(async (dir, name) => {
const full = join(dir, name);
const [, info = empty(name)] = await tryToCatch(superstat, full);

return info;
});

module.exports = async (dir) => {
const result = [];
const names = await readdir(dir);

for (const name of names) {
const full = join(dir, name);
const [
,
info = empty(),
] = await tryToCatch(superstat, full);

result.push(parseStat(assign(info, {
name,
})));
}
const statsPromises = names.map(stat(dir));
const stats = await Promise.all(statsPromises);

return result;
return stats.map(parseStat);
};

function empty() {
function empty(name) {
return {
name,
uid: 0,
mode: 0,
size: 0,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"format-io": "^2.0.0",
"nicki": "^5.0.0",
"shortdate": "^2.0.0",
"superstat": "^1.0.0",
"superstat": "^2.0.0",
"try-to-catch": "^3.0.0"
},
"keywords": [
Expand Down
5 changes: 3 additions & 2 deletions test/readify.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,10 @@ test('readify: sort: name: desc', async (t) => {
const sort = 'name';
const order = 'desc';

const getName = ({name}) => name;

const data = await readify('./test/fixture/attr_sort', {sort, order});
data.files = data.files
.map((file) => file.name);
data.files = data.files.map(getName);

t.deepEqual(data.files, files, 'should equal');
t.end();
Expand Down

0 comments on commit f415897

Please sign in to comment.