list-contents
Advanced tools
Comparing version 3.2.0 to 4.0.0
22
index.js
@@ -11,3 +11,3 @@ /* global Function */ | ||
module.exports = function(p,b,c){ | ||
const types = type(c,Function) ? [String,[Number,Object,null],Function]:type(b,Function) ? [String,Function]:[String,[Number,Object,Function,null],Function]; | ||
const types = type(c,Function) ? [String,[Object],Function]:type(b,Function) ? [String,Function]:type(b,Object) ? [String,Object,Function]:[String,[Object,Function],[Function,undefined]]; | ||
@@ -18,6 +18,8 @@ args(arguments,types,(o)=>{ | ||
}); | ||
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); | ||
const config = type(b,Object) ? b:{}; | ||
const callback = type(b,Function) ? b:c; | ||
const depth = type(config.depth,Number) ? config.depth:null; | ||
var exclude = type(config.exclude,String) ? [config.exclude]:type(config.exclude,Array) ? config.exclude:[]; | ||
var userContext = {error:null, dirs:[], files:[], inaccessible:[], path:getPath}; | ||
@@ -28,3 +30,3 @@ | ||
function onDone(){ | ||
getCallback(this); | ||
callback(this); | ||
} | ||
@@ -34,3 +36,3 @@ | ||
this.error = err; | ||
getCallback(this); | ||
callback(this); | ||
} | ||
@@ -48,3 +50,3 @@ | ||
function prepareExcluded(resolve){ | ||
getExcluded = getExcluded.map((o)=>{ | ||
exclude = exclude.map((o)=>{ | ||
return path.normalize(o); | ||
@@ -69,4 +71,4 @@ }); | ||
contents = contents.filter((x)=>{ | ||
const ind = getExcluded.indexOf(path.join(relative,x)); | ||
if(ind>=0) getExcluded.splice(ind,1); | ||
const ind = exclude.indexOf(path.join(relative,x)); | ||
if(ind>=0) exclude.splice(ind,1); | ||
return !(ind>=0); | ||
@@ -78,3 +80,3 @@ }); | ||
checkItem.call(this,relative,contents[i],(isDir,relative)=>{ | ||
if(isDir&&nextDeep!==getDeep) return explore.call(this,iter,reject,relative,nextDeep); | ||
if(isDir&&nextDeep!==depth) return explore.call(this,iter,reject,relative,nextDeep); | ||
iter(); | ||
@@ -81,0 +83,0 @@ },resolve); |
{ | ||
"name": "list-contents", | ||
"version": "3.2.0", | ||
"version": "4.0.0", | ||
"description": "Returns a list of paths to the subfolders and subfiles of the specified location.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,21 +18,18 @@ # Description | ||
##### `config` **[Object|Number|null]** | ||
* 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: | ||
* **`deep`** [Number|null] *(default:`null`)* | ||
It indicates how deep the `list-contents` should explore the folders in the given `path` directory. | ||
If set to `null` *(default)* it lists all subfiles and subfolders of all levels of the `path` directory. | ||
If set to `1` it lists only the folders and files of the `path` directory. | ||
If set to `2` it lists the elements of the `path` directory and the contents of the `path` directory's folders. | ||
##### `config` **[Object]** | ||
* if **omitted**, the parameters are set to their default values; *All the elements of all levels are listed*. | ||
* You can configure the `list-contents` module with the following [Object] `config`'s properties: | ||
* **`depth`** [Number|null] *(default:null)* | ||
It indicates how deep the `list-contents` module should explore the folders in the given `path` directory. | ||
If set to `null` *(default)* - it lists all subfiles and subfolders of all levels of the `path` directory. | ||
If set to 1 - it lists only the one level of `path` directory elements; eg. `./styles`, `./index.html` | ||
If set to 2 - it lists two levels of `path` directory elements; eg. `./styles/css`, `./scripts/ajax.js` | ||
etc. | ||
* **`exclude`** [Array|String] | ||
* **`exclude`** [Array|String] *(default:[])* | ||
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"` . | ||
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. | ||
The given paths **must be relative** to the `path`, otherwise they will be not recognized. | ||
You can ignore needless paths, eg. `'./node_modules'` or `'./.git'` to make the `list-contents` module faster. | ||
@@ -43,6 +40,4 @@ ```javascript | ||
listContents('./dist', (data)=>{/*...*/}); | ||
listContents('./dist', null, (data)=>{/*...*/}); | ||
listContents('./dist', 3, (data)=>{/*...*/}); | ||
listContents('./dist', {deep: 5}, (data)=>{/*...*/}); | ||
listContents('./dist', {deep: 3, exclude: ['node_modules','.git']}, (data)=>{/*...*/}) | ||
listContents('./dist', {depth: 5}, (data)=>{/*...*/}); | ||
listContents('./dist', {depth: 3, exclude: ['node_modules','.git']}, (data)=>{/*...*/}) | ||
``` | ||
@@ -49,0 +44,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93
9899
111