Skip to content

Commit f415897

Browse files
committed
feature(package) superstat v2.0.0
1 parent baa9231 commit f415897

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

lib/readdir.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,29 @@ const {readdir} = require('fs').promises;
55

66
const tryToCatch = require('try-to-catch');
77
const superstat = require('superstat');
8+
const currify = require('currify');
89

910
const noop = function() {};
1011

11-
const {assign} = Object;
12+
const stat = currify(async (dir, name) => {
13+
const full = join(dir, name);
14+
const [, info = empty(name)] = await tryToCatch(superstat, full);
15+
16+
return info;
17+
});
1218

1319
module.exports = async (dir) => {
14-
const result = [];
1520
const names = await readdir(dir);
1621

17-
for (const name of names) {
18-
const full = join(dir, name);
19-
const [
20-
,
21-
info = empty(),
22-
] = await tryToCatch(superstat, full);
23-
24-
result.push(parseStat(assign(info, {
25-
name,
26-
})));
27-
}
22+
const statsPromises = names.map(stat(dir));
23+
const stats = await Promise.all(statsPromises);
2824

29-
return result;
25+
return stats.map(parseStat);
3026
};
3127

32-
function empty() {
28+
function empty(name) {
3329
return {
30+
name,
3431
uid: 0,
3532
mode: 0,
3633
size: 0,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"format-io": "^2.0.0",
3232
"nicki": "^5.0.0",
3333
"shortdate": "^2.0.0",
34-
"superstat": "^1.0.0",
34+
"superstat": "^2.0.0",
3535
"try-to-catch": "^3.0.0"
3636
},
3737
"keywords": [

test/readify.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,10 @@ test('readify: sort: name: desc', async (t) => {
384384
const sort = 'name';
385385
const order = 'desc';
386386

387+
const getName = ({name}) => name;
388+
387389
const data = await readify('./test/fixture/attr_sort', {sort, order});
388-
data.files = data.files
389-
.map((file) => file.name);
390+
data.files = data.files.map(getName);
390391

391392
t.deepEqual(data.files, files, 'should equal');
392393
t.end();

0 commit comments

Comments
 (0)