adds isNegated property
This commit is contained in:
parent
8704e60f3e
commit
0e3768bbab
6
index.js
6
index.js
@ -26,7 +26,10 @@ module.exports = function parseGlob(pattern) {
|
||||
// leave `pattern` unmodified
|
||||
var glob = pattern;
|
||||
var tok = {};
|
||||
|
||||
tok.pattern = pattern;
|
||||
tok.isGlob = isGlob(pattern);
|
||||
tok.isNegated = pattern.charAt(0) === '!';
|
||||
|
||||
var braces = pattern.indexOf('{') !== -1;
|
||||
if (braces) {
|
||||
@ -34,7 +37,6 @@ module.exports = function parseGlob(pattern) {
|
||||
}
|
||||
|
||||
if (!/(\/|\*\*)/.test(glob)) {
|
||||
tok.pattern = pattern;
|
||||
tok.dirname = '';
|
||||
tok.filename = pattern;
|
||||
|
||||
@ -49,9 +51,7 @@ module.exports = function parseGlob(pattern) {
|
||||
|
||||
} else {
|
||||
var m = pathRe().exec(glob) || [];
|
||||
tok.pattern = pattern;
|
||||
tok.dirname = m[1];
|
||||
|
||||
tok.filename = glob.substr(tok.dirname.length);
|
||||
var dot = tok.filename.indexOf('.', 1);
|
||||
if (dot !== -1) {
|
||||
|
||||
9
test.js
9
test.js
@ -19,6 +19,15 @@ it('should detect when the pattern is a glob pattern:', function () {
|
||||
assert.equal(parse('!foo').isGlob, true);
|
||||
});
|
||||
|
||||
it('should detect when a pattern is negated:', function () {
|
||||
assert.equal(parse('a.min.js').isNegated, false);
|
||||
assert.equal(parse('!*.min.js').isNegated, true);
|
||||
assert.equal(parse('!foo/{a,b}.min.js').isNegated, true);
|
||||
assert.equal(parse('!foo/(a|b).min.js').isNegated, true);
|
||||
assert.equal(parse('!foo/[a-b].min.js').isNegated, true);
|
||||
assert.equal(parse('foo').isNegated, false);
|
||||
});
|
||||
|
||||
it('should get a filename from a complex pattern:', function () {
|
||||
assert.equal(parse('*.min.js').dirname, '');
|
||||
assert.equal(parse('/a/b/c').dirname, '/a/b/');
|
||||
|
||||
Reference in New Issue
Block a user