@@ -19,7 +19,6 @@ import {
1919 ImplementationData , ImplementationTable ,
2020 Implementer , ReportData ,
2121 ReqType ,
22- // Obsolete,
2322 Constants ,
2423} from './types.ts' ;
2524
@@ -83,23 +82,32 @@ async function get_opf(dirname: string): Promise<string> {
8382
8483/**
8584 * See if a file name path refers to a real file.
86- * Note: this function is only used in the utilities, not in the main program.
85+ * Note: this function is also used in the utilities, not in the main program.
8786 *
8887 * @internal
8988 */
90- export function isDirectory ( name : string ) : boolean {
91- return Deno . lstatSync ( name ) . isDirectory ;
89+ export function isDirectory ( name : string | Deno . DirEntry ) : boolean {
90+ if ( typeof name === 'string' ) {
91+ return Deno . lstatSync ( name ) . isDirectory ;
92+ } else {
93+ return name . isDirectory ;
94+ }
9295}
9396
9497
98+
9599/**
96100 * See if a file name path refers to a real file.
97- * Note: this function is only used in the utilities, not in the main program.
101+ * Note: this function is also used in the utilities, not in the main program.
98102 *
99103 * @internal
100104 */
101- export function isFile ( name : string ) : boolean {
102- return Deno . lstatSync ( name ) . isFile ;
105+ export function isFile ( name : string | Deno . DirEntry ) : boolean {
106+ if ( typeof name === 'string' ) {
107+ return Deno . lstatSync ( name ) . isFile ;
108+ } else {
109+ return name . isFile ;
110+ }
103111}
104112
105113
@@ -110,21 +118,21 @@ export function isFile(name: string): boolean {
110118 * Depending on the final configuration some filters may have to be added.)
111119 *
112120 * @param dir_name name of the directory
113- * @param filter_name a function to filter the retrieved list (e.g., no directories)
121+ * @param filter_entry a function to filter the retrieved list (e.g., no directories)
114122 * @returns lists of files in the directory
115123 */
116- export async function getListDir ( dir_name : string , filter_name : ( name : string ) => boolean = ( _name : string ) => true ) : Promise < string [ ] > {
124+ export async function getListDir ( dir_name : string , filter_entry : ( entry : Deno . DirEntry ) => boolean ) : Promise < string [ ] > {
117125 // The filter works on the full path, hence this extra layer
118- const file_name_filter = ( name : string ) : boolean => {
126+ const file_name_filter = ( entry : Deno . DirEntry ) : boolean => {
119127 // The 'xx-' prefix are used for the template tests
120- return name . startsWith ( 'xx-' ) === false && filter_name ( ` ${ dir_name } / ${ name } ` ) ;
128+ return entry . name . startsWith ( 'xx-' ) === false && filter_entry ( entry ) ;
121129 }
122130 try {
123- const file_names : string [ ] = [ ] ;
131+ const file_names : Deno . DirEntry [ ] = [ ] ;
124132 for await ( const entry of Deno . readDir ( dir_name ) ) {
125- file_names . push ( entry . name ) ;
133+ file_names . push ( entry ) ;
126134 }
127- return file_names . filter ( file_name_filter )
135+ return file_names . filter ( file_name_filter ) . map ( ( entry : Deno . DirEntry ) : string => entry . name ) ;
128136 } catch ( error ) {
129137 console . warn ( `Directory "${ dir_name } " could not be accessed ()` ) ;
130138 throw ( `Directory "${ dir_name } " could not be accessed (${ error } )` ) ;
0 commit comments