Package Exports
- list-contents
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (list-contents) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Description
list-contents is a module that returns a list of paths to the subfolders and subfiles of the specified location.
- Any bugs found? Give me to know on dev.rafalko@gmail.com or on GitHub
- Also check out
file-assistantpackage 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.*.*Thecallbackfunctionobject.errorproperty has been replaced withobject.inaccessibleproperty. If the file or folder is inaccessible, it is pushed intoobject.inaccessiblearray [see below]. Unlikeobject.error, if the file or folder is inaccessible, it does not stop retrieving the further files and folders. After retrieving all children items, thecallbackfunction returns the object withdirs,filesandinaccessible[Array] properties.
Installation
npm install list-contents
const list = require('list-contents');Usage
list(path,[config,]callback)
path [String]
- 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, thecallbackfunction 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 [Object], it takes the following properties:
deep[Number|null] (default:null) It indicates how deep thelist-contentsshould explore the folders in the givenpathdirectory.
If set tonull(default) it lists all subfiles and subfolders of all levels of thepathdirectory.
If set to1it lists only the folders and files of thepathdirectory.
If set to2it lists the elements of thepathdirectory and the contents of thepathdirectory's folders.
etc.
- if [Number], it sets
deepto[Number] - if [null], it sets
deeptonull
const listContents = require('list-contents');
listContents('./dist', (data)=>{/*...*/});
listContents('./dist', null, (data)=>{/*...*/});
listContents('./dist', 3, (data)=>{/*...*/});
listContents('./dist', {deep: 5}, (data)=>{/*...*/});callback [Function]
- the [Object] argument is passed through
callbackfunction. It has 4 properties:error[Boolean|Error]v2.*.*nullif thepathis valid, otherwise [Error] objectdirs[Array]
The list of all subfolders' paths of the specifiedpathargumentfiles[Array]
The list of all subfiles' paths of the specifiedpathargumentinaccessible[Array]v3.*.*
The list of all unrecognized or inaccessible children's paths of the specifiedpathargumentpath[String]
The path that was given aspathparameter
const list = require('list-contents');
list("./dist",(o)=>{
if(o.error) throw o.error;
console.log('Folders: ', o.dirs);
console.log('Files: ', o.files);
});Samples
Assuming that "./dist" path contains the following subfolders and subfiles:
dist
├ scripts
│ ├ index.js
│ └ ajax.js
├ styles
│ ├ css
│ │ ├ layout.css
│ │ └ media.css
│ └ scss
│ └ mixins.scss
└ templates
├ main.html
├ menubar.html
├ login.html
└ contact.htmlthe module will pass the following object through the callback function:
{
error: null,
path: "./dist",
dirs: [
'scripts',
'templates',
'styles',
'styles/css',
'styles/scss'
],
files: [
'scripts/ajax.js',
'scripts/index.js',
'templates/contact.html',
'templates/login.html',
'templates/main.html',
'templates/menubar.html',
'styles/css/layout.css',
'styles/css/media.css',
'styles/scss/mixins.scss'
]
}