@@ -4,7 +4,7 @@ const format = require('format-io');
44const currify = require ( 'currify' ) ;
55const tryToCatch = require ( 'try-to-catch' ) ;
66
7- const sortify = currify ( require ( '@cloudcmd/sortify' ) ) ;
7+ const sortify = require ( '@cloudcmd/sortify' ) ;
88const formatify = require ( '@cloudcmd/formatify' ) ;
99
1010const WIN = process . platform === 'win32' ;
@@ -15,6 +15,7 @@ const replaceProperty = currify(_replaceProperty);
1515const nicki = ! WIN && require ( 'nicki' ) ;
1616
1717const readdir = require ( './readdir' ) ;
18+ const isString = ( a ) => typeof a === 'string' ;
1819
1920module . exports = readify ;
2021
@@ -25,8 +26,12 @@ async function readify(path, options = {}) {
2526 sort = 'name' ,
2627 } = options ;
2728
28- check ( path , type ) ;
29- checkSort ( sort , order ) ;
29+ check ( {
30+ path,
31+ type,
32+ sort,
33+ order,
34+ } ) ;
3035
3136 const names = await readdir ( path ) ;
3237
@@ -36,21 +41,14 @@ async function readify(path, options = {}) {
3641 return await fillJSON ( path , type , formated ) ;
3742}
3843
39- function check ( path , type ) {
40- const isString = ( a ) => typeof a === 'string' ;
41-
42- const pathMsg = 'path should be string!' ;
43- const typeMsg = 'type should be a string or not to be defined!' ;
44-
44+ function check ( { path, type, sort, order} ) {
4545 if ( ! isString ( path ) )
46- throw Error ( pathMsg ) ;
46+ throw Error ( 'path should be string!' ) ;
4747
4848 if ( type && ! isString ( type ) )
49- throw Error ( typeMsg ) ;
50- }
51-
52- function checkSort ( sort , order ) {
53- if ( sort && typeof sort !== 'string' )
49+ throw Error ( 'type should be a string or not to be defined!' ) ;
50+
51+ if ( sort && ! isString ( sort ) )
5452 throw Error ( 'sort should be a string!' ) ;
5553
5654 if ( order && ! / ^ ( a s c | d e s c ) $ / . test ( order ) )
0 commit comments