1.0.14 • Published 15 days ago

file-system-walker v1.0.14

Weekly downloads
-
License
Anti 996
Repository
github
Last release
15 days ago

file-system-walker

Badge LICENSE Node npm version

A modern file system walker lib for Nodejs.

Installation

npm install file-system-walker --save

Usage

// import via esm
import { FileSystemWalker } from "file-system-walker";

// import via cjs
const { FileSystemWalker } = require("file-system-walker");
import { FileSystemWalker } from "file-system-walker";

const walker = new FileSystemWalker("/path/to/folder");

// walk file system asynchronously (Recommend)
for await (const entity of walker) {
  console.log(entity.filepath, entity.stats, entity.deep);

  // breakable for walker
  if (/node_modules/.test(entity.filepath)) {
    break;
  }
}

// walk file system synchronously (Not recommend)
for (const entity of walker) {
  console.log(entity.filepath, entity.stats, entity.deep);

  // breakable for walker
  if (/node_modules/.test(entity.filepath)) {
    break;
  }
}

API

new FileSystemWalker(filepath, [options])

Generate a traversable object which can use with for ... of and for await ... of

Options:

export interface FileSystemWalkerOptions {
  /**
   * Define the exclude when walk in
   * @default undefined
   */
  exclude?: RegExp | ((filepath: string, stat: fs.Stats) => boolean);
  /**
   * only travel to max depth.
   * @example `maxDeep=0 mean emit root dir only`
   * @example `maxDeep=1 mean emit the file/folder of root`
   * @default undefined
   */
  maxDeep?: number;
  /**
   * Whether follow the Symlinks
   * @default false
   */
  followSymlinks?: boolean;
}

Entity:

export interface FileSystemWalkerEntity {
  /**
   * The file path of walk entity
   */
  filepath: string;
  /**
   * The file status of walk entity
   */
  stats: fs.Stats;
  /**
   * The deep of the traverse. The root is zero
   */
  deep: number;
}

License

The Anti 996 License

1.0.14

15 days ago

1.0.13

15 days ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.12

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago