speedwalk
v0.1.0
Published
Walk an entire directory. Fast, simple, and asynchronous.
Downloads
68
Maintainers
Readme
SpeedWalk
Walk an entire directory. Fast, simple, and asynchronous.
Features
- Zero dependencies. Small bundle size.
- Written in TypeScript.
- Fast and asynchronous. Suitable for large directories. Fastest tree-traversal solution on NPM.
- Dead simple. Modeled after Golang's
filepath.Walk
. - Modern ESModules support.
Comparisons
Some comparisons between speedwalk and other Node.js libraries that provide tree-traversal solutions.
All tests were conducted on the same large directory. Each result is the average of each library's time to complete the walk with no custom functions provided.
|Package|Result|
|-|-|
|speedwalk
|6.95ms|
|walk
|13826.33ms|
|@root/walk
|276.96ms|
|walker
|296.05ms|
Usage
Import the walk
function from the package. To call it, pass in a root directory and a callback function accepting a path
and a dirent
.
import { walk } from 'speedwalk';
await walk('./', (path, dirent) => {
console.log('Path:', path);
console.log('Is a file:', dirent.isFile());
if (dirent.isDirectory() && dirent.name === 'node_modules') {
// Tell "walk" to skip the traversal of a certain
// directory by returning "true" from the callback.
return true;
}
});
The function will asynchronously walk through the root directory and all subsequent directories until the entire tree has been traversed.