diff options
Diffstat (limited to 'node_modules/extglob')
-rw-r--r-- | node_modules/extglob/LICENSE | 2 | ||||
-rw-r--r-- | node_modules/extglob/README.md | 372 | ||||
-rw-r--r-- | node_modules/extglob/index.js | 389 | ||||
-rw-r--r-- | node_modules/extglob/package.json | 96 |
4 files changed, 667 insertions, 192 deletions
diff --git a/node_modules/extglob/LICENSE b/node_modules/extglob/LICENSE index 65f90aca8..e33d14b75 100644 --- a/node_modules/extglob/LICENSE +++ b/node_modules/extglob/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015, Jon Schlinkert. +Copyright (c) 2015-2017, Jon Schlinkert. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/node_modules/extglob/README.md b/node_modules/extglob/README.md index 666440669..3255ea2b7 100644 --- a/node_modules/extglob/README.md +++ b/node_modules/extglob/README.md @@ -1,88 +1,362 @@ -# extglob [](http://badge.fury.io/js/extglob) [](https://travis-ci.org/jonschlinkert/extglob) +# extglob [](https://www.npmjs.com/package/extglob) [](https://npmjs.org/package/extglob) [](https://npmjs.org/package/extglob) [](https://travis-ci.org/micromatch/extglob) [](https://ci.appveyor.com/project/micromatch/extglob) -> Convert extended globs to regex-compatible strings. Add (almost) the expressive power of regular expressions to glob patterns. +> Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob patterns. -Install with [npm](https://www.npmjs.com/) +Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. + +## Install + +Install with [npm](https://www.npmjs.com/): ```sh -$ npm i extglob --save +$ npm install --save extglob ``` -Used by [micromatch](https://github.com/jonschlinkert/micromatch). +* Convert an extglob string to a regex-compatible string. +* More complete (and correct) support than [minimatch](https://github.com/isaacs/minimatch) (minimatch fails a large percentage of the extglob tests) +* Handles [negation patterns](#extglob-patterns) +* Handles [nested patterns](#extglob-patterns) +* Organized code base, easy to maintain and make changes when edge cases arise +* As you can see by the [benchmarks](#benchmarks), extglob doesn't pay with speed for it's completeness, accuracy and quality. -**Features** - -* Convert an extglob string to a regex-compatible string. **Only converts extglobs**, to handle full globs use [micromatch](https://github.com/jonschlinkert/micromatch). -* Pass `{regex: true}` to return a regex -* Handles nested patterns -* More complete (and correct) support than [minimatch](https://github.com/isaacs/minimatch) +**Heads up!**: This library only supports extglobs, to handle full glob patterns and other extended globbing features use [micromatch](https://github.com/jonschlinkert/micromatch) instead. ## Usage +The main export is a function that takes a string and options, and returns an object with the parsed AST and the compiled `.output`, which is a regex-compatible string that can be used for matching. + +```js +var extglob = require('extglob'); +console.log(extglob('!(xyz)*.js')); +``` + +## Extglob cheatsheet + +Extended globbing patterns can be defined as follows (as described by the [bash man page](https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html)): + +| **pattern** | **regex equivalent** | **description** | +| --- | --- | --- | +| `?(pattern-list)` | `(...|...)?` | Matches zero or one occurrence of the given pattern(s) | +| `*(pattern-list)` | `(...|...)*` | Matches zero or more occurrences of the given pattern(s) | +| `+(pattern-list)` | `(...|...)+` | Matches one or more occurrences of the given pattern(s) | +| `@(pattern-list)` | `(...|...)` <sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup> | Matches one of the given pattern(s) | +| `!(pattern-list)` | N/A | Matches anything except one of the given pattern(s) | + +## API + +### [extglob](index.js#L36) + +Convert the given `extglob` pattern into a regex-compatible string. Returns an object with the compiled result and the parsed AST. + +**Params** + +* `pattern` **{String}** +* `options` **{Object}** +* `returns` **{String}** + +**Example** + +```js +var extglob = require('extglob'); +console.log(extglob('*.!(*a)')); +//=> '(?!\\.)[^/]*?\\.(?!(?!\\.)[^/]*?a\\b).*?' +``` + +### [.match](index.js#L56) + +Takes an array of strings and an extglob pattern and returns a new array that contains only the strings that match the pattern. + +**Params** + +* `list` **{Array}**: Array of strings to match +* `pattern` **{String}**: Extglob pattern +* `options` **{Object}** +* `returns` **{Array}**: Returns an array of matches + +**Example** + +```js +var extglob = require('extglob'); +console.log(extglob.match(['a.a', 'a.b', 'a.c'], '*.!(*a)')); +//=> ['a.b', 'a.c'] +``` + +### [.isMatch](index.js#L111) + +Returns true if the specified `string` matches the given extglob `pattern`. + +**Params** + +* `string` **{String}**: String to match +* `pattern` **{String}**: Extglob pattern +* `options` **{String}** +* `returns` **{Boolean}** + +**Example** + ```js var extglob = require('extglob'); -extglob('?(z)'); -//=> '(?:z)?' -extglob('*(z)'); -//=> '(?:z)*' -extglob('+(z)'); -//=> '(?:z)+' -extglob('@(z)'); -//=> '(?:z)' -extglob('!(z)'); -//=> '(?!^(?:(?!z)[^/]*?)).*$' +console.log(extglob.isMatch('a.a', '*.!(*a)')); +//=> false +console.log(extglob.isMatch('a.b', '*.!(*a)')); +//=> true ``` -**Optionally return regex** +### [.contains](index.js#L150) + +Returns true if the given `string` contains the given pattern. Similar to `.isMatch` but the pattern can match any part of the string. + +**Params** + +* `str` **{String}**: The string to match. +* `pattern` **{String}**: Glob pattern to use for matching. +* `options` **{Object}** +* `returns` **{Boolean}**: Returns true if the patter matches any part of `str`. + +**Example** ```js -extglob('!(z)', {regex: true}); -//=> /(?!^(?:(?!z)[^/]*?)).*$/ +var extglob = require('extglob'); +console.log(extglob.contains('aa/bb/cc', '*b')); +//=> true +console.log(extglob.contains('aa/bb/cc', '*d')); +//=> false ``` -## Extglob patterns +### [.matcher](index.js#L184) + +Takes an extglob pattern and returns a matcher function. The returned function takes the string to match as its only argument. + +**Params** + +* `pattern` **{String}**: Extglob pattern +* `options` **{String}** +* `returns` **{Boolean}** -To learn more about how extglobs work, see the docs for [Bash pattern matching](https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html): +**Example** -* `?(pattern)`: Match zero or one occurrence of the given pattern. -* `*(pattern)`: Match zero or more occurrences of the given pattern. -* `+(pattern)`: Match one or more occurrences of the given pattern. -* `@(pattern)`: Match one of the given pattern. -* `!(pattern)`: Match anything except one of the given pattern. +```js +var extglob = require('extglob'); +var isMatch = extglob.matcher('*.!(*a)'); + +console.log(isMatch('a.a')); +//=> false +console.log(isMatch('a.b')); +//=> true +``` -## Related +### [.create](index.js#L214) -* [braces](https://github.com/jonschlinkert/braces): Fastest brace expansion for node.js, with the most complete support for the Bash 4.3 braces… [more](https://github.com/jonschlinkert/braces) -* [expand-brackets](https://github.com/jonschlinkert/expand-brackets): Expand POSIX bracket expressions (character classes) in glob patterns. -* [expand-range](https://github.com/jonschlinkert/expand-range): Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. See… [more](https://github.com/jonschlinkert/expand-range) -* [fill-range](https://github.com/jonschlinkert/fill-range): Fill in a range of numbers or letters, optionally passing an increment or multiplier to… [more](https://github.com/jonschlinkert/fill-range) -* [micromatch](https://github.com/jonschlinkert/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just… [more](https://github.com/jonschlinkert/micromatch) +Convert the given `extglob` pattern into a regex-compatible string. Returns an object with the compiled result and the parsed AST. -## Run tests +**Params** -Install dev dependencies: +* `str` **{String}** +* `options` **{Object}** +* `returns` **{String}** + +**Example** + +```js +var extglob = require('extglob'); +console.log(extglob.create('*.!(*a)').output); +//=> '(?!\\.)[^/]*?\\.(?!(?!\\.)[^/]*?a\\b).*?' +``` + +### [.capture](index.js#L248) + +Returns an array of matches captured by `pattern` in `string`, or `null` if the pattern did not match. + +**Params** + +* `pattern` **{String}**: Glob pattern to use for matching. +* `string` **{String}**: String to match +* `options` **{Object}**: See available [options](#options) for changing how matches are performed +* `returns` **{Boolean}**: Returns an array of captures if the string matches the glob pattern, otherwise `null`. + +**Example** + +```js +var extglob = require('extglob'); +extglob.capture(pattern, string[, options]); + +console.log(extglob.capture('test/*.js', 'test/foo.js')); +//=> ['foo'] +console.log(extglob.capture('test/*.js', 'foo/bar.css')); +//=> null +``` + +### [.makeRe](index.js#L281) + +Create a regular expression from the given `pattern` and `options`. + +**Params** + +* `pattern` **{String}**: The pattern to convert to regex. +* `options` **{Object}** +* `returns` **{RegExp}** + +**Example** + +```js +var extglob = require('extglob'); +var re = extglob.makeRe('*.!(*a)'); +console.log(re); +//=> /^[^\/]*?\.(?![^\/]*?a)[^\/]*?$/ +``` + +## Options + +Available options are based on the options from Bash (and the option names used in bash). + +### options.nullglob + +**Type**: `boolean` + +**Default**: `undefined` + +When enabled, the pattern itself will be returned when no matches are found. + +### options.nonull + +Alias for [options.nullglob](#optionsnullglob), included for parity with minimatch. + +### options.cache + +**Type**: `boolean` + +**Default**: `undefined` + +Functions are memoized based on the given glob patterns and options. Disable memoization by setting `options.cache` to false. + +### options.failglob + +**Type**: `boolean` + +**Default**: `undefined` + +Throw an error is no matches are found. + +## Benchmarks + +Last run on December 21, 2017 ```sh -$ npm i -d && npm test +# negation-nested (49 bytes) + extglob x 2,228,255 ops/sec ±0.98% (89 runs sampled) + minimatch x 207,875 ops/sec ±0.61% (91 runs sampled) + + fastest is extglob (by 1072% avg) + +# negation-simple (43 bytes) + extglob x 2,205,668 ops/sec ±1.00% (91 runs sampled) + minimatch x 311,923 ops/sec ±1.25% (91 runs sampled) + + fastest is extglob (by 707% avg) + +# range-false (57 bytes) + extglob x 2,263,877 ops/sec ±0.40% (94 runs sampled) + minimatch x 271,372 ops/sec ±1.02% (91 runs sampled) + + fastest is extglob (by 834% avg) + +# range-true (56 bytes) + extglob x 2,161,891 ops/sec ±0.41% (92 runs sampled) + minimatch x 268,265 ops/sec ±1.17% (91 runs sampled) + + fastest is extglob (by 806% avg) + +# star-simple (46 bytes) + extglob x 2,211,081 ops/sec ±0.49% (92 runs sampled) + minimatch x 343,319 ops/sec ±0.59% (91 runs sampled) + + fastest is extglob (by 644% avg) + +``` + +## Differences from Bash + +This library has complete parity with Bash 4.3 with only a couple of minor differences. + +* In some cases Bash returns true if the given string "contains" the pattern, whereas this library returns true if the string is an exact match for the pattern. You can relax this by setting `options.contains` to true. +* This library is more accurate than Bash and thus does not fail some of the tests that Bash 4.3 still lists as failing in their unit tests + +## About + +<details> +<summary><strong>Contributing</strong></summary> + +Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). + +</details> + +<details> +<summary><strong>Running Tests</strong></summary> + +Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: + +```sh +$ npm install && npm test ``` -## Contributing +</details> +<details> +<summary><strong>Building docs</strong></summary> + +_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ + +To generate the readme, run the following command: + +```sh +$ npm install -g verbose/verb#dev verb-generate-readme && verb +``` -Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/extglob/issues/new) +</details> -## Author +### Related projects + +You might also be interested in these projects: + +* [braces](https://www.npmjs.com/package/braces): Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support… [more](https://github.com/micromatch/braces) | [homepage](https://github.com/micromatch/braces "Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support for the Bash 4.3 braces specification, without sacrificing speed.") +* [expand-brackets](https://www.npmjs.com/package/expand-brackets): Expand POSIX bracket expressions (character classes) in glob patterns. | [homepage](https://github.com/jonschlinkert/expand-brackets "Expand POSIX bracket expressions (character classes) in glob patterns.") +* [expand-range](https://www.npmjs.com/package/expand-range): Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used… [more](https://github.com/jonschlinkert/expand-range) | [homepage](https://github.com/jonschlinkert/expand-range "Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used by [micromatch].") +* [fill-range](https://www.npmjs.com/package/fill-range): Fill in a range of numbers or letters, optionally passing an increment or `step` to… [more](https://github.com/jonschlinkert/fill-range) | [homepage](https://github.com/jonschlinkert/fill-range "Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`") +* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | [homepage](https://github.com/micromatch/micromatch "Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.") + +### Contributors + +| **Commits** | **Contributor** | +| --- | --- | +| 49 | [jonschlinkert](https://github.com/jonschlinkert) | +| 2 | [isiahmeadows](https://github.com/isiahmeadows) | +| 1 | [doowb](https://github.com/doowb) | +| 1 | [devongovett](https://github.com/devongovett) | +| 1 | [mjbvz](https://github.com/mjbvz) | +| 1 | [shinnn](https://github.com/shinnn) | + +### Author **Jon Schlinkert** -+ [github/jonschlinkert](https://github.com/jonschlinkert) -+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) +* [linkedin/in/jonschlinkert](https://linkedin.com/in/jonschlinkert) +* [github/jonschlinkert](https://github.com/jonschlinkert) +* [twitter/jonschlinkert](https://twitter.com/jonschlinkert) -## License +### License -Copyright © 2015 Jon Schlinkert -Released under the MIT license. +Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). +Released under the [MIT License](LICENSE). *** -_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on August 01, 2015._
\ No newline at end of file +_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on December 21, 2017._ + +<hr class="footnotes-sep"> +<section class="footnotes"> +<ol class="footnotes-list"> +<li id="fn1" class="footnote-item">`@` isn "'t a RegEx character." <a href="#fnref1" class="footnote-backref">↩</a> + +</li> +</ol> +</section>
\ No newline at end of file diff --git a/node_modules/extglob/index.js b/node_modules/extglob/index.js index 2e774d4aa..116e6d5cb 100644 --- a/node_modules/extglob/index.js +++ b/node_modules/extglob/index.js @@ -1,178 +1,331 @@ -/*! - * extglob <https://github.com/jonschlinkert/extglob> - * - * Copyright (c) 2015, Jon Schlinkert. - * Licensed under the MIT License. - */ - 'use strict'; /** * Module dependencies */ -var isExtglob = require('is-extglob'); -var re, cache = {}; +var extend = require('extend-shallow'); +var unique = require('array-unique'); +var toRegex = require('to-regex'); /** - * Expose `extglob` + * Local dependencies */ -module.exports = extglob; +var compilers = require('./lib/compilers'); +var parsers = require('./lib/parsers'); +var Extglob = require('./lib/extglob'); +var utils = require('./lib/utils'); +var MAX_LENGTH = 1024 * 64; /** - * Convert the given extglob `string` to a regex-compatible - * string. + * Convert the given `extglob` pattern into a regex-compatible string. Returns + * an object with the compiled result and the parsed AST. * * ```js * var extglob = require('extglob'); - * extglob('!(a?(b))'); - * //=> '(?!a(?:b)?)[^/]*?' + * console.log(extglob('*.!(*a)')); + * //=> '(?!\\.)[^/]*?\\.(?!(?!\\.)[^/]*?a\\b).*?' * ``` - * - * @param {String} `str` The string to convert. + * @param {String} `pattern` * @param {Object} `options` - * @option {Boolean} [options] `esc` If `false` special characters will not be escaped. Defaults to `true`. - * @option {Boolean} [options] `regex` If `true` a regular expression is returned instead of a string. * @return {String} * @api public */ +function extglob(pattern, options) { + return extglob.create(pattern, options).output; +} + +/** + * Takes an array of strings and an extglob pattern and returns a new + * array that contains only the strings that match the pattern. + * + * ```js + * var extglob = require('extglob'); + * console.log(extglob.match(['a.a', 'a.b', 'a.c'], '*.!(*a)')); + * //=> ['a.b', 'a.c'] + * ``` + * @param {Array} `list` Array of strings to match + * @param {String} `pattern` Extglob pattern + * @param {Object} `options` + * @return {Array} Returns an array of matches + * @api public + */ + +extglob.match = function(list, pattern, options) { + if (typeof pattern !== 'string') { + throw new TypeError('expected pattern to be a string'); + } -function extglob(str, opts) { - opts = opts || {}; - var o = {}, i = 0; + list = utils.arrayify(list); + var isMatch = extglob.matcher(pattern, options); + var len = list.length; + var idx = -1; + var matches = []; - // fix common character reversals - // '*!(.js)' => '*.!(js)' - str = str.replace(/!\(([^\w*()])/g, '$1!('); + while (++idx < len) { + var ele = list[idx]; - // support file extension negation - str = str.replace(/([*\/])\.!\([*]\)/g, function (m, ch) { - if (ch === '/') { - return escape('\\/[^.]+'); + if (isMatch(ele)) { + matches.push(ele); } - return escape('[^.]+'); - }); - - // create a unique key for caching by - // combining the string and options - var key = str - + String(!!opts.regex) - + String(!!opts.contains) - + String(!!opts.escape); + } - if (cache.hasOwnProperty(key)) { - return cache[key]; + // if no options were passed, uniquify results and return + if (typeof options === 'undefined') { + return unique(matches); } - if (!(re instanceof RegExp)) { - re = regex(); + if (matches.length === 0) { + if (options.failglob === true) { + throw new Error('no matches found for "' + pattern + '"'); + } + if (options.nonull === true || options.nullglob === true) { + return [pattern.split('\\').join('')]; + } } - opts.negate = false; - var m; + return options.nodupes !== false ? unique(matches) : matches; +}; - while (m = re.exec(str)) { - var prefix = m[1]; - var inner = m[3]; - if (prefix === '!') { - opts.negate = true; - } +/** + * Returns true if the specified `string` matches the given + * extglob `pattern`. + * + * ```js + * var extglob = require('extglob'); + * + * console.log(extglob.isMatch('a.a', '*.!(*a)')); + * //=> false + * console.log(extglob.isMatch('a.b', '*.!(*a)')); + * //=> true + * ``` + * @param {String} `string` String to match + * @param {String} `pattern` Extglob pattern + * @param {String} `options` + * @return {Boolean} + * @api public + */ - var id = '__EXTGLOB_' + (i++) + '__'; - // use the prefix of the _last_ (outtermost) pattern - o[id] = wrap(inner, prefix, opts.escape); - str = str.split(m[0]).join(id); +extglob.isMatch = function(str, pattern, options) { + if (typeof pattern !== 'string') { + throw new TypeError('expected pattern to be a string'); } - var keys = Object.keys(o); - var len = keys.length; + if (typeof str !== 'string') { + throw new TypeError('expected a string'); + } - // we have to loop again to allow us to convert - // patterns in reverse order (starting with the - // innermost/last pattern first) - while (len--) { - var prop = keys[len]; - str = str.split(prop).join(o[prop]); + if (pattern === str) { + return true; } - var result = opts.regex - ? toRegex(str, opts.contains, opts.negate) - : str; + if (pattern === '' || pattern === ' ' || pattern === '.') { + return pattern === str; + } - result = result.split('.').join('\\.'); + var isMatch = utils.memoize('isMatch', pattern, options, extglob.matcher); + return isMatch(str); +}; - // cache the result and return it - return (cache[key] = result); -} +/** + * Returns true if the given `string` contains the given pattern. Similar to `.isMatch` but + * the pattern can match any part of the string. + * + * ```js + * var extglob = require('extglob'); + * console.log(extglob.contains('aa/bb/cc', '*b')); + * //=> true + * console.log(extglob.contains('aa/bb/cc', '*d')); + * //=> false + * ``` + * @param {String} `str` The string to match. + * @param {String} `pattern` Glob pattern to use for matching. + * @param {Object} `options` + * @return {Boolean} Returns true if the patter matches any part of `str`. + * @api public + */ + +extglob.contains = function(str, pattern, options) { + if (typeof str !== 'string') { + throw new TypeError('expected a string'); + } + + if (pattern === '' || pattern === ' ' || pattern === '.') { + return pattern === str; + } + + var opts = extend({}, options, {contains: true}); + opts.strictClose = false; + opts.strictOpen = false; + return extglob.isMatch(str, pattern, opts); +}; /** - * Convert `string` to a regex string. + * Takes an extglob pattern and returns a matcher function. The returned + * function takes the string to match as its only argument. * - * @param {String} `str` - * @param {String} `prefix` Character that determines how to wrap the string. - * @param {Boolean} `esc` If `false` special characters will not be escaped. Defaults to `true`. - * @return {String} + * ```js + * var extglob = require('extglob'); + * var isMatch = extglob.matcher('*.!(*a)'); + * + * console.log(isMatch('a.a')); + * //=> false + * console.log(isMatch('a.b')); + * //=> true + * ``` + * @param {String} `pattern` Extglob pattern + * @param {String} `options` + * @return {Boolean} + * @api public */ -function wrap(inner, prefix, esc) { - if (esc) inner = escape(inner); - - switch (prefix) { - case '!': - return '(?!' + inner + ')[^/]' + (esc ? '%%%~' : '*?'); - case '@': - return '(?:' + inner + ')'; - case '+': - return '(?:' + inner + ')+'; - case '*': - return '(?:' + inner + ')' + (esc ? '%%' : '*') - case '?': - return '(?:' + inner + '|)'; - default: - return inner; +extglob.matcher = function(pattern, options) { + if (typeof pattern !== 'string') { + throw new TypeError('expected pattern to be a string'); } -} -function escape(str) { - str = str.split('*').join('[^/]%%%~'); - str = str.split('.').join('\\.'); - return str; -} + function matcher() { + var re = extglob.makeRe(pattern, options); + return function(str) { + return re.test(str); + }; + } + + return utils.memoize('matcher', pattern, options, matcher); +}; /** - * extglob regex. + * Convert the given `extglob` pattern into a regex-compatible string. Returns + * an object with the compiled result and the parsed AST. + * + * ```js + * var extglob = require('extglob'); + * console.log(extglob.create('*.!(*a)').output); + * //=> '(?!\\.)[^/]*?\\.(?!(?!\\.)[^/]*?a\\b).*?' + * ``` + * @param {String} `str` + * @param {Object} `options` + * @return {String} + * @api public */ -function regex() { - return /(\\?[@?!+*$]\\?)(\(([^()]*?)\))/; -} +extglob.create = function(pattern, options) { + if (typeof pattern !== 'string') { + throw new TypeError('expected pattern to be a string'); + } + + function create() { + var ext = new Extglob(options); + var ast = ext.parse(pattern, options); + return ext.compile(ast, options); + } + + return utils.memoize('create', pattern, options, create); +}; /** - * Negation regex + * Returns an array of matches captured by `pattern` in `string`, or `null` + * if the pattern did not match. + * + * ```js + * var extglob = require('extglob'); + * extglob.capture(pattern, string[, options]); + * + * console.log(extglob.capture('test/*.js', 'test/foo.js')); + * //=> ['foo'] + * console.log(extglob.capture('test/*.js', 'foo/bar.css')); + * //=> null + * ``` + * @param {String} `pattern` Glob pattern to use for matching. + * @param {String} `string` String to match + * @param {Object} `options` See available [options](#options) for changing how matches are performed + * @return {Boolean} Returns an array of captures if the string matches the glob pattern, otherwise `null`. + * @api public */ -function negate(str) { - return '(?!^' + str + ').*$'; -} +extglob.capture = function(pattern, str, options) { + var re = extglob.makeRe(pattern, extend({capture: true}, options)); + + function match() { + return function(string) { + var match = re.exec(string); + if (!match) { + return null; + } + + return match.slice(1); + }; + } + + var capture = utils.memoize('capture', pattern, options, match); + return capture(str); +}; /** - * Create the regex to do the matching. If - * the leading character in the `pattern` is `!` - * a negation regex is returned. + * Create a regular expression from the given `pattern` and `options`. * - * @param {String} `pattern` - * @param {Boolean} `contains` Allow loose matching. - * @param {Boolean} `isNegated` True if the pattern is a negation pattern. + * ```js + * var extglob = require('extglob'); + * var re = extglob.makeRe('*.!(*a)'); + * console.log(re); + * //=> /^[^\/]*?\.(?![^\/]*?a)[^\/]*?$/ + * ``` + * @param {String} `pattern` The pattern to convert to regex. + * @param {Object} `options` + * @return {RegExp} + * @api public */ -function toRegex(pattern, contains, isNegated) { - var prefix = contains ? '^' : ''; - var after = contains ? '$' : ''; - pattern = ('(?:' + pattern + ')' + after); - if (isNegated) { - pattern = prefix + negate(pattern); +extglob.makeRe = function(pattern, options) { + if (pattern instanceof RegExp) { + return pattern; } - return new RegExp(prefix + pattern); -} + + if (typeof pattern !== 'string') { + throw new TypeError('expected pattern to be a string'); + } + + if (pattern.length > MAX_LENGTH) { + throw new Error('expected pattern to be less than ' + MAX_LENGTH + ' characters'); + } + + function makeRe() { + var opts = extend({strictErrors: false}, options); + if (opts.strictErrors === true) opts.strict = true; + var res = extglob.create(pattern, opts); + return toRegex(res.output, opts); + } + + var regex = utils.memoize('makeRe', pattern, options, makeRe); + if (regex.source.length > MAX_LENGTH) { + throw new SyntaxError('potentially malicious regex detected'); + } + + return regex; +}; + +/** + * Cache + */ + +extglob.cache = utils.cache; +extglob.clearCache = function() { + extglob.cache.__data__ = {}; +}; + +/** + * Expose `Extglob` constructor, parsers and compilers + */ + +extglob.Extglob = Extglob; +extglob.compilers = compilers; +extglob.parsers = parsers; + +/** + * Expose `extglob` + * @type {Function} + */ + +module.exports = extglob; diff --git a/node_modules/extglob/package.json b/node_modules/extglob/package.json index 969cbe562..afe515732 100644 --- a/node_modules/extglob/package.json +++ b/node_modules/extglob/package.json @@ -1,22 +1,25 @@ { "name": "extglob", - "description": "Convert extended globs to regex-compatible strings. Add (almost) the expressive power of regular expressions to glob patterns.", - "version": "0.3.2", - "homepage": "https://github.com/jonschlinkert/extglob", - "author": { - "name": "Jon Schlinkert", - "url": "https://github.com/jonschlinkert" - }, - "repository": { - "type": "git", - "url": "git://github.com/jonschlinkert/extglob.git" - }, + "description": "Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob patterns.", + "version": "2.0.4", + "homepage": "https://github.com/micromatch/extglob", + "author": "Jon Schlinkert (https://github.com/jonschlinkert)", + "contributors": [ + "Brian Woodward (https://twitter.com/doowb)", + "Devon Govett (http://badassjs.com)", + "Isiah Meadows (https://www.isiahmeadows.com)", + "Jon Schlinkert (http://twitter.com/jonschlinkert)", + "Matt Bierner (http://mattbierner.com)", + "Shinnosuke Watanabe (https://shinnn.github.io)" + ], + "repository": "micromatch/extglob", "bugs": { - "url": "https://github.com/jonschlinkert/extglob/issues" + "url": "https://github.com/micromatch/extglob/issues" }, "license": "MIT", "files": [ - "index.js" + "index.js", + "lib" ], "main": "index.js", "engines": { @@ -26,35 +29,80 @@ "test": "mocha" }, "dependencies": { - "is-extglob": "^1.0.0" + "array-unique": "^0.3.2", + "define-property": "^1.0.0", + "expand-brackets": "^2.1.4", + "extend-shallow": "^2.0.1", + "fragment-cache": "^0.2.1", + "regex-not": "^1.0.0", + "snapdragon": "^0.8.1", + "to-regex": "^3.0.1" }, "devDependencies": { - "ansi-green": "^0.1.1", - "micromatch": "^2.1.6", - "minimatch": "^2.0.1", - "minimist": "^1.1.0", - "mocha": "*", - "should": "*", - "success-symbol": "^0.1.0" + "bash-match": "^1.0.2", + "for-own": "^1.0.0", + "gulp": "^3.9.1", + "gulp-eslint": "^4.0.0", + "gulp-format-md": "^1.0.0", + "gulp-istanbul": "^1.1.2", + "gulp-mocha": "^3.0.1", + "gulp-unused": "^0.2.1", + "helper-changelog": "^0.3.0", + "is-windows": "^1.0.1", + "micromatch": "^3.0.4", + "minimatch": "^3.0.4", + "minimist": "^1.2.0", + "mocha": "^3.5.0", + "multimatch": "^2.1.0" }, "keywords": [ "bash", "extended", "extglob", "glob", + "globbing", "ksh", "match", + "pattern", + "patterns", + "regex", + "test", "wildcard" ], + "lintDeps": { + "devDependencies": { + "files": { + "options": { + "ignore": [ + "benchmark/**/*.js" + ] + } + } + } + }, "verb": { + "toc": false, + "layout": "default", + "tasks": [ + "readme" + ], "related": { "list": [ - "micromatch", - "expand-brackets", "braces", + "expand-brackets", + "expand-range", "fill-range", - "expand-range" + "micromatch" ] + }, + "helpers": [ + "helper-changelog" + ], + "plugins": [ + "gulp-format-md" + ], + "lint": { + "reflinks": true } } } |