Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

list-contents

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

list-contents - npm Package Compare versions

Comparing version 2.0.3 to 2.0.4

.npmignore

92

index.js

@@ -1,8 +0,8 @@

/* global Promise */
const fs = require('fs-extra');
const fs = require('fs');
const path = require('path');
const args = require('typeof-arguments');
const cliColor = require('cli-color');
const moveOn = require('move-on');
const error = cliColor.red;
const warn = cliColor.bgYellow.black;
const warn = cliColor.bgYellow.blue;

@@ -14,60 +14,48 @@ module.exports = function(getPath,callback){

});
var msgError = new Error(warn('list-contents') + ': ' + error('Could not get the access to the contents of the given directory path.'));
var dirs = [];
var files = [];
var userContext = {dirs:[], files:[], path:getPath, error:null };
run(getPath)
.then(()=>callback({error:null,files:files,dirs:dirs,path:getPath}))
.catch((err)=>callback({error:err,files:files,dirs:dirs,path:getPath}));
moveOn([explore],userContext,callback,(u,e)=>{
callback({dirs:[], files:[], path:getPath, error:e });
});
function run(pth){
return new Promise((resolve,reject)=>{
getContent(pth)
.then((o)=>getDirsAndFiles(o))
.then(()=>resolve())
.catch((err)=>reject(err));
});
}
function getContent(pth){
return new Promise((resolve,reject)=>{
fs.readdir(pth,(err,content)=>{
if(err) {
reject(msgError);
} else {
resolve({pth:pth,content:content});
function explore(resolve,reject,r){
var relative = typeof r==='undefined' ? '':r;
var abs = path.resolve(this.path,relative);
fs.readdir(abs,(err,contents)=>{
if(err) reject(new Error(warn('list-contents') + ': ' + error(`Could not get the access to the '${parseSlashes(abs)}' path.`)));
if(!err){
var contentsIter = 0;
if(!contents.length) resolve();
for(let i in contents){
checkItem.call(this,relative,contents[i],(isDir,relative)=>{
if(isDir) explore.call(this,iter,reject,relative);
if(!isDir) iter();
});
}
});
}
function iter(){
if(++contentsIter===contents.length) resolve();
}
});
}
function getDirsAndFiles(o){
return new Promise((resolve,reject)=>{
var promises = [];
for(let i in o.content){
let p = path.resolve(o.pth,o.content[i]);
let rel = path.relative(getPath,p);
var promise = new Promise((resolve,reject)=>{
fs.lstat(p,(err,stats)=>{
if(err){
reject(msgError);
return;
} else {
if(stats.isDirectory()){
dirs.push(rel);
run(p).then(()=>{
resolve();
});
} else {
files.push(rel);
resolve();
}
}
});
});
promises.push(promise);
function checkItem(r,item,resolve,reject){
var absolute = path.resolve(this.path,r,item);
var relative = path.join(r,item);
fs.stat(absolute,(err,stats)=>{
if(err) reject(new Error(warn('list-contents') + ': ' + error(`Could not get the access to the '${parseSlashes(absolute)}' path.`)));
if(!err){
var exists = err === null,
isFile = stats && stats.isFile(),
isDir = stats && stats.isDirectory();
if(exists && isFile) this.files.push(parseSlashes(relative));
if(exists && isDir) this.dirs.push(parseSlashes(relative));
resolve(isDir,relative);
}
Promise.all(promises).then(()=>resolve(),(err)=>reject(err));
});
}
function parseSlashes(path){
return path.replace(/\\/g,'/');
}
};
{
"name": "list-contents",
"version": "2.0.3",
"version": "2.0.4",
"description": "Returns a list of paths to the subfolders and subfiles of the specified location.",

@@ -22,3 +22,3 @@ "main": "index.js",

"cli-color": "^1.2.0",
"fs-extra": "^4.0.1",
"move-on": "^1.0.0",
"typeof-arguments": "^3.0.1"

@@ -25,0 +25,0 @@ },

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