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;
55
66const tryToCatch = require ( 'try-to-catch' ) ;
77const superstat = require ( 'superstat' ) ;
8+ const currify = require ( 'currify' ) ;
89
910const 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
1319module . 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 ,
Original file line number Diff line number Diff line change 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" : [
Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments