lazy-fs-walker
v0.1.2
Published
Node.js lazy file system walker.
Downloads
7
Readme
lazy-fs-walker
Node.js lazy file system walker.
How to use
yarn add lazy-fs-walker
Example
const walker = require('lazy-fs-walker')
const files = (await walker(require('os').homedir())).map(f => f.name)
API
The async walker
function receive two arguments, root
and options
.
export default function LazyFSWalker(root: string, options?: LazyFSWalkerOptions): Promise<LazyFSWalkerReturns>;
The root
is a dirname which you want to start walking.
The options
is an object and the definition is:
interface LazyFSWalkerOptions {
keepHidden: boolean;
onlyDir: boolean;
}
keepHidden
: keep hidden files in result, defaultfalse
onlyDir
: only emit dirs to result, defaultfalse
The walker
return a files array and the definition is:
interface LazyFSWalkerFilename {
readonly name: string;
}
interface LazyFSWalkerFile extends LazyFSWalkerFilename {
readonly walker: null;
}
interface LazyFSWalkerDir extends LazyFSWalkerFilename {
readonly walker: () => Promise<LazyFSWalkerReturns>;
}
declare type LazyFSWalkerReturns = ReadonlyArray<LazyFSWalkerDir | LazyFSWalkerFile>;
As u see, the walker
is lazy because it won't deep in sub-dirs at once. You must call the walker
by hand, like this:
test('should walk to lazy-fs-walker.ts', async () => {
const src = (await walker('.')).filter(f => f.name === 'src')[0]
const main = (await src.walker())[0].name
expect(main).toBe('lazy-fs-walker.ts')
})
License
MIT