Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

directory-tree

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

directory-tree - npm Package Compare versions

Comparing version 3.0.1 to 3.1.0

bin/index.js

1

index.d.ts

@@ -28,2 +28,3 @@ import { Stats } from 'fs';

followSymlink ? : boolean;
depth ? : number;
}

@@ -30,0 +31,0 @@ export type DirectoryTreeCallback = (item: DirectoryTree, path: string, stats: Stats) => void;

14

lib/directory-tree.js

@@ -51,3 +51,7 @@ 'use strict';

*/
function directoryTree (path, options, onEachFile, onEachDirectory) {
function directoryTree (path, options, onEachFile, onEachDirectory, currentDepth = 0) {
if (options.depth !== undefined && options.attributes.indexOf('size') !== -1) {
throw new Error('usage of size attribute with depth option is prohibited');
}
const name = PATH.basename(path);

@@ -123,5 +127,7 @@ options = options || {};

item.children = dirData
.map(child => directoryTree(PATH.join(path, child), options, onEachFile, onEachDirectory))
.filter(e => !!e);
if (options.depth === undefined || options.depth > currentDepth) {
item.children = dirData
.map(child => directoryTree(PATH.join(path, child), options, onEachFile, onEachDirectory, currentDepth + 1))
.filter(e => !!e);
}

@@ -128,0 +134,0 @@ if (options.attributes) {

{
"name": "directory-tree",
"version": "3.0.1",
"version": "3.1.0",
"description": "Convert a directory tree to a JS object.",

@@ -20,2 +20,6 @@ "repository": {

"homepage": "https://github.com/mihneadb/node-directory-tree",
"dependencies": {
"command-line-args": "^5.2.0",
"command-line-usage": "^6.1.1"
},
"devDependencies": {

@@ -25,2 +29,3 @@ "chai": "^2.3.0",

},
"bin": "bin/index.js",
"engines": {

@@ -27,0 +32,0 @@ "node": ">=10.0"

@@ -86,2 +86,4 @@ [![Build Status](https://api.travis-ci.com/mihneadb/node-directory-tree.svg?branch=master)](https://api.travis-ci.com/mihneadb/node-directory-tree.svg?branch=master)

`depth` : `number` - If presented, reads so many nested dirs as specified in argument. Usage of size attribute with depth option is prohibited.
## Result

@@ -190,1 +192,20 @@

Check out version `0.1.1` if you need support for older versions of Node.
## CLI usage
You can use script directly from command line for generating json data.
```bash
$ npx directory-tree --help
```
```bash
$ npx directory-tree --path /Users/user/target --attributes type,extension --pretty -o ./xz.json --depth 1
```
### Available options
-p, --path string 🗂 The input folder to process. Required.
-e, --exclude string 🐒 Exclude some folders from processing by regexp string. Ex -e "test_data/some_dir$|js|.DS_Store"
-o, --output string 📝 Put result into file provided by this options. Overwrites if exists.
-d, --depth number ☞ Reads dirs in deep as specified. Usage of size attribute with depth option is prohibited.
--attributes string ℹ️ Grab file attributes. Example: --attributes size,type,extension. Usage of size attribute with depth option is prohibited
--pretty 💎 Json pretty print
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc