Compare commits

..

No commits in common. "master" and "3.0.2" have entirely different histories.

3 changed files with 200 additions and 262 deletions

View File

@ -1,23 +1,23 @@
# parse-glob [![NPM version](https://badge.fury.io/js/parse-glob.svg)](http://badge.fury.io/js/parse-glob) [![Build Status](https://travis-ci.org/jonschlinkert/parse-glob.svg)](https://travis-ci.org/jonschlinkert/parse-glob)
# parse-glob [![NPM version](https://badge.fury.io/js/parse-glob.svg)](http://badge.fury.io/js/parse-glob) [![Build Status](https://travis-ci.org/jonschlinkert/parse-glob.svg)](https://travis-ci.org/jonschlinkert/parse-glob)
> Parse a glob pattern into an object of tokens.
**Changes from v1.0.0 to v3.0.4**
**Changes from v1.0.0 to v3.0.2**
* all path-related properties are now on the `path` object
* all boolean properties are now on the `is` object
* adds `base` property
- all path-related properties are now on the `path` object
- all boolean properties are now on the `is` object
- adds `base` property
See the [properties](#properties) section for details.
Install with [npm](https://www.npmjs.com/)
## Install with [npm](npmjs.org)
```sh
$ npm i parse-glob --save
```bash
npm i parse-glob --save
```
* parses 1,000+ glob patterns in 29ms (2.3 GHz Intel Core i7)
* Extensive [unit tests](./test.js) (more than 1,000 lines), covering wildcards, globstars, character classes, brace patterns, extglobs, dotfiles and other complex patterns.
- parses 1,000+ glob patterns in 29ms (2.3 GHz Intel Core i7)
- Extensive [unit tests](./test.js) (more than 1,000 lines), covering wildcards, globstars, character classes, brace patterns, extglobs, dotfiles and other complex patterns.
See the tests for [hundreds of examples](./test.js).
@ -60,42 +60,43 @@ parseGlob('a/b/c/**/*.{yml,json}');
The object returned by parseGlob has the following properties:
* `orig`: a copy of the original, unmodified glob pattern
* `is`: an object with boolean information about the glob:
- `glob`: true if the pattern actually a glob pattern
- `negated`: true if it's a negation pattern (`!**/foo.js`)
- `extglob`: true if it has extglobs (`@(foo|bar)`)
- `braces`: true if it has braces (`{1..2}` or `.{txt,md}`)
- `brackets`: true if it has POSIX brackets (`[[:alpha:]]`)
- `globstar`: true if the pattern has a globstar (double star, `**`)
- `dotfile`: true if the pattern should match dotfiles
- `dotdir`: true if the pattern should match dot-directories (like `.git`)
* `glob`: the glob pattern part of the string, if any
* `base`: the non-glob part of the string, if any
* `path`: file path segments
- `dirname`: directory
- `basename`: file name with extension
- `filename`: file name without extension
- `extname`: file extension with dot
- `ext`: file extension without dot
- `orig`: a copy of the original, unmodified glob pattern
- `is`: an object with boolean information about the glob:
+ `glob`: true if the pattern actually a glob pattern
+ `negated`: true if it's a negation pattern (`!**/foo.js`)
+ `extglob`: true if it has extglobs (`@(foo|bar)`)
+ `braces`: true if it has braces (`{1..2}` or `.{txt,md}`)
+ `brackets`: true if it has POSIX brackets (`[[:alpha:]]`)
+ `globstar`: true if the pattern has a globstar (double star, `**`)
+ `dotfile`: true if the pattern should match dotfiles
+ `dotdir`: true if the pattern should match dot-directories (like `.git`)
- `glob`: the glob pattern part of the string, if any
- `base`: the non-glob part of the string, if any
- `path`: file path segments
+ `dirname`: directory
+ `basename`: file name with extension
+ `filename`: file name without extension
+ `extname`: file extension with dot
+ `ext`: file extension without dot
## Related
* [glob-base](https://www.npmjs.com/package/glob-base): Returns an object with the (non-glob) base path and the actual pattern. | [homepage](https://github.com/jonschlinkert/glob-base)
* [glob-parent](https://www.npmjs.com/package/glob-parent): Strips glob magic from a string to provide the parent path | [homepage](https://github.com/es128/glob-parent)
* [glob-path-regex](https://www.npmjs.com/package/glob-path-regex): Regular expression for matching the parts of glob pattern. | [homepage](https://github.com/regexps/glob-path-regex)
* [is-glob](https://www.npmjs.com/package/is-glob): Returns `true` if the given string looks like a glob pattern. | [homepage](https://github.com/jonschlinkert/is-glob)
* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just… [more](https://www.npmjs.com/package/micromatch) | [homepage](https://github.com/jonschlinkert/micromatch)
* [glob-base](https://github.com/jonschlinkert/glob-base): Returns an object with the (non-glob) base path and the… [more](https://github.com/jonschlinkert/glob-base)
* [glob-parent](https://github.com/es128/glob-parent): Strips glob magic from a string to provide the parent… [more](https://github.com/es128/glob-parent)
* [glob-path-regex](https://github.com/regexps/glob-path-regex): Regular expression for matching the parts of glob pattern.
* [is-glob](https://github.com/jonschlinkert/is-glob): Returns `true` if the given string looks like a glob… [more](https://github.com/jonschlinkert/is-glob)
* [micromatch](https://github.com/jonschlinkert/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative… [more](https://github.com/jonschlinkert/micromatch)
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/parse-glob/issues/new).
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/parse-glob/issues)
## Tests
Install dev dependencies:
```sh
$ npm i -d && npm test
```bash
npm i -d && npm test
```
## Author
@ -107,9 +108,15 @@ $ npm i -d && npm test
## License
Copyright © 2014-2015 Jon Schlinkert
Copyright (c) 2014-2015 Jon Schlinkert
Released under the MIT license.
***
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 22, 2015._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on April 25, 2015._
<!-- reflinks generated by verb-reflinks plugin -->
[verb]: https://github.com/assemble/verb
[template]: https://github.com/jonschlinkert/template
[assemble]: http://assemble.io

View File

@ -156,120 +156,8 @@ function unescape(str) {
return str;
}
},{"glob-base":2,"is-dotfile":4,"is-extglob":5,"is-glob":6}],2:[function(require,module,exports){
/*!
* glob-base <https://github.com/jonschlinkert/glob-base>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var path = require('path');
var parent = require('glob-parent');
var isGlob = require('is-glob');
module.exports = function globBase(pattern) {
if (typeof pattern !== 'string') {
throw new TypeError('glob-base expects a string.');
}
var res = {};
res.base = parent(pattern);
res.isGlob = isGlob(pattern);
if (res.base !== '.') {
res.glob = pattern.substr(res.base.length);
if (res.glob.charAt(0) === '/') {
res.glob = res.glob.substr(1);
}
} else {
res.glob = pattern;
}
if (!res.isGlob) {
res.base = dirname(pattern);
res.glob = res.base !== '.'
? pattern.substr(res.base.length)
: pattern;
}
if (res.glob.substr(0, 2) === './') {
res.glob = res.glob.substr(2);
}
if (res.glob.charAt(0) === '/') {
res.glob = res.glob.substr(1);
}
return res;
};
function dirname(glob) {
if (glob.slice(-1) === '/') return glob;
return path.dirname(glob);
}
},{"glob-parent":3,"is-glob":6,"path":7}],3:[function(require,module,exports){
'use strict';
var path = require('path');
var isglob = require('is-glob');
module.exports = function globParent(str) {
str += 'a'; // preserves full path in case of trailing path separator
do {str = path.dirname(str)} while (isglob(str));
return str;
};
},{"is-glob":6,"path":7}],4:[function(require,module,exports){
/*!
* is-dotfile <https://github.com/jonschlinkert/is-dotfile>
*
* Copyright (c) 2015-2017, Jon Schlinkert.
* Released under the MIT License.
*/
module.exports = function(str) {
if (str.charCodeAt(0) === 46 /* . */ && str.indexOf('/', 1) === -1) {
return true;
}
var slash = str.lastIndexOf('/');
return slash !== -1 ? str.charCodeAt(slash + 1) === 46 /* . */ : false;
};
},{}],5:[function(require,module,exports){
/*!
* is-extglob <https://github.com/jonschlinkert/is-extglob>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
module.exports = function isExtglob(str) {
return typeof str === 'string'
&& /[@?!+*]\(/.test(str);
};
},{}],6:[function(require,module,exports){
/*!
* is-glob <https://github.com/jonschlinkert/is-glob>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
var isExtglob = require('is-extglob');
module.exports = function isGlob(str) {
return typeof str === 'string'
&& (/[*!?{}(|)[\]]/.test(str)
|| isExtglob(str));
};
},{"is-extglob":5}],7:[function(require,module,exports){
},{"glob-base":4,"is-dotfile":7,"is-extglob":8,"is-glob":9}],2:[function(require,module,exports){
(function (process){
// .dirname, .basename, and .extname methods are extracted from Node.js v8.11.1,
// backported and transplited with Babel, with backwards-compat fixes
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
@ -321,6 +209,14 @@ function normalizeArray(parts, allowAboveRoot) {
return parts;
}
// Split a filename into [root, dir, basename, ext], unix version
// 'root' is just a slash, or nothing.
var splitPathRe =
/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
var splitPath = function(filename) {
return splitPathRe.exec(filename).slice(1);
};
// path.resolve([from ...], to)
// posix version
exports.resolve = function() {
@ -436,120 +332,37 @@ exports.relative = function(from, to) {
exports.sep = '/';
exports.delimiter = ':';
exports.dirname = function (path) {
if (typeof path !== 'string') path = path + '';
if (path.length === 0) return '.';
var code = path.charCodeAt(0);
var hasRoot = code === 47 /*/*/;
var end = -1;
var matchedSlash = true;
for (var i = path.length - 1; i >= 1; --i) {
code = path.charCodeAt(i);
if (code === 47 /*/*/) {
if (!matchedSlash) {
end = i;
break;
}
} else {
// We saw the first non-path separator
matchedSlash = false;
}
exports.dirname = function(path) {
var result = splitPath(path),
root = result[0],
dir = result[1];
if (!root && !dir) {
// No dirname whatsoever
return '.';
}
if (end === -1) return hasRoot ? '/' : '.';
if (hasRoot && end === 1) {
// return '//';
// Backwards-compat fix:
return '/';
if (dir) {
// It has a dirname, strip trailing slash
dir = dir.substr(0, dir.length - 1);
}
return path.slice(0, end);
return root + dir;
};
function basename(path) {
if (typeof path !== 'string') path = path + '';
var start = 0;
var end = -1;
var matchedSlash = true;
var i;
for (i = path.length - 1; i >= 0; --i) {
if (path.charCodeAt(i) === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
start = i + 1;
break;
}
} else if (end === -1) {
// We saw the first non-path separator, mark this as the end of our
// path component
matchedSlash = false;
end = i + 1;
}
}
if (end === -1) return '';
return path.slice(start, end);
}
// Uses a mixed approach for backwards-compatibility, as ext behavior changed
// in new Node.js versions, so only basename() above is backported here
exports.basename = function (path, ext) {
var f = basename(path);
exports.basename = function(path, ext) {
var f = splitPath(path)[2];
// TODO: make this comparison case-insensitive on windows?
if (ext && f.substr(-1 * ext.length) === ext) {
f = f.substr(0, f.length - ext.length);
}
return f;
};
exports.extname = function (path) {
if (typeof path !== 'string') path = path + '';
var startDot = -1;
var startPart = 0;
var end = -1;
var matchedSlash = true;
// Track the state of characters (if any) we see before our first dot and
// after any path separator we find
var preDotState = 0;
for (var i = path.length - 1; i >= 0; --i) {
var code = path.charCodeAt(i);
if (code === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
startPart = i + 1;
break;
}
continue;
}
if (end === -1) {
// We saw the first non-path separator, mark this as the end of our
// extension
matchedSlash = false;
end = i + 1;
}
if (code === 46 /*.*/) {
// If this is our first dot, mark it as the start of our extension
if (startDot === -1)
startDot = i;
else if (preDotState !== 1)
preDotState = 1;
} else if (startDot !== -1) {
// We saw a non-dot and non-path separator before our dot, so we should
// have a good chance at having a non-empty extension
preDotState = -1;
}
}
if (startDot === -1 || end === -1 ||
// We saw a non-dot character immediately before the dot
preDotState === 0 ||
// The (right-most) trimmed path component is exactly '..'
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
return '';
}
return path.slice(startDot, end);
exports.extname = function(path) {
return splitPath(path)[3];
};
function filter (xs, f) {
@ -571,7 +384,7 @@ var substr = 'ab'.substr(-1) === 'b'
;
}).call(this,require('_process'))
},{"_process":8}],8:[function(require,module,exports){
},{"_process":3}],3:[function(require,module,exports){
// shim for using process in browser
var process = module.exports = {};
@ -631,4 +444,112 @@ process.chdir = function (dir) {
};
process.umask = function() { return 0; };
},{}]},{},[1]);
},{}],4:[function(require,module,exports){
/*!
* glob-base <https://github.com/jonschlinkert/glob-base>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var path = require('path');
var parent = require('glob-parent');
module.exports = function globBase(pattern) {
if (typeof pattern !== 'string') {
throw new TypeError('glob-base expects a string.');
}
var res = {};
res.base = parent(pattern);
res.isGlob = res.base !== pattern;
if (res.base !== '.') {
res.glob = pattern.substr(res.base.length);
if (res.glob.charAt(0) === '/') {
res.glob = res.glob.substr(1);
}
} else {
res.glob = pattern;
}
if (!res.isGlob) {
res.base = dirname(pattern);
res.glob = res.base !== '.'
? pattern.substr(res.base.length)
: pattern;
}
if (res.glob.substr(0, 2) === './') {
res.glob = res.glob.substr(2);
}
if (res.glob.charAt(0) === '/') {
res.glob = res.glob.substr(1);
}
return res;
};
function dirname(glob) {
if (glob.slice(-1) === '/') return glob;
return path.dirname(glob);
}
},{"glob-parent":5,"path":2}],5:[function(require,module,exports){
'use strict';
var path = require('path');
var isglob = require('is-glob');
module.exports = function globParent(str) {
while (isglob(str)) str = path.dirname(str);
return str;
};
},{"is-glob":6,"path":2}],6:[function(require,module,exports){
/*!
* is-glob <https://github.com/jonschlinkert/is-glob>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
module.exports = function isGlob(str) {
return typeof str === 'string'
&& /[!*{}?(|)[\]]/.test(str);
};
},{}],7:[function(require,module,exports){
/*!
* is-dotfile <https://github.com/regexps/is-dotfile>
*
* Copyright (c) 2015 Jon Schlinkert, contributors.
* Licensed under the MIT license.
*/
module.exports = function(str) {
if (str.charCodeAt(0) === 46 /* . */ && str.indexOf('/', 1) === -1) {
return true;
}
var last = str.lastIndexOf('/');
return last !== -1 ? str.charCodeAt(last + 1) === 46 /* . */ : false;
};
},{}],8:[function(require,module,exports){
/*!
* is-extglob <https://github.com/jonschlinkert/is-extglob>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
module.exports = function isExtglob(str) {
return typeof str === 'string'
&& /[@?!+*]\(/.test(str);
};
},{}],9:[function(require,module,exports){
arguments[4][6][0].apply(exports,arguments)
},{"dup":6}]},{},[1]);

View File

@ -1,14 +1,23 @@
{
"name": "@plastichub/parse-glob",
"name": "parse-glob",
"description": "Parse a glob pattern into an object of tokens.",
"version": "3.0.5",
"version": "3.0.2",
"homepage": "https://github.com/jonschlinkert/parse-glob",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"repository": "jonschlinkert/parse-glob",
"author": {
"name": "Jon Schlinkert",
"url": "https://github.com/jonschlinkert"
},
"repository": {
"type": "git",
"url": "git://github.com/jonschlinkert/parse-glob.git"
},
"bugs": {
"url": "https://github.com/jonschlinkert/parse-glob/issues"
},
"license": "MIT",
"license": {
"type": "MIT",
"url": "https://github.com/jonschlinkert/parse-glob/blob/master/LICENSE"
},
"files": [
"index.js"
],
@ -21,14 +30,15 @@
"prepublish": "browserify -o browser.js -e index.js"
},
"dependencies": {
"glob-base": "^0.3.0",
"glob-base": "^0.2.0",
"is-dotfile": "^1.0.0",
"is-extglob": "^1.0.0",
"is-glob": "^2.0.0"
"is-glob": "^1.1.3"
},
"devDependencies": {
"browserify": "^9.0.3",
"mocha": "^3.0.0"
"lodash": "^3.3.1",
"mocha": "*"
},
"keywords": [
"glob",