adds is-glob to detect globs
This commit is contained in:
parent
341c6851b6
commit
8dfc6ddbd0
13
index.js
13
index.js
@ -8,6 +8,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var pathRe = require('glob-path-regex');
|
var pathRe = require('glob-path-regex');
|
||||||
|
var isGlob = require('is-glob');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a glob pattern into sections
|
* Parse a glob pattern into sections
|
||||||
@ -22,8 +23,10 @@ var pathRe = require('glob-path-regex');
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function parseGlob(pattern) {
|
module.exports = function parseGlob(pattern) {
|
||||||
|
// leave `pattern` unmodified
|
||||||
var glob = pattern;
|
var glob = pattern;
|
||||||
var tok = {};
|
var tok = {};
|
||||||
|
tok.isGlob = isGlob(pattern);
|
||||||
|
|
||||||
var braces = pattern.indexOf('{') !== -1;
|
var braces = pattern.indexOf('{') !== -1;
|
||||||
if (braces) {
|
if (braces) {
|
||||||
@ -67,11 +70,11 @@ module.exports = function parseGlob(pattern) {
|
|||||||
tok.ext = tok.extname.split('.').slice(-1)[0];
|
tok.ext = tok.extname.split('.').slice(-1)[0];
|
||||||
|
|
||||||
if (braces) {
|
if (braces) {
|
||||||
tok.dirname = unescape(tok.dirname);
|
tok.dirname = tok.dirname ? unescape(tok.dirname) : '';
|
||||||
tok.filename = unescape(tok.filename);
|
tok.filename = tok.filename ? unescape(tok.filename) : '';
|
||||||
tok.basename = unescape(tok.basename);
|
tok.basename = tok.basename ? unescape(tok.basename) : '';
|
||||||
tok.extname = unescape(tok.extname);
|
tok.extname = tok.extname ? unescape(tok.extname) : '';
|
||||||
tok.ext = unescape(tok.ext);
|
tok.ext = tok.ext ? unescape(tok.ext) : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
tok.dotfiles = tok.filename.charAt(0) === '.';
|
tok.dotfiles = tok.filename.charAt(0) === '.';
|
||||||
|
|||||||
9
test.js
9
test.js
@ -10,6 +10,15 @@
|
|||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var parse = require('./');
|
var parse = require('./');
|
||||||
|
|
||||||
|
it('should detect when the pattern is a glob pattern:', function () {
|
||||||
|
assert.equal(parse('a.min.js').isGlob, false);
|
||||||
|
assert.equal(parse('*.min.js').isGlob, true);
|
||||||
|
assert.equal(parse('foo/{a,b}.min.js').isGlob, true);
|
||||||
|
assert.equal(parse('foo/(a|b).min.js').isGlob, true);
|
||||||
|
assert.equal(parse('foo/[a-b].min.js').isGlob, true);
|
||||||
|
assert.equal(parse('!foo').isGlob, true);
|
||||||
|
});
|
||||||
|
|
||||||
it('should get a filename from a complex pattern:', function () {
|
it('should get a filename from a complex pattern:', function () {
|
||||||
assert.equal(parse('*.min.js').dirname, '');
|
assert.equal(parse('*.min.js').dirname, '');
|
||||||
assert.equal(parse('/a/b/c').dirname, '/a/b/');
|
assert.equal(parse('/a/b/c').dirname, '/a/b/');
|
||||||
|
|||||||
Reference in New Issue
Block a user