JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 12
  • Score
    100M100P100Q20973F
  • License ISC

List all files in a given directory

Package Exports

  • enumerate-files

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 (enumerate-files) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

enumerate-files

npm version Build Status Coverage Status

A Node.js module to list all files in a given directory

const enumerateFiles = require('enumerate-files');

(async () => {
  const files = await enumerateFiles('./node_modules/enumerate-files/');
  /* Set {
    '/Users/example/node_modules/LICENSE',
    '/Users/example/node_modules/README.md',
    '/Users/example/node_modules/index.js',
    '/Users/example/node_modules/package.json'
  } */
})();

Installation

Use npm.

npm install enumerate-files

API

const enumerateFiles = require('enumerate-files');

enumerateFiles(dir [, options])

dir: string Buffer Uint8Array URL (directory path)
options: Object
Return: Promise<Set<string|Buffer>>

The returned promise is fulfilled with a Set of strings or Buffers — absolute paths of all files included in a given directory. Symbolic links and directories are excluded.

Every options except for withFileTypes are directly passed to the underlying readdir-sorted.

(async () => {
  const iterator = (await enumerateFiles('/dir')).values();

  iterator.next().value; //=> '/dir/10.js'
  iterator.next().value; //=> '/dir/2a.js'
  iterator.next().value; //=> '/dir/2A.js'
})();

(async () => {
  const iterator = (await enumerateFiles('/dir', {
    numeric: true,
    caseFirst: 'upper',
    encoding: 'buffer'
  })).values();

  iterator.next().value; //=> Buffer.from('/dir/2A.js')
  iterator.next().value; //=> Buffer.from('/dir/2a.js')
  iterator.next().value; //=> Buffer.from('/dir/10.js')
})();

License

ISC License © 2017 - 2018 Shinnosuke Watanabe