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 3.1.0 to 3.2.0

70

index.js

@@ -6,6 +6,5 @@ /* global Function */

const args = require('typeof-arguments');
const cliColor = require('cli-color');
const moveOn = require('move-on');
const type = require('of-type');
const error = cliColor.red;
const cliError = (msg)=>`\x1b[31m${msg}\x1b[0m`;

@@ -16,12 +15,38 @@ module.exports = function(p,b,c){

args(arguments,types,(o)=>{
var err = new TypeError(error(o.message));
var err = new TypeError(cliError(o.message));
throw err;
});
const getDeep = type(b,Number) ? b:type(b,Object) ? type(b.deep,Number) ? b.deep:0:0;
var getExcluded = type(b,Object) ? type(b.exclude,String) ? [b.exclude]:type(b.exclude,Array) ? b.exclude:[]:[];
const getCallback = type(b,Function) ? b:c;
const getPath = path.resolve(p);
var userContext = {dirs:[], files:[], inaccessible:[], path:getPath};
var userContext = {error:null, dirs:[], files:[], inaccessible:[], path:getPath};
moveOn([explore],userContext,getCallback,()=>{});
moveOn([pathExists,prepareExcluded,explore],userContext,onDone,onCatch);
function onDone(){
getCallback(this);
}
function onCatch(userContext,err){
this.error = err;
getCallback(this);
}
function pathExists(resolve,reject){
itemExists(this.path,(o)=>{
if(!o.exists) return reject(new Error(`The given path '${getPath}' does not exist or is inaccessible.`));
if(o.exists&&o.file) return reject(new Error(`The given path '${getPath}' leads to the file, while it should indicate the folder.`));
if(!(o.exists&&o.dir)) return reject(new Error(`Could not get the access to the given path '${getPath}'.`));
if(o.exists&&o.dir) return resolve();
});
}
function prepareExcluded(resolve){
getExcluded = getExcluded.map((o)=>{
return path.normalize(o);
});
resolve();
}
function explore(resolve,reject,r,l){

@@ -39,2 +64,9 @@ var relative = typeof r === 'undefined' ? './':r;

var contentsIter = 0;
contents = contents.filter((x)=>{
const ind = getExcluded.indexOf(path.join(relative,x));
if(ind>=0) getExcluded.splice(ind,1);
return !(ind>=0);
});
if(!contents.length) resolve();

@@ -57,17 +89,23 @@ for(let i in contents){

var relative = path.join(r,item);
fs.stat(absolute,(err,stats)=>{
if(err){
this.inaccessible.push(relative);
resolve();
}
itemExists(absolute,(o)=>{
if(o.error) this.inaccessible.push(relative);
if(o.file) this.files.push(relative);
if(o.dir) this.dirs.push(relative);
resolve(o.dir,relative);
});
}
function itemExists(getPath,callback){
fs.stat(getPath,(err,stats)=>{
var o = {error:null,exists:false,file:false,dir:false};
if(err) o.error = err;
if(!err){
var exists = err === null,
isFile = stats && stats.isFile(),
isDir = stats && stats.isDirectory();
if(exists && isFile) this.files.push(relative);
if(exists && isDir) this.dirs.push(relative);
resolve(isDir,relative);
o.exists = type(err,null);
o.file = type(stats,'Stats')&&stats.isFile();
o.dir = type(stats,'Stats')&&stats.isDirectory();
}
return callback(o);
});
}
};
{
"name": "list-contents",
"version": "3.1.0",
"version": "3.2.0",
"description": "Returns a list of paths to the subfolders and subfiles of the specified location.",

@@ -21,3 +21,2 @@ "main": "index.js",

"dependencies": {
"cli-color": "^1.2.0",
"move-on": "^1.0.0",

@@ -24,0 +23,0 @@ "of-type": "^2.1.0",

@@ -5,4 +5,2 @@ # Description

* Also check out [**`file-assistant`**](https://www.npmjs.com/package/file-assistant) package that creates, copies or moves the folders and files into the specified path or modifies the files' content according to the given [Array] object (or .json file path) instructions.
* Changes:
* **`v3.*.*`** The `callback` function `object.error` property has been replaced with `object.inaccessible` property. If the file or folder is inaccessible, it is pushed into `object.inaccessible` array [\[see below\]](#callback-function). Unlike `object.error`, if the file or folder is inaccessible, it does not stop retrieving the further files and folders. After retrieving all children items, the `callback` function returns the object with `dirs`, `files` and `inaccessible` [Array] properties.

@@ -20,7 +18,8 @@ # Installation

* It should indicate the path to the chosen directory, which subfolders and subfiles should be listed
> If the `path`, eg. `'./dist/styles'` is inaccessible itself, the `callback` function will return object:
> `{files:[], dirs:[], inaccessible:[ './' ], path:'./dist/styles'}`
##### `config` **[Object|Number|null]**
* if **omitted**, the parameters are set to their default values *(see below)*
* if **omitted**, the parameters are set to their default values *[see below]*
* if [Number], it sets `deep` to `[Number]` *[see below]*
* if [null], it sets `deep` to `null` *[see below]*
* if [Object], it takes the following properties:

@@ -33,4 +32,10 @@ * **`deep`** [Number|null] *(default:`null`)*

etc.
* if [Number], it sets `deep` to `[Number]`
* if [null], it sets `deep` to `null`
* **`exclude`** [Array|String]
It indicates the folders' and files' paths that should be ignored and not included into the `files`, `dirs` and `inaccessible` lists.
If the folder is indicated, neither the folder nor its contents will be included.
When [String], it can indicate the one path to ignore, eg `"./bin"` .
When [Array], it can indicate more than one path to ignore, eg. `["./node_modules", "./bin"]`.
The given paths must be **relative** to the `path`.
You can ignore needless paths, eg. `'./node_modules'` or `'./.git'` to make the module faster.
```javascript

@@ -43,7 +48,8 @@ const listContents = require('list-contents');

listContents('./dist', {deep: 5}, (data)=>{/*...*/});
listContents('./dist', {deep: 3, exclude: ['node_modules','.git']}, (data)=>{/*...*/})
```
##### `callback` **[Function]**
* the [Object] argument is passed through **`callback`** function. It has 4 properties:
* **`error`** [Boolean|Error] **`v2.*.*`**
* the [Object] argument is passed through **`callback`** function. It has 5 properties:
* **`error`** [Boolean|Error]
`null` if the **`path`** is valid, otherwise [Error] object

@@ -55,3 +61,4 @@ * **`dirs`** [Array]

* **`inaccessible`** [Array] **`v3.*.*`**
The list of all unrecognized or inaccessible children's paths of the specified **`path`** argument
The list of all unrecognized or inaccessible elements' paths of the specified **`path`** argument.
If the file or folder is inaccessible, it does not stop retrieving the further files and folders.
* **`path`** [String]

@@ -111,4 +118,5 @@ The path that was given as **`path`** parameter

'styles/scss/mixins.scss'
]
],
inaccessible: []
}
```
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