minimatch-capture
v1.1.0
Published
A minimap wrapper that captures the dynamic part. Useful for constructing identifiers from paths.
Downloads
21,551
Readme
minimap-capture
A minimap wrapper that captures the dynamic part. Useful for constructing identifiers from paths.
Installation
npm install --save minimap-captureUsage
var capture = require("minimap-capture")
capture("foo/bar/a/bat/index.js", "foo/*/a/*/index.js") // "bar/a/bat"
capture("foo/bar/b/bat/index.js", "foo/*/a/*/index.js") // falseCapture class
Create a capture object by instantiating the capture.Capture class.
var Capture = require("capture").Capture
var c = new Capture(pattern, options)Properties
patternThe original pattern.optionsThe options supplied to the constructor.regexpCreated by themakeRemethod. A single regular expression expressing the entire pattern.
Methods
makeReGenerate theregexpmember if necessary, and return it. Will returnfalseif the pattern is invalid.capture(path)Return captured portion of the path, or false otherwise.
capture(path, pattern, options)
Main export. Capture a portion of the path.
var result = capture("foo/bar/a/bat/index.js", "foo/*/a/*/index.js") // bar/a/batReturns false if pattern does not match.
capture.match(list, pattern, options)
Match against the list of files and return both full path and captured portion.
var fileList = [
"foo/bar/a/bat/index.js",
"foo/bar/a/bing/index.js",
"foo/bar/b/bat/index.js",
"foo/bar/b/bing/index.js",
]
var files = capture.match(fileList, "*.js")
/*
files = [
["foo/bar/a/bat/index.js", "bar/a/bat"],
["foo/bar/a/bing/index.js", "bar/a/bing"]
]
*/capture.makeRe(pattern, options)
Make a regular expression object from the pattern. Adds a capture group for the captured portion. If pattern is braced more than one capture group is added.
