
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
dir-parser
Advanced tools
Parse a directory and generate it's structure tree.

$ npm install dir-parser -g
$ parser -h
Usage: parser [options]
Options:
-V, --version output the version number
-v, --version
-d, --directory [directory] Target directory, default: "./"
-o, --output [output] Output path, default: "./"
-l, --lineType [lineType] Line type of tree (dashed | solid), default: solid.
-e, --excludes [excludes] Exclude some directories or files by name.
-x, --excPaths [excPaths] Exclude some directories or files by path.
-r, --patterns [patterns] Exclude some directories or files by RegExp.
-c, --config [config] Parser config file.
-f, --filesFirst Print files first, before than directories.
-n, --noNum Not show file and directory number.
-s, --silent Not print the parse-result in terminal.
-h, --help output usage information
$ cd your/demo/app
$ parser
app ( directories: 7, Files: 9 )
āā bin
ā āā www
āā public
ā āā images
ā āā javascripts
ā āā stylesheets
ā āā style.css
āā routes
ā āā index.js
ā āā users.js
āā views
ā āā error.pug
ā āā index.pug
ā āā layout.pug
āā app.js
āā package.json
$ parser -l dashed -f
app ( directories: 7, Files: 9 )
+-- app.js
+-- package.json
+-- bin
¦ +-- www
+-- public
¦ +-- images
¦ +-- javascripts
¦ +-- stylesheets
¦ +-- style.css
+-- routes
¦ +-- index.js
¦ +-- users.js
+-- views
+-- error.pug
+-- index.pug
+-- layout.pug
$ parser -e bin,public -n -s
$ cat dir-info.txt
app
āā routes
ā āā index.js
ā āā users.js
āā views
ā āā error.jade
ā āā index.jade
ā āā layout.jade
āā app.js
āā package.json
Usage 01
There should no white space in the excludes series!
$ parser -e .git,node_modules -x bin/www
Usage 02
There should no white space in the excludes Array!
$ parser -e ['.git','node_modules'] -x ['bin/www']
Usage 03
Parse by a config file
$ vi parser.conf.json
{
"filesFirst": false,
"noNum": false,
"silent": false,
"directory": "your/demo/app",
"output": "your/output/dir",
"excludes": [ ".git", "node_modules" ]
}
$ parser -c ./parser.conf.json
parser(dirPath: string, ptions: Options): Promise<Parsed>
interface Options {
output?: string; // path string
lineType?: 'solid' | 'dashed';
excludes?: Array<string>; // eg: [ '.git', 'node_modules', '.idea' ];
excPaths?: Array<string>; // eg: [ 'src/app' ];
patterns?: Array<string>; // eg: [ 'src/*.js ]';
filesFirst?: boolean;
noNum?: boolean;
files?: boolean;
children?: boolean;
dirTree?: boolean;
}
interface Parsed extends DirInfo {
dirTree: string;
children: Array<DirInfo|FileInfo>
files: Array<FileInfo>
}
interface DirInfo {
name: string = name;
type: 'directory';
size: number;
size_kb: number;
path: string;
absPath: string;
dir: string;
absDir: string;
dirNum: number;
fileNum: number;
children: Array<DirInfo|FileInfo>
}
interface FileInfo {
name: string = name;
base: string = infos.name;
ext: string = infos.ext;
type: 'file';
size: number;
size_kb: number;
path: string;
absPath: string;
dir: string;
absDir: string;
}
$ npm install dir-parser funclib
$ vi test.js
const fn = require('funclib');
const parser = require('dir-parser');
/**
* ============================================================
* Get parsed dir-tree
* ============================================================
*/
const excludes = ['.git', 'dir-info.txt', 'package-lock.json'];
parser('./', {
excludes: excludes,
// lineType: 'dashed',
// filesFirst: true,
}).then(parsed => {
fn.log(parsed.dirTree, '# parsed.dirTree');
fn.log(fn.pick(parsed, prop => prop !== 'dirTree'), '# parsed result info');
// fn.log(parsed.children, '# parsed.children');
// fn.log(parsed.files, '# parsed.files');
});
$ node test.js
==================================================================
[17:06:57] # parsed.dirTree
------------------------------------------------------------------
dir-parser ( directories: 8, Files: 30 )
āā bin
ā āā parser.js
āā node_modules
ā āā commander
ā ā āā typings
ā ā ā āā index.d.ts
ā ā āā CHANGELOG.md
ā ā āā index.js
ā ā āā LICENSE
ā ā āā package.json
ā ā āā Readme.md
ā āā funclib
ā ā āā funclib.core.js
ā ā āā funclib.js
ā ā āā funclib.min.js
ā ā āā index.d.ts
ā ā āā index.js
ā ā āā package.json
ā ā āā README.md
ā āā progress
ā āā lib
ā ā āā node-progress.js
ā āā CHANGELOG.md
ā āā index.js
ā āā LICENSE
ā āā Makefile
ā āā package.json
ā āā Readme.md
āā src
ā āā base.js
ā āā dir-parser.js
āā .gitignore
āā dir-parser.png
āā index.js
āā package.json
āā parser.conf.json
āā README.md
āā test.js
==================================================================
==================================================================
[17:06:57] # parsed result info
------------------------------------------------------------------
{
"name": "dir-parser",
"type": "directory",
"path": "./",
"absPath": "E:\\work\\code\\dir-parser",
"dir": ".",
"absDir": "E:\\work\\code",
"dirNum": 8,
"fileNum": 30
}
==================================================================
$ npm install dir-parser funclib
$ vi test.js
const fn = require('funclib');
const parser = require('dir-parser');
/**
* ============================================================
* Get parsed dir-info (children & files)
* ============================================================
*/
const excludes = ['.git', 'node_modules', 'dir-info.txt', 'package-lock.json'];
parser('./', {
excludes: excludes,
files: true, // Default is false, If true, returns will conatins an array of all subfiles's info;
children: true, // Default is false, If true, returns will conatins an object of all children's info;
dirTree: false // Default is true, returns will conatins a tree of the directory;
}).then(parsed => {
fn.log(parsed.children, '# parsed.children');
fn.log(parsed.files, '# parsed.files');
});
$ node test.js
==================================================================
[17:06:57] # parsed.children
------------------------------------------------------------------
[
{
"name": "bin",
"type": "directory",
"size": 2920,
"size_kb": "2.85kb",
"path": "bin",
"absPath": "E:\\work\\code\\dir-parser\\bin",
"dir": ".",
"absDir": "E:\\work\\code\\dir-parser",
"dirNum": 0,
"fileNum": 1,
"children": [
{
"name": "parser.js",
"base": "parser",
"ext": ".js",
"type": "file",
"size": 2920,
"size_kb": "2.85kb",
"path": "bin\\parser.js",
"absPath": "E:\\work\\code\\dir-parser\\bin\\parser.js",
"dir": "bin",
"absDir": "E:\\work\\code\\dir-parser\\bin"
}
]
},
{
"name": "src",
"type": "directory",
"size": 6488,
"size_kb": "6.34kb",
"path": "src",
"absPath": "E:\\work\\code\\dir-parser\\src",
"dir": ".",
"absDir": "E:\\work\\code\\dir-parser",
"dirNum": 0,
"fileNum": 2,
"children": [
{
"name": "base.js",
"base": "base",
"ext": ".js",
"type": "file",
"size": 1038,
"size_kb": "1.01kb",
"path": "src\\base.js",
"absPath": "E:\\work\\code\\dir-parser\\src\\base.js",
"dir": "src",
"absDir": "E:\\work\\code\\dir-parser\\src"
},
{
"name": "dir-parser.js",
"base": "dir-parser",
"ext": ".js",
"type": "file",
"size": 5450,
"size_kb": "5.32kb",
"path": "src\\dir-parser.js",
"absPath": "E:\\work\\code\\dir-parser\\src\\dir-parser.js",
"dir": "src",
"absDir": "E:\\work\\code\\dir-parser\\src"
}
]
},
{
"name": ".gitignore",
"base": ".gitignore",
"ext": "",
"type": "file",
"size": 34,
"size_kb": "0.03kb",
"path": ".gitignore",
"absPath": "E:\\work\\code\\dir-parser\\.gitignore",
"dir": "",
"absDir": "E:\\work\\code\\dir-parser"
},
{
"name": "dir-parser.png",
"base": "dir-parser",
"ext": ".png",
"type": "file",
"size": 76316,
"size_kb": "74.53kb",
"path": "dir-parser.png",
"absPath": "E:\\work\\code\\dir-parser\\dir-parser.png",
"dir": "",
"absDir": "E:\\work\\code\\dir-parser"
},
{
"name": "index.js",
"base": "index",
"ext": ".js",
"type": "file",
"size": 45,
"size_kb": "0.04kb",
"path": "index.js",
"absPath": "E:\\work\\code\\dir-parser\\index.js",
"dir": "",
"absDir": "E:\\work\\code\\dir-parser"
},
{
"name": "package.json",
"base": "package",
"ext": ".json",
"type": "file",
"size": 732,
"size_kb": "0.71kb",
"path": "package.json",
"absPath": "E:\\work\\code\\dir-parser\\package.json",
"dir": "",
"absDir": "E:\\work\\code\\dir-parser"
},
{
"name": "parser.conf.json",
"base": "parser.conf",
"ext": ".json",
"type": "file",
"size": 111,
"size_kb": "0.11kb",
"path": "parser.conf.json",
"absPath": "E:\\work\\code\\dir-parser\\parser.conf.json",
"dir": "",
"absDir": "E:\\work\\code\\dir-parser"
},
{
"name": "README.md",
"base": "README",
"ext": ".md",
"type": "file",
"size": 11467,
"size_kb": "11.2kb",
"path": "README.md",
"absPath": "E:\\work\\code\\dir-parser\\README.md",
"dir": "",
"absDir": "E:\\work\\code\\dir-parser"
},
{
"name": "test.js",
"base": "test",
"ext": ".js",
"type": "file",
"size": 1196,
"size_kb": "1.17kb",
"path": "test.js",
"absPath": "E:\\work\\code\\dir-parser\\test.js",
"dir": "",
"absDir": "E:\\work\\code\\dir-parser"
}
]
==================================================================
==================================================================
[17:06:57] # parsed.files
------------------------------------------------------------------
[
{
"name": "parser.js",
"base": "parser",
"ext": ".js",
"type": "file",
"size": 2920,
"size_kb": "2.85kb",
"path": "bin\\parser.js",
"absPath": "E:\\work\\code\\dir-parser\\bin\\parser.js",
"dir": "bin",
"absDir": "E:\\work\\code\\dir-parser\\bin"
},
{
"name": "base.js",
"base": "base",
"ext": ".js",
"type": "file",
"size": 1038,
"size_kb": "1.01kb",
"path": "src\\base.js",
"absPath": "E:\\work\\code\\dir-parser\\src\\base.js",
"dir": "src",
"absDir": "E:\\work\\code\\dir-parser\\src"
},
{
"name": "dir-parser.js",
"base": "dir-parser",
"ext": ".js",
"type": "file",
"size": 5450,
"size_kb": "5.32kb",
"path": "src\\dir-parser.js",
"absPath": "E:\\work\\code\\dir-parser\\src\\dir-parser.js",
"dir": "src",
"absDir": "E:\\work\\code\\dir-parser\\src"
},
{
"name": ".gitignore",
"base": ".gitignore",
"ext": "",
"type": "file",
"size": 34,
"size_kb": "0.03kb",
"path": ".gitignore",
"absPath": "E:\\work\\code\\dir-parser\\.gitignore",
"dir": "",
"absDir": "E:\\work\\code\\dir-parser"
},
{
"name": "dir-parser.png",
"base": "dir-parser",
"ext": ".png",
"type": "file",
"size": 76316,
"size_kb": "74.53kb",
"path": "dir-parser.png",
"absPath": "E:\\work\\code\\dir-parser\\dir-parser.png",
"dir": "",
"absDir": "E:\\work\\code\\dir-parser"
},
{
"name": "index.js",
"base": "index",
"ext": ".js",
"type": "file",
"size": 45,
"size_kb": "0.04kb",
"path": "index.js",
"absPath": "E:\\work\\code\\dir-parser\\index.js",
"dir": "",
"absDir": "E:\\work\\code\\dir-parser"
},
{
"name": "package.json",
"base": "package",
"ext": ".json",
"type": "file",
"size": 732,
"size_kb": "0.71kb",
"path": "package.json",
"absPath": "E:\\work\\code\\dir-parser\\package.json",
"dir": "",
"absDir": "E:\\work\\code\\dir-parser"
},
{
"name": "parser.conf.json",
"base": "parser.conf",
"ext": ".json",
"type": "file",
"size": 111,
"size_kb": "0.11kb",
"path": "parser.conf.json",
"absPath": "E:\\work\\code\\dir-parser\\parser.conf.json",
"dir": "",
"absDir": "E:\\work\\code\\dir-parser"
},
{
"name": "README.md",
"base": "README",
"ext": ".md",
"type": "file",
"size": 11467,
"size_kb": "11.2kb",
"path": "README.md",
"absPath": "E:\\work\\code\\dir-parser\\README.md",
"dir": "",
"absDir": "E:\\work\\code\\dir-parser"
},
{
"name": "test.js",
"base": "test",
"ext": ".js",
"type": "file",
"size": 1196,
"size_kb": "1.17kb",
"path": "test.js",
"absPath": "E:\\work\\code\\dir-parser\\test.js",
"dir": "",
"absDir": "E:\\work\\code\\dir-parser"
}
]
==================================================================
FAQs
Parse a directory and generate it's structure tree.
The npm package dir-parser receives a total of 173 weekly downloads. As such, dir-parser popularity was classified as not popular.
We found that dir-parser 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
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.