tromp

Asynchronous filesystem directory walk with events and accept/reject filtering. For use with minimatch or other filtering tools.

Tromp is an asynchronous filesystem directory walking algorithm with events and accept/reject filtering, designed to be used modules like minimatch.

var tromp = require('tromp')
 
tromp('.')
  .reject(/node_modules/)
  .on('listed', function (listing) {
    console.log(listing.inspect()) })

Instantiate using function tromp(path, options, callback), returning an instance of WalkRoot extending from EventEmitter.

argdesc
pathstring path reference for where to start walking
options.showHiddenif falsy, names beginning with . will be masked. default false
options.autoWalkpluggable function(entry) called when directories are traversed; default calls entry.walk()
options.schedulecallable to schedule functions for later execution. default process.nextTick
options.tasksnumber of concurrent filesystem operations in flight at once
callbackwhen provided, the function is added to .on('listed', callback)
eventargsdesc
'done'Emitted all walks have completed
'listing'listingWhen entries have been received, but before entries have started fs.stat
'listed'listingAfter all entries have completed fs.stat
'filter'entry, listingAfter each WalkEntry's completes fs.stat, but before entry event
'entry'entry, listingAfter each WalkEntry's completes fs.stat and is not excluded during filter event
'file'entry, listingAfter 'entry' event, but only emitted for files
'dir'entry, listingAfter 'entry' event, but only emitted for directories

Starts a new walk rooted at path, creating a WalkListing instance if not already in progress for that path. Emits active events when listings are initiated or completed.

WalkRoot::autoWalk(entry, target) method

Double dispatch mechanism, defaulting to entry.walk(target)

Calls entry.filter(rx,ctx) for each filter event occurence

Calls entry.accept(rx,ctx) for each filter event occurence

Calls entry.accept(rx,ctx) for each filter event occurence

Shared context between WalkRoot, WalkListing and WalkEntry instances.

  • root is the managing WalkRoot instance.
  • rootPath is the path walking initiates from
  • listPath is the directory path of the listing

Encapsulates the active process of listing a directory and stating all of the entries so they can be categorized.

  • rootPath is the path walking initiates from
  • path is the directory path of the listing
  • relPath is path as relative to rootPath

Returns all entries not already excluded matching every function in fnList

Returns all entries matching every function in fnList

Invokes select({match:rx}, opts...)

Invokes select({isFile:true}, opts...)

Invokes select({isDirectory:true}, opts...)

Invokes entry.filter(rx, ctx) against all listing entries.

Invokes entry.accept(rx, ctx) against all listing entries.

Invokes entry.reject(rx, ctx) against all listing entries.

An manipulable object representing and entry of the WalkListing.

  • rootPath is the path initially responsible for listing this entry
  • path is the resolved path this entry represents
  • relPath is path as relative to rootPath
  • stat is an fs.stat instance, once initialized
  • modeKey is a string enum from ['unknown', 'file', 'dir', 'other']

Returns true if the entry is a file.

Returns true if the entry is a directory.

Returns true if not excluded and is a directory

Starts a new walk using the entry's path if it is walkable. See WalkRoot::walk.

If rx is callable, then return rx.call(this.name, ctx) Otherwise use String::match as return this.name.match(rx).

Mark as excluded if !!value, otherwise mark as included.

With no parameters, marks entry as included. Otherwise, if match(rx, ctx), then exclude(false)

With no parameters, marks entry as excluded. Otherwise, if match(rx, ctx), then exclude(true)

Invokes exclude(match(rx, ctx))