1.1.1 • Published 9 years ago
node-walkup v1.1.1
WalkUp
- Walks up a directory tree from a give subdirectory
- Returns file names that match a pattern
- Emits
matchas results are found
WalkUp uses the glob library to do it's pattern matching.
Installation
Install with npm
npm install node-walkupExample
var walkup = require("node-walkup")
options = {
cwd: "/path/to/some/sub/dir/with/files"
}
walkup("*.json", options, function (err, matches) {
// err is an error object or null.
// matches is an array of objects
// [
// {
// dir: "/path/to/some/sub/dir/with/files",
// files: ["a.json"]
// },
// {
// dir: "/path/to/some/sub/dir/with",
// files: ["b.json", "c.json"]
// },
// ]
})walkup(pattern, options, cb)
pattern{String}Pattern to be matchedoptions{Object}cb{Function(err, matches)}err{Error | null}matches{Array<Object>}where{Object}dir:{String}dir where match was foundfiles:Array<String>filenames found matching the pattern in that dir
Perform an asynchronous glob search. If no matching files are found, then an empty array is returned.
Class: walkup.WalkUp
Create a WalkUp object by instantiating the walkup.WalkUp class.
var WalkUp = require("walkup").WalkUp
var matches = new WalkUp(pattern, options, cb)It's an EventEmitter, and starts walking up the dir tree to find matches immediately.
Events
endWhen the matching is finished, this is emitted with all the matches found.matchEvery time a match is found, this is emitted with the specific thing that matched.errorEmitted when an unexpected error is encountered, or whenever any fs error occurs ifoptions.strictis set.abortWhenabort()is called, this event is raised.
Methods
abortStop the search
Options
All the options that can be passed to glob can also be passed to
WalkUp to change pattern matching behavior with a few exceptions where
such options are unsuitable for walkup. Also, some have been added,
or have walkup-specific ramifications.
All options are false by default, unless otherwise noted.
All options are added to the WalkUp object, as well.
cwdThe current working directory in which to search. Defaults toprocess.cwd(). Seeglobfor a full list of options.
Glob options suppressed in walkup:
noglobstarWe're walking up a dir tree, so this is always set to false.matchBaseDitto.nonullWhy not?