1.1.2 • Published 6 years ago

readdir-on-steroids v1.1.2

Weekly downloads
300
License
MIT
Repository
github
Last release
6 years ago

readdir-on-steroids

CircleCI

Recursively read the contents of a directory.

Installation

npm install readdir-on-steroids

Usage

import readdir from "readdir-on-steroids";

const directory = process.argv[3] || ".";

// only list files
function listFilter(path, stats) {
  return stats.isFile();
}

// don't traverse the .git, lib, node_modules or .vscode directories
function walkFilter(path, stats) {
  return (
    !/\.git$/.test(path) &&
    !/lib/.test(path) &&
    !/node_modules/.test(path) &&
    !/\.vscode/.test(path)
  );
}

readdir(directory, { listFilter, walkFilter }).then(
  paths => console.log(paths.join("\n")),
  error => console.error(error)
);

Output:

.gitignore
README.md
examples/index.ts
package.json
src/__mocks__/fs.ts
src/index.test.ts
src/index.ts
yarn.lock

API

readdir(directory: string, options?: Options): Promise<string[]>
ParameterTypeRequiredDefaultDescription
directorystringThe directory to read.
optionsOptions{}The options.

Options

ParameterTypeRequiredDefaultDescription
concurrencynumber4The maximum number of concurrent calls to readdir.
listFilter(path: string, stats: Stats) => booleanA function filtering the paths that will be returned.
walkFilter(path: string, stats: Stats) => booleanA function filtering the paths that will be walked.

Stats

ParameterTypeRequiredDefaultDescription
rootstringThe root directory being read.
depthnumberThe relative depth from the root directory.
1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.2.2

9 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago