This commit is contained in:
jonschlinkert 2015-02-17 07:53:20 -05:00
parent 60918796b4
commit 2d91c3f5a4
4 changed files with 11 additions and 16 deletions

View File

@ -33,7 +33,7 @@ parseGlob('a/b/{c,d}/*.js');
basename: '*',
extname: '.js',
ext: 'js' },
is: { glob: true, negated: false, globstar: false,
is: { glob: true, braces: true, negated: false, globstar: false,
dotfile: false, dotdir: false },
original: 'a/b/{c,d}/*.js',
pattern: 'a/b/{c,d}/*.js' }

View File

@ -37,7 +37,7 @@ parseGlob('a/b/{c,d}/*.js');
basename: '*',
extname: '.js',
ext: 'js' },
is: { glob: true, negated: false, globstar: false,
is: { glob: true, braces: true, negated: false, globstar: false,
dotfile: false, dotdir: false },
original: 'a/b/{c,d}/*.js',
pattern: 'a/b/{c,d}/*.js' }

View File

@ -40,22 +40,17 @@ function parseGlob(pattern, getbase) {
tok.pattern = pattern;
path.whole = tok.pattern;
// is the pattern actually a glob?
tok.is.glob = isGlob(glob);
// Boolean values
tok.is.glob = isGlob(glob);
tok.is.negated = glob.charAt(0) === '!';
tok.is.globstar = glob.indexOf('**') !== -1;
// is it a negation pattern?
tok.is.negated = glob.charAt(0) === '!';
// does the pattern contain braces?
var braces = glob.indexOf('{') !== -1;
if (tok.is.glob && braces) {
tok.is.braces = true;
glob = glob.substr(0, braces) + escape(glob.substr(braces));
}
// does the pattern contain a globstar (`**`)?
tok.is.globstar = glob.indexOf('**') !== -1;
// if there is no `/` and no `**`, this means our
// pattern can only match file names
if (glob.indexOf('/') === -1 && !tok.is.globstar) {
@ -65,13 +60,17 @@ function parseGlob(pattern, getbase) {
var basename = /^([^.]*)/.exec(glob);
if (basename) {
path.basename = basename[0] ? unescape(basename[0]) : '';
path.basename = basename[0] || '';
path.extname = glob.substr(path.basename.length);
} else {
path.basename = tok.original;
path.extname = '';
}
path.ext = path.extname.split('.').slice(-1)[0];
if (braces) {
path.basename = unescape(path.basename);
}
// we either have a `/` or `**`
} else {
@ -116,7 +115,6 @@ function parseGlob(pattern, getbase) {
tok.pattern = tok.path.filename;
}
}
return tok;
}

View File

@ -14,9 +14,6 @@ function getBase(glob) {
return parse(glob, true);
}
console.log(parse('a/b/d/e'))
describe('`is` object:', function () {
it('should detect when the pattern is a glob pattern:', function () {
assert.equal(parse('a.min.js').is.glob, false);