recursive-readdir-async
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -17,4 +17,5 @@ /** | ||
const TREE = 2 | ||
// native fs module | ||
const fs = require('fs') | ||
// native modules | ||
const FS = require('fs') | ||
const PATH = require('path') | ||
/** | ||
@@ -26,3 +27,3 @@ * returns a Promise with Stats info of the file | ||
return new Promise(function (resolve, reject) { | ||
fs.stat(file, function (err, stats) { | ||
FS.stat(file, function (err, stats) { | ||
if (err) { | ||
@@ -41,3 +42,3 @@ // console.error(err) | ||
*/ | ||
async function myReaddir(path) { | ||
async function myReaddir(path, settings, deep) { | ||
const data = [] | ||
@@ -48,3 +49,3 @@ return new Promise(function (resolve, reject) { | ||
// Asynchronously computes the canonical pathname by resolving ., .. and symbolic links. | ||
fs.realpath(path, function (err, rpath) { | ||
FS.realpath(path, function (err, rpath) { | ||
if (err) | ||
@@ -57,3 +58,3 @@ rpath = path | ||
// Reading contents of path | ||
fs.readdir(rpath, function (err, files) { | ||
FS.readdir(rpath, function (err, files) { | ||
@@ -73,3 +74,6 @@ // If error reject them | ||
} | ||
if (settings.extensions) | ||
obj.extension = (PATH.extname(files[i])).toLowerCase() | ||
if (settings.deep) | ||
obj.deep = deep | ||
data.push(obj); | ||
@@ -103,6 +107,8 @@ } | ||
*/ | ||
async function listDir(path, settings, progress) { | ||
async function listDir(path, settings, progress, deep) { | ||
let list | ||
if (deep == undefined) | ||
deep = 0; | ||
try { | ||
list = await myReaddir(path); | ||
list = await myReaddir(path, settings, deep); | ||
} catch (err) { | ||
@@ -121,5 +127,5 @@ return { 'error': err, 'path': path } | ||
if (settings.mode == LIST) | ||
list = list.concat(await listDir(list[i].fullname, settings, progress)) | ||
list = list.concat(await listDir(list[i].fullname, settings, progress, deep+1)) | ||
else { | ||
list[i].content = await listDir(list[i].fullname, settings, progress) | ||
list[i].content = await listDir(list[i].fullname, settings, progress, deep+1) | ||
if (list[i].content.length == 0) | ||
@@ -148,6 +154,6 @@ list[i].content = null | ||
*/ | ||
async function dir(path, options, progress) { | ||
async function list(path, options, progress) { | ||
// options skipped? | ||
if (typeof options == 'function') | ||
if (typeof options == 'function') | ||
progress = options | ||
@@ -160,3 +166,5 @@ | ||
stats: false, | ||
ignoreFolders: true | ||
ignoreFolders: true, | ||
extensions: false, | ||
deep: false | ||
} | ||
@@ -174,2 +182,6 @@ | ||
settings.ignoreFolders = options.ignoreFolders | ||
if (options.deep != undefined) | ||
settings.deep = options.deep | ||
if (options.extensions != undefined) | ||
settings.extensions = options.extensions | ||
} | ||
@@ -181,6 +193,8 @@ | ||
module.exports = { | ||
list: dir, | ||
LIST: LIST, | ||
TREE: TREE, | ||
list: list, | ||
stat: stat, | ||
LIST: LIST, | ||
TREE: TREE | ||
fs: FS, | ||
path: PATH | ||
} |
{ | ||
"name": "recursive-readdir-async", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Module to recursive read directory async (non blocking). Must be used with Promises. Configurable, extended filtering. etc.", | ||
@@ -10,2 +10,5 @@ "main": "module.js", | ||
}, | ||
"engines": { | ||
"node": ">=7.6" | ||
}, | ||
"keywords": [ | ||
@@ -31,2 +34,6 @@ "recursive", | ||
"homepage": "https://github.com/m0rtadelo/recursive-readdir-async", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/m0rtadelo/recursive-readdir-async.git" | ||
}, | ||
"license": "MIT", | ||
@@ -33,0 +40,0 @@ "devDependencies": { |
@@ -25,4 +25,3 @@ # recursive-readdir-async | ||
const rra = require('recursive-readdir-async'); | ||
rra.list('.'); | ||
rra.then(function(list){ | ||
rra.list('.').then(function(list){ | ||
console.log(list) | ||
@@ -38,3 +37,5 @@ }) | ||
stats: false, | ||
ignoreFolders: true | ||
ignoreFolders: true, | ||
extensions: true, | ||
deep: true | ||
} | ||
@@ -55,4 +56,6 @@ const list = await rra.list('.', options, function (obj, index, total) { | ||
* **recursive (true | false)** : If true, files and folders of folders and subfolders will be listed. IF false, only the files and folders of the select directory will be listed. *Default: true* | ||
* **stats (true | false)** : If true a stats object (with file information), will be added to every file. If false this info is not added. *Default: false* | ||
* **stats (true | false)** : If true a stats object (with file information), will be added to every item. If false this info is not added. *Default: false* | ||
* **ignoreFolders (true | false)** : If true and mode is LIST, the list will be returned with files only. If true and mode is TREE, the directory structures without files will be deleted. If false, all empty and non empty directories will be listed. *Default: true* | ||
* **extensions (true | false)** : If true, lowercase extensions will be added to every item (file.TXT = .txt). *Default: false* | ||
* **deep (true | false)** : If true, folder depth information will be added to every item starting by 0 (initial path), and be incremented by 1 in every subfolder. *Default: false* | ||
## Object structure | ||
@@ -59,0 +62,0 @@ The function will return an object and never throw an error. All errors will be added to the returned object. The return object in LIST mode are like this: |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
13275
5
175
145
1