🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

dir-parser

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dir-parser - npm Package Compare versions

Comparing version
1.1.5
to
1.1.6
+56
index.d.ts
export = parser;
export as namespace parser;
declare var parser: parser.Parser;
declare namespace parser {
interface 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;
}
}
+1
-1
{
"name": "dir-parser",
"version": "1.1.5",
"version": "1.1.6",
"description": "Parse a directory and generate it's structure tree.",

@@ -5,0 +5,0 @@ "main": "index.js",

+102
-43
# Dir Parser
![npm](https://img.shields.io/npm/v/dir-parser.svg)
[![npm](https://img.shields.io/npm/v/dir-parser.svg)](https://www.npmjs.com/package/dir-parser)

@@ -15,7 +15,7 @@ Parse a directory and generate it's structure tree.

> $ npm install dir-parser -g
`$ npm install dir-parser -g`
### Get help
> $ parser -h
`$ parser -h`
```

@@ -42,6 +42,6 @@ Usage: parser [options]

> $ cd your/demo/app<br>
> $ parser
`$ cd your/demo/app`<br>
`$ parser`
```
app ( Directorys: 7, Files: 9 )
app ( directories: 7, Files: 9 )
├─ bin

@@ -67,5 +67,5 @@ │ └─ www

> $ parser -l dashed -f
`$ parser -l dashed -f`
```
app ( Directorys: 7, Files: 9 )
app ( directories: 7, Files: 9 )
+-- app.js

@@ -89,4 +89,4 @@ +-- package.json

> $ parser -e bin,public -n -s<br>
> $ cat dir-info.txt
`$ parser -e bin,public -n -s`<br>
`$ cat dir-info.txt`
```

@@ -109,11 +109,11 @@ app

*There should no white space in the excludes series!*
> $ parser -e .git,node_modules -x bin/www
`$ 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']
`$ parser -e ['.git','node_modules'] -x ['bin/www']`
Usage 03
*Parse by a config file*
> $ vi parser.conf.json
`$ vi parser.conf.json`
```

@@ -129,19 +129,71 @@ {

```
> $ parser -c ./parser.conf.json
`$ parser -c ./parser.conf.json`
### Use dir-parser in javaScript code
```
parser(dirPath: string, ptions: Options): Promise<Parsed>
> $ npm install dir-parser funclib<br>
> $ vi test.js
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`<br>
`$ vi test.js`
```
const fn = require('funclib');
const parser = require('dir-parser');
/**
* ============================================================
* Get parsed dir-tree
* ============================================================
*/
let excludes = ['.git', 'dir-info.txt', 'package-lock.json'];
parser('./', { excludes: excludes }).then(parsed => {
/**
* ============================================================
* 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');

@@ -152,20 +204,4 @@ fn.log(fn.pick(parsed, prop => prop !== 'dirTree'), '# parsed result info');

});
/**
* ============================================================
* Get parsed dir-info (children & files)
* ============================================================
*/
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
`$ node test.js`
```

@@ -175,3 +211,3 @@ ==================================================================

------------------------------------------------------------------
dir-parser ( Directorys: 8, Files: 30 )
dir-parser ( directories: 8, Files: 30 )
├─ bin

@@ -232,4 +268,27 @@ │ └─ parser.js

==================================================================
```
`$ npm install dir-parser funclib`<br>
`$ 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`
```
==================================================================

@@ -517,2 +576,2 @@ [17:06:57] # parsed.children

==================================================================
```
```

@@ -82,3 +82,3 @@ const fs = require('fs');

// Classify directorys and files of the dirPath
// Classify directories and files of the dirPath
fs.readdirSync(dirPath).forEach(path_ => {

@@ -217,3 +217,3 @@ const iPath = path.join(dirPath, path_);

} else {
dirTree = `${tarName} ( Directorys: ${tarInfo.dirNum}, Files: ${tarInfo.fileNum} )\r\n${dirTree}`;
dirTree = `${tarName} ( directories: ${tarInfo.dirNum}, Files: ${tarInfo.fileNum} )\r\n${dirTree}`;
}

@@ -220,0 +220,0 @@ tarInfo.dirTree = dirTree.replace(/\r\n$/, '');

+14
-8
const fn = require('funclib');
const parse = require('./index');
const parser = require('./index');
/**
* ============================================================
* Get parsed dir-tree

@@ -9,10 +10,15 @@ * ============================================================

let excludes = ['.git', 'dir-info.txt', 'package-lock.json'];
parse('./', { excludes: excludes }).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');
});
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');
});
/**
* ============================================================
* Get parsed dir-info (children & files)

@@ -22,3 +28,3 @@ * ============================================================

excludes = ['.git', 'node_modules', 'dir-info.txt', 'package-lock.json'];
parse('./', {
parser('./', {
excludes: excludes,

@@ -25,0 +31,0 @@ files: true, // Default is false, If true, returns will conatins an array of all subfiles's info;