diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-09-17 15:24:50 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-09-17 15:24:50 +0300 |
commit | 2a287f317a51f5f02b643af0acf2733cadbb8081 (patch) | |
tree | 725983c2fc98dfee2b7ed826f4fccb3bee6ca45a /src/deepReadDir.tsx | |
download | benzin-next-2a287f317a51f5f02b643af0acf2733cadbb8081.tar.gz |
feat: initial commit
Diffstat (limited to 'src/deepReadDir.tsx')
-rw-r--r-- | src/deepReadDir.tsx | 12 |
1 files changed, 12 insertions, 0 deletions
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<string[]> => 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; |