
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
directory-tree
Advanced tools
#directory-tree
Creates an javascript object representing a directory tree.
npm i -S directory-tree
##Usage
var dirTree = require('directory-tree');
var tree = dirTree('/some/path');
And you can also filter by extensions:
var dirTree = require('directory-tree');
var filteredTree = dirTree('/some/path', ['.jpg', '.png']);
This will take a directory tree:
photos
āāā summer
āĀ Ā āāā june
āĀ Ā āāā windsurf.jpg
āāā winter
āāā january
āāā ski.png
āāā snowboard.jpg
And return a js object:
{
"path": "photos",
"name": "photos",
"size": 600,
"children": [
{
"path": "photos/summer",
"name": "summer",
"size": 400,
"children": [
{
"path": "photos/summer/june",
"name": "june",
"size": 400,
"children": [
{
"path": "photos/summer/june/windsurf.jpg",
"name": "windsurf.jpg",
"size": 400,
"extension": ".jpg"
}
]
}
]
},
{
"path": "photos/winter",
"name": "winter",
"size": 200,
"children": [
{
"path": "photos/winter/january",
"name": "january",
"size": 200,
"children": [
{
"path": "photos/winter/january/ski.png",
"name": "ski.png",
"size": 100,
"extension": ".png"
},
{
"path": "photos/winter/january/snowboard.jpg",
"name": "snowboard.jpg",
"size": 100,
"extension": ".jpg"
}
]
}
]
}
]
}
Device, FIFO and socket files are ignored.
Files to which the user does not have permissions are included in the directory tree, however, directories to which the user does not have permissions, along with all of its contained files, are completely ignored.
To run tests go the package root in your CLI and run,
$ npm test
Make sure you have the dev dependcies installed (e.g. npm install .
)
Check out version 0.1.1
if you need support for older versions of node.
FAQs
Convert a directory tree to a JS object.
The npm package directory-tree receives a total of 102,130 weekly downloads. As such, directory-tree popularity was classified as popular.
We found that directory-tree demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Ā It has 1 open source maintainer 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.