get-files.ts 403 B

1234567891011
  1. import * as fs from 'node:fs';
  2. import * as path from 'node:path';
  3. export async function getFiles (
  4. dir: string,
  5. test: ((file: string) => boolean) = (_: string) => true // eslint-disable-line @typescript-eslint/no-unused-vars
  6. ): Promise<string[]> {
  7. return fs.promises.readdir(dir)
  8. .then(files => files.map(file => path.join(dir, file)))
  9. .then(files => files.filter(file => test(file)));
  10. }