dir-tree-creator
Advanced tools
Comparing version 3.0.0 to 4.0.0
@@ -26,19 +26,32 @@ 'use strict' | ||
function dirTree (root, label, cb) { | ||
if (typeof label === 'function') { | ||
cb = label | ||
label = path.basename(root) | ||
function dirTree (root, opts, cb) { | ||
if (typeof opts === 'function') { | ||
cb = opts | ||
opts = {} | ||
} | ||
opts.label = opts.label || path.basename(root) | ||
opts.hidden = typeof opts.hidden !== 'undefined' ? opts.hidden : true | ||
const paths = [] | ||
klaw(root).on('error', er => cb(er)).on('data', i => paths.push(i.path)) | ||
const filterFunc = item => { | ||
if (!opts.hidden) { | ||
const basename = path.basename(item) | ||
return basename === '.' || basename[0] !== '.' | ||
} else { | ||
return true | ||
} | ||
} | ||
klaw(root, { filter: filterFunc }).on('error', er => cb(er)).on('data', i => paths.push(i.path)) | ||
.on('end', () => { | ||
const tree = { | ||
label: label, | ||
label: opts.label, | ||
nodes: [] | ||
} | ||
for (let i = 0; i < paths.length; i += 1) { | ||
for (var i = 0; i < paths.length; i += 1) { | ||
const p = paths[i] | ||
const par = path.dirname(p) | ||
if (par === root) { | ||
addNode(tree, label, path.basename(p)) | ||
addNode(tree, opts.label, path.basename(p)) | ||
} else { | ||
@@ -45,0 +58,0 @@ addNode(tree, path.basename(par), path.basename(p)) |
{ | ||
"name": "dir-tree-creator", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "npm like directory tree structure creator based on the given root path", | ||
@@ -5,0 +5,0 @@ "main": "dir-tree-creator.js", |
@@ -19,6 +19,8 @@ dir-tree-creator | ||
**dirtree(dir[, label], cb)** | ||
**dirtree(dir[, opts], cb)** | ||
- `dir` `<String>` root directory path | ||
- `label` `<String>` *(optional)* label for the root node of the directory tree; if nothing specified, the root path's basename will be used. | ||
- `opts` `<Object>` *(optional)* object with the following properties: | ||
- `label` `<String>` label for the root node of the directory tree; if nothing specified, the root path's basename will be used. | ||
- `hidden` `<Boolean>` determines if hidden files should be included; set to false to ignore hidden files; defaults to true. | ||
- `cb` `<Function>` | ||
@@ -43,3 +45,3 @@ - `err` `<Error | null>` | ||
dirTree('some/dir', 'custom label', (err, tr) => { | ||
dirTree('some/dir', { label: 'custom label' }, (err, tr) => { | ||
if (err) return console.error(err) | ||
@@ -60,6 +62,5 @@ console.log(tr) | ||
│ │ └── file2.js | ||
│ └── file1.md | ||
│ └── file1.md | ||
├── file-under-root.js | ||
└── .gitignore | ||
``` | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5334
58
64