JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 392
  • Score
    100M100P100Q88274F
  • License MIT

Returns a list of paths to the subfolders and subfiles of the specified location.

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.

Installation

npm install list-contents

const list = require('list-contents');

Usage

list(path,callback)

path [String]
  • It should indicate the path to the chosen directory, which subfolders and subfiles should be listed
callback [Function]
  • the [Object] argument is passed through callback function. It has 4 properties:
    • error [Boolean|Error] null if the path is valid, otherwise [Error] object
    • dirs [Array] The list of all subfolders' paths of the specified path argument
    • files [Array] The list of all subfiles' paths of the specified path argument
    • path [String] The path that was given as path parameter
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.html

the 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'
  ]
}