minimatch-capture
v1.1.0
Published
A minimap wrapper that captures the dynamic part. Useful for constructing identifiers from paths.
Downloads
19,898
Readme
minimap-capture
A minimap wrapper that captures the dynamic part. Useful for constructing identifiers from paths.
Installation
npm install --save minimap-capture
Usage
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") // false
Capture class
Create a capture object by instantiating the capture.Capture class.
var Capture = require("capture").Capture
var c = new Capture(pattern, options)
Properties
pattern
The original pattern.options
The options supplied to the constructor.regexp
Created by themakeRe
method. A single regular expression expressing the entire pattern.
Methods
makeRe
Generate theregexp
member if necessary, and return it. Will returnfalse
if 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/bat
Returns 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.