From 2a287f317a51f5f02b643af0acf2733cadbb8081 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 17 Sep 2022 15:24:50 +0300 Subject: feat: initial commit --- src/deepReadDir.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/deepReadDir.tsx (limited to 'src/deepReadDir.tsx') diff --git a/src/deepReadDir.tsx b/src/deepReadDir.tsx new file mode 100644 index 0000000..ec585ec --- /dev/null +++ b/src/deepReadDir.tsx @@ -0,0 +1,12 @@ +import {lstat, readdir} from 'node:fs/promises' +import {join} from 'node:path' + +const deepReadDir = async (dirPath: string): Promise => await Promise.all( + (await readdir(dirPath)).map(async (entity) => { + const path = join(dirPath, entity) + return (await lstat(path)).isDirectory() ? await deepReadDir(path) : path + }), +).then(arr => arr.flat()); + + +export default deepReadDir; -- cgit v1.2.3