readdirp

  • Version 4.1.2
  • Published
  • 36.1 kB
  • No dependencies
  • MIT license

Install

npm i readdirp
yarn add readdirp
pnpm add readdirp

Overview

Recursive version of fs.readdir with small RAM & CPU footprint.

Index

Variables

variable EntryTypes

const EntryTypes: {
readonly FILE_TYPE: 'files';
readonly DIR_TYPE: 'directories';
readonly FILE_DIR_TYPE: 'files_directories';
readonly EVERYTHING_TYPE: 'all';
};

    Functions

    function readdirp

    readdirp: (root: Path, options?: Partial<ReaddirpOptions>) => ReaddirpStream;
    • Streaming version: Reads all files and directories in given root recursively. Consumes ~constant small amount of RAM.

      Parameter root

      Root directory

      Parameter options

      Options to specify root (start directory), filters and recursion depth

    function readdirpPromise

    readdirpPromise: (
    root: Path,
    options?: Partial<ReaddirpOptions>
    ) => Promise<EntryInfo[]>;
    • Promise version: Reads all files and directories in given root recursively. Compared to streaming version, will consume a lot of RAM e.g. when 1 million files are listed.

      Returns

      array of paths and their entry infos

    Classes

    class ReaddirpStream

    class ReaddirpStream extends Readable {}
    • Readable readdir stream, emitting new files as they're being listed.

    constructor

    constructor(options?: Partial<ReaddirpOptions>);

      property parent

      parent?: DirEntry;

        property parents

        parents: any[];

          property reading

          reading: boolean;

            Interfaces

            interface DirEntry

            interface DirEntry {}
            • Directory entry. Contains path, depth count, and files.

            property depth

            depth: number;

              property files

              files: PathOrDirent[];

                property path

                path: Path;

                  interface EntryInfo

                  interface EntryInfo {}
                  • Emitted entry. Contains relative & absolute path, basename, and either stats or dirent.

                  property basename

                  basename: string;

                    property dirent

                    dirent?: Dirent;

                      property fullPath

                      fullPath: string;

                        property path

                        path: string;

                          property stats

                          stats?: Stats;

                            Type Aliases

                            type EntryType

                            type EntryType = (typeof EntryTypes)[keyof typeof EntryTypes];

                              type Path

                              type Path = string;
                              • Path in file system.

                              type PathOrDirent

                              type PathOrDirent = Dirent | Path;
                              • Path or dir entries (files)

                              type Predicate

                              type Predicate = string[] | string | Tester;

                                type ReaddirpOptions

                                type ReaddirpOptions = {
                                root: string;
                                fileFilter?: Predicate;
                                directoryFilter?: Predicate;
                                type?: EntryType;
                                lstat?: boolean;
                                depth?: number;
                                alwaysStat?: boolean;
                                highWaterMark?: number;
                                };
                                • Options for readdirp. * type: files, directories, or both * lstat: whether to use symlink-friendly stat * depth: max depth * alwaysStat: whether to use stat (more resources) or dirent * highWaterMark: streaming param, specifies max amount of resources per entry

                                type Tester

                                type Tester = (entryInfo: EntryInfo) => boolean;
                                • Filterer for files

                                Package Files (1)

                                Dependencies (0)

                                No dependencies.

                                Dev Dependencies (8)

                                Peer Dependencies (0)

                                No peer dependencies.

                                Badge

                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/readdirp.

                                • Markdown
                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/readdirp)
                                • HTML
                                  <a href="https://www.jsdocs.io/package/readdirp"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>