Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Returns true when the given `name` matches any of the path properties on a vinyl file.
Returns true when the given name
matches any of the path properties on a vinyl file.
Install with npm:
$ npm install match-file --save
var matchFile = require('match-file');
Returns true if the given string matches one of the path properties on the file
object (does not match agains file.extname
only)
var File = require('vinyl');
var matchFile = require('match-file');
var file = new File({path: 'a/b/c.txt', base: 'a'});
var isMatch = matchFile('c.txt', file);
//=> true (since `c.txt` matches file.basename)
Examples
Continuing with the above setup code, all of the following would return true
:
// file.path
matchFile('a/b/c.txt', file);
// file.relative
matchFile('b/c.txt', file);
// file.basename
matchFile('c.txt', file);
// file.stem
matchFile('c', file);
Similar to matchFile
, but also supports glob patterns for matching. micromatch is used for matching, visit that project to see all available features and options.
var file = new File({path: 'a/b/c.txt'});
console.log(matcher.isMatch('*.js', file));
//=> false
var file = new File({path: 'a/b/c.js'});
console.log(matcher.isMatch('*.js', file));
//=> true
var File = require('vinyl');
var matchFile = require('match-file');
var file = new File({path: 'a/b/c/d/e.txt', base: 'a/b/c'});
file.key = 'zzz/a.txt'; // arbitrary key (for caching)
// file.path
console.log(matchFile.isMatch('a/b/c/d/e.txt', file));
// file.relative
console.log(matchFile.isMatch('d/e.txt', file));
// file.basename
console.log(matchFile.isMatch('e.txt', file));
// file.stem
console.log(matchFile.isMatch('e', file));
// file.key
console.log(matchFile.isMatch('zzz/a.txt', file));
// glob pattern for `file.path`
console.log(matchFile.isMatch('**/*.txt', file));
// glob pattern for `file.relative`
console.log(matchFile.isMatch('d/*.txt', file));
// glob pattern for `file.stem`
console.log(matchFile.isMatch('*', file));
// glob pattern for `file.basename`
console.log(matchFile.isMatch('*.txt', file));
Returns a matcher function bound to the given glob patterns
and options
. micromatch is used for matching, visit that project to see all available features and options.
var isMatch = matchFile.matcher('*.js');
console.log(isMatch);
//=> [function]
var file = new File({path: 'a/b/c.txt'});
console.log(isMatch(file));
//=> false
var file = new File({path: 'a/b/c.js'});
console.log(isMatch(file));
//=> true
Given this setup code:
var File = require('vinyl');
var matchFile = require('match-file');
var file = new File({path: 'a/b/c/d/e.txt', base: 'a/b/c'});
file.key = 'zzz/a.txt'; // arbitrary key (for caching)
All of the following examples would return true
:
// file.path
var isMatch = matchFile.matcher('a/b/c/d/e.txt');
console.log(isMatch(file));
// file.relative
var isMatch = matchFile.matcher('d/e.txt');
console.log(isMatch(file));
// file.basename
var isMatch = matchFile.matcher('e.txt');
console.log(isMatch(file));
// file.stem
var isMatch = matchFile.matcher('e');
console.log(isMatch(file));
// file.key
var isMatch = matchFile.matcher('zzz/a.txt');
console.log(isMatch(file));
// glob pattern for `file.path`
var isMatch = matchFile.matcher('**/*.txt');
console.log(isMatch(file));
// glob pattern for `file.relative`
var isMatch = matchFile.matcher('d/*.txt');
console.log(isMatch(file));
// glob pattern for `file.stem`
var isMatch = matchFile.matcher('*');
console.log(isMatch(file));
// glob pattern for `file.basename`
var isMatch = matchFile.matcher('*.txt');
console.log(isMatch(file));
Use in your gulp plugin:
var though = require('though2');
var gulp = require('gulp');
gulp.task('example', function() {
return gulp.src('src/**/*')
.pipe(filter('*.js'));
});
function filter(pattern, options) {
// define a matcher function outside of the plugin function
var isMatch = matchFile.matcher(pattern, options);
return through.obj(function(file, enc, next) {
// use the matcher function
if (isMatch(file)) {
next(null, file);
return;
}
next();
});
}
You might also be interested in these projects:
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Install dev dependencies:
$ npm install -d && npm test
Jon Schlinkert
Copyright © 2016, Jon Schlinkert. Released under the MIT license.
This file was generated by verb, v0.9.0, on April 26, 2016.
FAQs
Returns true when the given `name` matches any of the path properties on a vinyl file.
The npm package match-file receives a total of 21,142 weekly downloads. As such, match-file popularity was classified as popular.
We found that match-file demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.