New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

recursive-dir-reader

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

recursive-dir-reader - npm Package Compare versions

Comparing version 0.0.1 to 1.0.0

README.md

54

index.js

@@ -11,24 +11,28 @@ 'use strict';

*/
function async(dir, callback) {
function async(dir, callback = undefined) {
const paths = [];
fs.readdir(dir, (err, items) => {
if (err) throw console.error(err);
startReading(dir, callback);
each(items, itemName => {
const path = `${dir}/${itemName}`;
function startReading(dir, callback) {
fs.readdir(dir, (err, items) => {
if (err) throw console.error(err);
fs.stat(path, (err, stat) => {
if (err) throw console.error(err);
each(items, itemName => {
const path = `${dir}/${itemName}`;
if (stat.isDirectory()) async(path, callback);
fs.stat(path, (err, stat) => {
if (err) throw console.error(err);
else {
if (callback) callback(path);
if (stat.isDirectory()) startReading(path, callback);
paths.push(path);
}
else {
if (callback) callback(path);
paths.push(path);
}
});
});
});
});
}

@@ -38,5 +42,19 @@ return paths;

function sync(dir, callback) {
/**
* Synchronous Get All Files In Directory & Subdirectories
* @param {string} dir - A path to a directory
* @param {function|undefined} callback - Calls the function one time for each item in the folder.
*/
function sync(dir, callback = undefined) {
const paths = [];
try {
const paths = [];
startReading(dir, callback);
} catch (err) {
throw console.error(err);
}
return paths;
function startReading(dir, callback) {
const items = fs.readdirSync(dir);

@@ -48,3 +66,3 @@

if (isDirectory) sync(path, callback);
if (isDirectory) startReading(path, callback);

@@ -57,6 +75,2 @@ else {

});
return paths;
} catch (err) {
throw console.error(err);
}

@@ -63,0 +77,0 @@ }

{
"name": "recursive-dir-reader",
"version": "0.0.1",
"version": "1.0.0",
"description": "reading directory and subdirectories",

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

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