glob-possible-parent
Find out if a path can be a parent of a file you are looking for.
Installation
$ npm install glob-possible-parent
Usage
This library can be used with a glob matching library (micromatch,
minimatch, etc.) to create a matcher that will match not
only the given pattern, but also any parent directories. This can be used to optimize
glob implementation, and prevent unnecessary disk access, by immediately ruling out
directories which can't contain any matching files.
var gpp = require('glob-possible-parent');
var micromatch = require('micromatch');
var gppRegExp = new RegExp('^(?:\\/$|(?:' + gpp('src/js/**/*.js').map(function (pattern) {
return micromatch.makeRe(pattern, { dot: true }).toString().slice(1, -1);
}).join('|') + '))$');
console.log(gppRegExp.test('src'));
console.log(gppRegExp.test('src/js'));
console.log(gppRegExp.test('src/js/x.js'));
console.log(gppRegExp.test('src/css'));
License
Copyright (c) 2016 Martin Kolárik. Released under the MIT license.