File tree Expand file tree Collapse file tree 3 files changed +16
-18
lines changed Expand file tree Collapse file tree 3 files changed +16
-18
lines changed Original file line number Diff line number Diff line change @@ -5,32 +5,29 @@ const {readdir} = require('fs').promises;
5
5
6
6
const tryToCatch = require ( 'try-to-catch' ) ;
7
7
const superstat = require ( 'superstat' ) ;
8
+ const currify = require ( 'currify' ) ;
8
9
9
10
const noop = function ( ) { } ;
10
11
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
+ } ) ;
12
18
13
19
module . exports = async ( dir ) => {
14
- const result = [ ] ;
15
20
const names = await readdir ( dir ) ;
16
21
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 ) ;
28
24
29
- return result ;
25
+ return stats . map ( parseStat ) ;
30
26
} ;
31
27
32
- function empty ( ) {
28
+ function empty ( name ) {
33
29
return {
30
+ name,
34
31
uid : 0 ,
35
32
mode : 0 ,
36
33
size : 0 ,
Original file line number Diff line number Diff line change 31
31
"format-io" : " ^2.0.0" ,
32
32
"nicki" : " ^5.0.0" ,
33
33
"shortdate" : " ^2.0.0" ,
34
- "superstat" : " ^1 .0.0" ,
34
+ "superstat" : " ^2 .0.0" ,
35
35
"try-to-catch" : " ^3.0.0"
36
36
},
37
37
"keywords" : [
Original file line number Diff line number Diff line change @@ -384,9 +384,10 @@ test('readify: sort: name: desc', async (t) => {
384
384
const sort = 'name' ;
385
385
const order = 'desc' ;
386
386
387
+ const getName = ( { name} ) => name ;
388
+
387
389
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 ) ;
390
391
391
392
t . deepEqual ( data . files , files , 'should equal' ) ;
392
393
t . end ( ) ;
You can’t perform that action at this time.
0 commit comments