Socket
Socket
Sign inDemoInstall

fdir

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fdir - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

.npmignore

80

index.js

@@ -1,45 +0,59 @@

const util = require("util");
const fs = require("fs");
const path = require("path");
const readdir = util.promisify(fs.readdir);
const readdirOpts = { withFileTypes: true };
function sync(dir, options) {
const dirents = fs.readdirSync(dir, { withFileTypes: true });
const paths = [];
if (options.includeDirs) paths.push(dir);
if (--options.maxDepth < 0) return paths;
dirents.forEach(function(dirent) {
const dirPath = recurse(dirent, dir, paths, options);
if (dirPath) {
sync(dirPath, options).forEach(function(item) {
paths.push(item);
});
}
});
const dirs = [dir];
let currentDepth = options.maxDepth;
var i = 0;
while (i < dirs.length && !(--currentDepth < 0)) {
const dir = dirs[i];
if (options.includeDirs) paths.push(dir);
const dirents = fs.readdirSync(dir, readdirOpts);
dirents.forEach(function(dirent) {
recurse(dirent, dir, paths, options, dirs);
});
++i;
}
return paths;
}
async function async(dir, options) {
const dirents = await readdir(dir, { withFileTypes: true });
const paths = [];
if (options.includeDirs) paths.push(dir);
if (--options.maxDepth < 0) return paths;
await Promise.all(
dirents.map(async function(dirent) {
const dirPath = recurse(dirent, dir, paths, options);
if (dirPath) {
(await async(dirPath, options)).forEach(function(item) {
paths.push(item);
function async(dir, options) {
return new Promise(function(resolve) {
const paths = [];
const dirs = [dir];
let cursor = 0;
let readCount = 0;
let currentDepth = options.maxDepth;
function walk() {
let total = dirs.length;
for (; cursor < total; ++cursor) {
if (--currentDepth < 0) {
resolve(paths);
break;
}
const dir = dirs[cursor];
if (options.includeDirs) paths.push(dir);
fs.readdir(dir, readdirOpts, function(err, dirents) {
if (!dirents) return;
dirents.forEach(function(dirent) {
recurse(dirent, dir, paths, options, dirs);
});
if (++readCount === total) {
if (dirs.length === cursor) {
resolve(paths);
} else {
walk();
}
}
});
}
})
);
return paths;
}
walk();
});
}
function recurse(dirent, dir, paths, options) {
function recurse(dirent, dir, paths, options, dirs) {
// In node < 10, Dirent is not present. Instead we get string paths

@@ -54,3 +68,3 @@ const dirName = dirent.name || dirent;

if (options.isExcludedDir && options.isExcludedDir(dirName)) return;
return fullPath;
dirs.push(fullPath);
} else {

@@ -57,0 +71,0 @@ if (!options.includeBasePath) fullPath = dirName;

{
"name": "fdir",
"version": "1.1.1",
"version": "1.2.0",
"description": "The fastest directory crawler for NodeJS. Crawls 10k files in 13ms.",

@@ -40,10 +40,10 @@ "main": "index.js",

"get-all-files": "^1.0.7",
"jest": "24.0.0",
"klaw-sync": "^6.0.0",
"recur-readdir": "0.0.1",
"recursive-files": "^1.0.2",
"recursive-fs": "^2.0.0",
"recursive-readdir": "^2.2.2",
"rrdir": "^2.0.0",
"rrdir": "^6.1.2",
"walk-sync": "^2.0.2"
}
}

Sorry, the diff of this file is not supported yet

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