Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mstephen19/speedwalk
Walk an entire directory. Fast, simple, and asynchronous.
https://github.com/mstephen19/speedwalk
asynchronous esmodules javascript nodejs npm tree typescript
Last synced: 24 days ago
JSON representation
Walk an entire directory. Fast, simple, and asynchronous.
- Host: GitHub
- URL: https://github.com/mstephen19/speedwalk
- Owner: mstephen19
- Created: 2023-01-11T19:14:44.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-24T19:36:23.000Z (almost 2 years ago)
- Last Synced: 2024-11-21T11:12:16.471Z (about 1 month ago)
- Topics: asynchronous, esmodules, javascript, nodejs, npm, tree, typescript
- Language: Go
- Homepage: https://www.npmjs.com/package/speedwalk
- Size: 3.57 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SpeedWalk
[![Install size](https://packagephobia.com/badge?p=speedwalk@latest)](https://packagephobia.com/result?p=speedwalk@latest)
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`](https://pkg.go.dev/path/filepath#Walk).
- Modern [ESModules](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/) 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`.
```TypeScript
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.