Security News
npm Updates Search Experience with New Objective Sorting Options
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
@universal-packages/directory-traversal
Advanced tools
Simple tool to traverse a directory deeply and get desired info
Sometimes you just need a way to map a directory to either load modules in real time or just get the available files to run a task, directory traversal will map a directory for you and deliver a convenient DirectoryMap
object for you.
npm install @universal-packages/directory-traversal
traverse(locations: String, [options])
The traverse function will go recursively from a root directory until it maps the whole tree, you can execute a callback for every visited directory after being mapped, limit the depth and filter for files you want or you not want to be mapped, returning a DirectoryMap
object
import { traverse } from '@universal-packages/directory-traversal'
const directoryMap = traverse('~/projects')
console.log(directoryMap)
You can modify the behavior of the traverse function by providing options.
callback
Function
A function to call for every mapped directory for you to analyze in place, return false if you want to stop going deeper into that directory.
const directoryMap = traverse('~/projects', {
callback: (directoryMap) => {
if (directoryMap.path.include('homework')) {
return false
}
}
})
fileFilter
(yml | yaml | js | json)[] | Regex
To only include files that satisfies this condition.
maxDepth
Number
To only map files going this level deep.
From the traverse example you will get something like this:
{
"path": "home/projects",
"files": [],
"directories": [
{
"path": "home/projects/universal-directory-traversal",
"files": [
"home/projects/universal-directory-traversal/.editorconfig",
"home/projects/universal-directory-traversal/.gitignore",
"home/projects/universal-directory-traversal/CODE-OF-CONDUCT.md",
"home/projects/universal-directory-traversal/CONTRIBUTING.md",
"home/projects/universal-directory-traversal/LICENSE.md",
"home/projects/universal-directory-traversal/README.md",
"home/projects/universal-directory-traversal/package-lock.json",
"home/projects/universal-directory-traversal/package.json",
"home/projects/universal-directory-traversal/tsconfig.dis.json",
"home/projects/universal-directory-traversal/tsconfig.json"
],
"directories": []
}
]
}
This library is developed in TypeScript and shipped fully typed.
The development of this library happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving this library.
FAQs
Simple tool to traverse a directory deeply and get desired info
We found that @universal-packages/directory-traversal demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.