update, text, response
This commit is contained in:
184
node_modules/braces/CHANGELOG.md
generated
vendored
184
node_modules/braces/CHANGELOG.md
generated
vendored
@@ -1,184 +0,0 @@
|
||||
# Release history
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
<details>
|
||||
<summary><strong>Guiding Principles</strong></summary>
|
||||
|
||||
- Changelogs are for humans, not machines.
|
||||
- There should be an entry for every single version.
|
||||
- The same types of changes should be grouped.
|
||||
- Versions and sections should be linkable.
|
||||
- The latest version comes first.
|
||||
- The release date of each versions is displayed.
|
||||
- Mention whether you follow Semantic Versioning.
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Types of changes</strong></summary>
|
||||
|
||||
Changelog entries are classified using the following labels _(from [keep-a-changelog](http://keepachangelog.com/)_):
|
||||
|
||||
- `Added` for new features.
|
||||
- `Changed` for changes in existing functionality.
|
||||
- `Deprecated` for soon-to-be removed features.
|
||||
- `Removed` for now removed features.
|
||||
- `Fixed` for any bug fixes.
|
||||
- `Security` in case of vulnerabilities.
|
||||
|
||||
</details>
|
||||
|
||||
## [3.0.0] - 2018-04-08
|
||||
|
||||
v3.0 is a complete refactor, resulting in a faster, smaller codebase, with fewer deps, and a more accurate parser and compiler.
|
||||
|
||||
**Breaking Changes**
|
||||
|
||||
- The undocumented `.makeRe` method was removed
|
||||
|
||||
**Non-breaking changes**
|
||||
|
||||
- Caching was removed
|
||||
|
||||
## [2.3.2] - 2018-04-08
|
||||
|
||||
- start refactoring
|
||||
- cover sets
|
||||
- better range handling
|
||||
|
||||
## [2.3.1] - 2018-02-17
|
||||
|
||||
- Remove unnecessary escape in Regex. (#14)
|
||||
|
||||
## [2.3.0] - 2017-10-19
|
||||
|
||||
- minor code reorganization
|
||||
- optimize regex
|
||||
- expose `maxLength` option
|
||||
|
||||
## [2.2.1] - 2017-05-30
|
||||
|
||||
- don't condense when braces contain extglobs
|
||||
|
||||
## [2.2.0] - 2017-05-28
|
||||
|
||||
- ensure word boundaries are preserved
|
||||
- fixes edge case where extglob characters precede a brace pattern
|
||||
|
||||
## [2.1.1] - 2017-04-27
|
||||
|
||||
- use snapdragon-node
|
||||
- handle edge case
|
||||
- optimizations, lint
|
||||
|
||||
## [2.0.4] - 2017-04-11
|
||||
|
||||
- pass opts to compiler
|
||||
- minor optimization in create method
|
||||
- re-write parser handlers to remove negation regex
|
||||
|
||||
## [2.0.3] - 2016-12-10
|
||||
|
||||
- use split-string
|
||||
- clear queue at the end
|
||||
- adds sequences example
|
||||
- add unit tests
|
||||
|
||||
## [2.0.2] - 2016-10-21
|
||||
|
||||
- fix comma handling in nested extglobs
|
||||
|
||||
## [2.0.1] - 2016-10-20
|
||||
|
||||
- add comments
|
||||
- more tests, ensure quotes are stripped
|
||||
|
||||
## [2.0.0] - 2016-10-19
|
||||
|
||||
- don't expand braces inside character classes
|
||||
- add quantifier pattern
|
||||
|
||||
## [1.8.5] - 2016-05-21
|
||||
|
||||
- Refactor (#10)
|
||||
|
||||
## [1.8.4] - 2016-04-20
|
||||
|
||||
- fixes https://github.com/jonschlinkert/micromatch/issues/66
|
||||
|
||||
## [1.8.0] - 2015-03-18
|
||||
|
||||
- adds exponent examples, tests
|
||||
- fixes the first example in https://github.com/jonschlinkert/micromatch/issues/38
|
||||
|
||||
## [1.6.0] - 2015-01-30
|
||||
|
||||
- optimizations, `bash` mode:
|
||||
- improve path escaping
|
||||
|
||||
## [1.5.0] - 2015-01-28
|
||||
|
||||
- Merge pull request #5 from eush77/lib-files
|
||||
|
||||
## [1.4.0] - 2015-01-24
|
||||
|
||||
- add extglob tests
|
||||
- externalize exponent function
|
||||
- better whitespace handling
|
||||
|
||||
## [1.3.0] - 2015-01-24
|
||||
|
||||
- make regex patterns explicity
|
||||
|
||||
## [1.1.0] - 2015-01-11
|
||||
|
||||
- don't create a match group with `makeRe`
|
||||
|
||||
## [1.0.0] - 2014-12-23
|
||||
|
||||
- Merge commit '97b05f5544f8348736a8efaecf5c32bbe3e2ad6e'
|
||||
- support empty brace syntax
|
||||
- better bash coverage
|
||||
- better support for regex strings
|
||||
|
||||
## [0.1.4] - 2014-11-14
|
||||
|
||||
- improve recognition of bad args, recognize mismatched argument types
|
||||
- support escaping
|
||||
- remove pathname-expansion
|
||||
- support whitespace in patterns
|
||||
|
||||
## [0.1.0]
|
||||
|
||||
- first commit
|
||||
|
||||
[2.3.2]: https://github.com/micromatch/braces/compare/2.3.1...2.3.2
|
||||
[2.3.1]: https://github.com/micromatch/braces/compare/2.3.0...2.3.1
|
||||
[2.3.0]: https://github.com/micromatch/braces/compare/2.2.1...2.3.0
|
||||
[2.2.1]: https://github.com/micromatch/braces/compare/2.2.0...2.2.1
|
||||
[2.2.0]: https://github.com/micromatch/braces/compare/2.1.1...2.2.0
|
||||
[2.1.1]: https://github.com/micromatch/braces/compare/2.1.0...2.1.1
|
||||
[2.1.0]: https://github.com/micromatch/braces/compare/2.0.4...2.1.0
|
||||
[2.0.4]: https://github.com/micromatch/braces/compare/2.0.3...2.0.4
|
||||
[2.0.3]: https://github.com/micromatch/braces/compare/2.0.2...2.0.3
|
||||
[2.0.2]: https://github.com/micromatch/braces/compare/2.0.1...2.0.2
|
||||
[2.0.1]: https://github.com/micromatch/braces/compare/2.0.0...2.0.1
|
||||
[2.0.0]: https://github.com/micromatch/braces/compare/1.8.5...2.0.0
|
||||
[1.8.5]: https://github.com/micromatch/braces/compare/1.8.4...1.8.5
|
||||
[1.8.4]: https://github.com/micromatch/braces/compare/1.8.0...1.8.4
|
||||
[1.8.0]: https://github.com/micromatch/braces/compare/1.6.0...1.8.0
|
||||
[1.6.0]: https://github.com/micromatch/braces/compare/1.5.0...1.6.0
|
||||
[1.5.0]: https://github.com/micromatch/braces/compare/1.4.0...1.5.0
|
||||
[1.4.0]: https://github.com/micromatch/braces/compare/1.3.0...1.4.0
|
||||
[1.3.0]: https://github.com/micromatch/braces/compare/1.2.0...1.3.0
|
||||
[1.2.0]: https://github.com/micromatch/braces/compare/1.1.0...1.2.0
|
||||
[1.1.0]: https://github.com/micromatch/braces/compare/1.0.0...1.1.0
|
||||
[1.0.0]: https://github.com/micromatch/braces/compare/0.1.4...1.0.0
|
||||
[0.1.4]: https://github.com/micromatch/braces/compare/0.1.0...0.1.4
|
||||
|
||||
[Unreleased]: https://github.com/micromatch/braces/compare/0.1.0...HEAD
|
||||
[keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog
|
||||
329
node_modules/braces/README.md
generated
vendored
329
node_modules/braces/README.md
generated
vendored
@@ -1,4 +1,4 @@
|
||||
# braces [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [](https://www.npmjs.com/package/braces) [](https://npmjs.org/package/braces) [](https://npmjs.org/package/braces) [](https://travis-ci.org/micromatch/braces)
|
||||
# braces [](https://www.npmjs.com/package/braces) [](https://npmjs.org/package/braces) [](https://npmjs.org/package/braces) [](https://travis-ci.org/micromatch/braces) [](https://ci.appveyor.com/project/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.
|
||||
|
||||
@@ -12,67 +12,67 @@ Install with [npm](https://www.npmjs.com/):
|
||||
$ npm install --save braces
|
||||
```
|
||||
|
||||
## v3.0.0 Released!!
|
||||
|
||||
See the [changelog](CHANGELOG.md) for details.
|
||||
|
||||
## Why use braces?
|
||||
|
||||
Brace patterns make globs more powerful by adding the ability to match specific ranges and sequences of characters.
|
||||
Brace patterns are great for matching ranges. Users (and implementors) shouldn't have to think about whether or not they will break their application (or yours) from accidentally defining an aggressive brace pattern. _Braces is the only library that offers a [solution to this problem](#performance)_.
|
||||
|
||||
* **Accurate** - complete support for the [Bash 4.3 Brace Expansion](www.gnu.org/software/bash/) specification (passes all of the Bash braces tests)
|
||||
* **[fast and performant](#benchmarks)** - Starts fast, runs fast and [scales well](#performance) as patterns increase in complexity.
|
||||
* **Organized code base** - The parser and compiler are easy to maintain and update when edge cases crop up.
|
||||
* **Well-tested** - Thousands of test assertions, and passes all of the Bash, minimatch, and [brace-expansion](https://github.com/juliangruber/brace-expansion) unit tests (as of the date this was written).
|
||||
* **Safer** - You shouldn't have to worry about users defining aggressive or malicious brace patterns that can break your application. Braces takes measures to prevent malicious regex that can be used for DDoS attacks (see [catastrophic backtracking](https://www.regular-expressions.info/catastrophic.html)).
|
||||
* [Supports lists](#lists) - (aka "sets") `a/{b,c}/d` => `['a/b/d', 'a/c/d']`
|
||||
* [Supports sequences](#sequences) - (aka "ranges") `{01..03}` => `['01', '02', '03']`
|
||||
* [Supports steps](#steps) - (aka "increments") `{2..10..2}` => `['2', '4', '6', '8', '10']`
|
||||
* [Supports escaping](#escaping) - To prevent evaluation of special characters.
|
||||
* **Safe(r)**: Braces isn't vulnerable to DoS attacks like [brace-expansion](https://github.com/juliangruber/brace-expansion), [minimatch](https://github.com/isaacs/minimatch) and [multimatch](https://github.com/sindresorhus/multimatch) (a different bug than the [other regex DoS bug](https://medium.com/node-security/minimatch-redos-vulnerability-590da24e6d3c#.jew0b6mpc)).
|
||||
* **Accurate**: complete support for the [Bash 4.3 Brace Expansion](www.gnu.org/software/bash/) specification (passes all of the Bash braces tests)
|
||||
* **[fast and performant](#benchmarks)**: Starts fast, runs fast and [scales well](#performance) as patterns increase in complexity.
|
||||
* **Organized code base**: with parser and compiler that are eas(y|ier) to maintain and update when edge cases crop up.
|
||||
* **Well-tested**: thousands of test assertions. Passes 100% of the [minimatch](https://github.com/isaacs/minimatch) and [brace-expansion](https://github.com/juliangruber/brace-expansion) unit tests as well (as of the writing of this).
|
||||
|
||||
## Usage
|
||||
|
||||
The main export is a function that takes one or more brace `patterns` and `options`.
|
||||
|
||||
```js
|
||||
const braces = require('braces');
|
||||
// braces(patterns[, options]);
|
||||
|
||||
console.log(braces(['{01..05}', '{a..e}']));
|
||||
//=> ['(0[1-5])', '([a-e])']
|
||||
|
||||
console.log(braces(['{01..05}', '{a..e}'], { expand: true }));
|
||||
//=> ['01', '02', '03', '04', '05', 'a', 'b', 'c', 'd', 'e']
|
||||
var braces = require('braces');
|
||||
braces(pattern[, options]);
|
||||
```
|
||||
|
||||
### Brace Expansion vs. Compilation
|
||||
By default, braces returns an optimized regex-source string. To get an array of brace patterns, use `brace.expand()`.
|
||||
|
||||
By default, brace patterns are compiled into strings that are optimized for creating regular expressions and matching.
|
||||
The following section explains the difference in more detail. _(If you're curious about "why" braces does this by default, see [brace matching pitfalls](#brace-matching-pitfalls)_.
|
||||
|
||||
**Compiled**
|
||||
### Optimized vs. expanded braces
|
||||
|
||||
**Optimized**
|
||||
|
||||
By default, patterns are optimized for regex and matching:
|
||||
|
||||
```js
|
||||
console.log(braces('a/{x,y,z}/b'));
|
||||
console.log(braces('a/{x,y,z}/b'));
|
||||
//=> ['a/(x|y|z)/b']
|
||||
console.log(braces(['a/{01..20}/b', 'a/{1..5}/b']));
|
||||
//=> [ 'a/(0[1-9]|1[0-9]|20)/b', 'a/([1-5])/b' ]
|
||||
```
|
||||
|
||||
**Expanded**
|
||||
|
||||
Enable brace expansion by setting the `expand` option to true, or by using [braces.expand()](#expand) (returns an array similar to what you'd expect from Bash, or `echo {1..5}`, or [minimatch](https://github.com/isaacs/minimatch)):
|
||||
To expand patterns the same way as Bash or [minimatch](https://github.com/isaacs/minimatch), use the [.expand](#expand) method:
|
||||
|
||||
```js
|
||||
console.log(braces('a/{x,y,z}/b', { expand: true }));
|
||||
console.log(braces.expand('a/{x,y,z}/b'));
|
||||
//=> ['a/x/b', 'a/y/b', 'a/z/b']
|
||||
|
||||
console.log(braces.expand('{01..10}'));
|
||||
//=> ['01','02','03','04','05','06','07','08','09','10']
|
||||
```
|
||||
|
||||
Or use [options.expand](#optionsexpand):
|
||||
|
||||
```js
|
||||
console.log(braces('a/{x,y,z}/b', {expand: true}));
|
||||
//=> ['a/x/b', 'a/y/b', 'a/z/b']
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
* [lists](#lists): Supports "lists": `a/{b,c}/d` => `['a/b/d', 'a/c/d']`
|
||||
* [sequences](#sequences): Supports alphabetical or numerical "sequences" (ranges): `{1..3}` => `['1', '2', '3']`
|
||||
* [steps](#steps): Supports "steps" or increments: `{2..10..2}` => `['2', '4', '6', '8', '10']`
|
||||
* [escaping](#escaping)
|
||||
* [options](#options)
|
||||
|
||||
### Lists
|
||||
|
||||
Expand lists (like Bash "sets"):
|
||||
Uses [fill-range](https://github.com/jonschlinkert/fill-range) for expanding alphabetical or numeric lists:
|
||||
|
||||
```js
|
||||
console.log(braces('a/{foo,bar,baz}/*.js'));
|
||||
@@ -84,22 +84,21 @@ console.log(braces.expand('a/{foo,bar,baz}/*.js'));
|
||||
|
||||
### Sequences
|
||||
|
||||
Expand ranges of characters (like Bash "sequences"):
|
||||
Uses [fill-range](https://github.com/jonschlinkert/fill-range) for expanding alphabetical or numeric ranges (bash "sequences"):
|
||||
|
||||
```js
|
||||
console.log(braces.expand('{1..3}')); // ['1', '2', '3']
|
||||
console.log(braces.expand('a/{1..3}/b')); // ['a/1/b', 'a/2/b', 'a/3/b']
|
||||
console.log(braces('{a..c}', { expand: true })); // ['a', 'b', 'c']
|
||||
console.log(braces('foo/{a..c}', { expand: true })); // ['foo/a', 'foo/b', 'foo/c']
|
||||
console.log(braces.expand('{1..3}')); // ['1', '2', '3']
|
||||
console.log(braces.expand('a{01..03}b')); // ['a01b', 'a02b', 'a03b']
|
||||
console.log(braces.expand('a{1..3}b')); // ['a1b', 'a2b', 'a3b']
|
||||
console.log(braces.expand('{a..c}')); // ['a', 'b', 'c']
|
||||
console.log(braces.expand('foo/{a..c}')); // ['foo/a', 'foo/b', 'foo/c']
|
||||
|
||||
// supports zero-padded ranges
|
||||
console.log(braces('a/{01..03}/b')); //=> ['a/(0[1-3])/b']
|
||||
console.log(braces('a/{001..300}/b')); //=> ['a/(0{2}[1-9]|0[1-9][0-9]|[12][0-9]{2}|300)/b']
|
||||
// supports padded ranges
|
||||
console.log(braces('a{01..03}b')); //=> [ 'a(0[1-3])b' ]
|
||||
console.log(braces('a{001..300}b')); //=> [ 'a(0{2}[1-9]|0[1-9][0-9]|[12][0-9]{2}|300)b' ]
|
||||
```
|
||||
|
||||
See [fill-range](https://github.com/jonschlinkert/fill-range) for all available range-expansion options.
|
||||
|
||||
### Steppped ranges
|
||||
### Steps
|
||||
|
||||
Steps, or increments, may be used with ranges:
|
||||
|
||||
@@ -192,30 +191,43 @@ console.log(braces('a/{b,c}/d', { maxLength: 3 })); //=> throws an error
|
||||
|
||||
**Default**: `undefined`
|
||||
|
||||
**Description**: Generate an "expanded" brace pattern (alternatively you can use the `braces.expand()` method, which does the same thing).
|
||||
**Description**: Generate an "expanded" brace pattern (this option is unncessary with the `.expand` method, which does the same thing).
|
||||
|
||||
```js
|
||||
console.log(braces('a/{b,c}/d', { expand: true }));
|
||||
console.log(braces('a/{b,c}/d', {expand: true}));
|
||||
//=> [ 'a/b/d', 'a/c/d' ]
|
||||
```
|
||||
|
||||
### options.optimize
|
||||
|
||||
**Type**: `Boolean`
|
||||
|
||||
**Default**: `true`
|
||||
|
||||
**Description**: Enabled by default.
|
||||
|
||||
```js
|
||||
console.log(braces('a/{b,c}/d'));
|
||||
//=> [ 'a/(b|c)/d' ]
|
||||
```
|
||||
|
||||
### options.nodupes
|
||||
|
||||
**Type**: `Boolean`
|
||||
|
||||
**Default**: `undefined`
|
||||
**Default**: `true`
|
||||
|
||||
**Description**: Remove duplicates from the returned array.
|
||||
**Description**: Duplicates are removed by default. To keep duplicates, pass `{nodupes: false}` on the options
|
||||
|
||||
### options.rangeLimit
|
||||
|
||||
**Type**: `Number`
|
||||
|
||||
**Default**: `1000`
|
||||
**Default**: `250`
|
||||
|
||||
**Description**: To prevent malicious patterns from being passed by users, an error is thrown when `braces.expand()` is used or `options.expand` is true and the generated range will exceed the `rangeLimit`.
|
||||
**Description**: When `braces.expand()` is used, or `options.expand` is true, brace patterns will automatically be [optimized](#optionsoptimize) when the difference between the range minimum and range maximum exceeds the `rangeLimit`. This is to prevent huge ranges from freezing your application.
|
||||
|
||||
You can customize `options.rangeLimit` or set it to `Inifinity` to disable this altogether.
|
||||
You can set this to any number, or change `options.rangeLimit` to `Inifinity` to disable this altogether.
|
||||
|
||||
**Examples**
|
||||
|
||||
@@ -237,30 +249,15 @@ console.log(braces.expand('{1..100}'));
|
||||
|
||||
**Description**: Customize range expansion.
|
||||
|
||||
**Example: Transforming non-numeric values**
|
||||
|
||||
```js
|
||||
const alpha = braces.expand('x/{a..e}/y', {
|
||||
transform(value, index) {
|
||||
// When non-numeric values are passed, "value" is a character code.
|
||||
return 'foo/' + String.fromCharCode(value) + '-' + index;
|
||||
var range = braces.expand('x{a..e}y', {
|
||||
transform: function(str) {
|
||||
return 'foo' + str;
|
||||
}
|
||||
});
|
||||
console.log(alpha);
|
||||
//=> [ 'x/foo/a-0/y', 'x/foo/b-1/y', 'x/foo/c-2/y', 'x/foo/d-3/y', 'x/foo/e-4/y' ]
|
||||
```
|
||||
|
||||
**Example: Transforming numeric values**
|
||||
|
||||
```js
|
||||
const numeric = braces.expand('{1..5}', {
|
||||
transform(value) {
|
||||
// when numeric values are passed, "value" is a number
|
||||
return 'foo/' + value * 2;
|
||||
}
|
||||
});
|
||||
console.log(numeric);
|
||||
//=> [ 'foo/2', 'foo/4', 'foo/6', 'foo/8', 'foo/10' ]
|
||||
console.log(range);
|
||||
//=> [ 'xfooay', 'xfooby', 'xfoocy', 'xfoody', 'xfooey' ]
|
||||
```
|
||||
|
||||
### options.quantifiers
|
||||
@@ -278,7 +275,7 @@ The `quantifiers` option tells braces to detect when [regex quantifiers](https:/
|
||||
**Examples**
|
||||
|
||||
```js
|
||||
const braces = require('braces');
|
||||
var braces = require('braces');
|
||||
console.log(braces('a/b{1,3}/{x,y,z}'));
|
||||
//=> [ 'a/b(1|3)/(x|y|z)' ]
|
||||
console.log(braces('a/b{1,3}/{x,y,z}', {quantifiers: true}));
|
||||
@@ -444,25 +441,25 @@ Instead, convert the pattern into an optimized regular expression. This is easie
|
||||
|
||||
Minimatch gets exponentially slower as patterns increase in complexity, braces does not. The following results were generated using `braces()` and `minimatch.braceExpand()`, respectively.
|
||||
|
||||
| **Pattern** | **braces** | **[minimatch][]** |
|
||||
| --- | --- | --- |
|
||||
| `{1..9007199254740991}`[^1] | `298 B` (5ms 459μs)| N/A (freezes) |
|
||||
| `{1..1000000000000000}` | `41 B` (1ms 15μs) | N/A (freezes) |
|
||||
| `{1..100000000000000}` | `40 B` (890μs) | N/A (freezes) |
|
||||
| `{1..10000000000000}` | `39 B` (2ms 49μs) | N/A (freezes) |
|
||||
| `{1..1000000000000}` | `38 B` (608μs) | N/A (freezes) |
|
||||
| `{1..100000000000}` | `37 B` (397μs) | N/A (freezes) |
|
||||
| `{1..10000000000}` | `35 B` (983μs) | N/A (freezes) |
|
||||
| `{1..1000000000}` | `34 B` (798μs) | N/A (freezes) |
|
||||
| `{1..100000000}` | `33 B` (733μs) | N/A (freezes) |
|
||||
| `{1..10000000}` | `32 B` (5ms 632μs) | `78.89 MB` (16s 388ms 569μs) |
|
||||
| `{1..1000000}` | `31 B` (1ms 381μs) | `6.89 MB` (1s 496ms 887μs) |
|
||||
| `{1..100000}` | `30 B` (950μs) | `588.89 kB` (146ms 921μs) |
|
||||
| `{1..10000}` | `29 B` (1ms 114μs) | `48.89 kB` (14ms 187μs) |
|
||||
| `{1..1000}` | `28 B` (760μs) | `3.89 kB` (1ms 453μs) |
|
||||
| `{1..100}` | `22 B` (345μs) | `291 B` (196μs) |
|
||||
| `{1..10}` | `10 B` (533μs) | `20 B` (37μs) |
|
||||
| `{1..3}` | `7 B` (190μs) | `5 B` (27μs) |
|
||||
| **Pattern** | **braces** | **[minimatch](https://github.com/isaacs/minimatch)** |
|
||||
| --- | --- | --- |
|
||||
| `{1..9007199254740991}`<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup> | `298 B` (5ms 459μs) | N/A (freezes) |
|
||||
| `{1..1000000000000000}` | `41 B` (1ms 15μs) | N/A (freezes) |
|
||||
| `{1..100000000000000}` | `40 B` (890μs) | N/A (freezes) |
|
||||
| `{1..10000000000000}` | `39 B` (2ms 49μs) | N/A (freezes) |
|
||||
| `{1..1000000000000}` | `38 B` (608μs) | N/A (freezes) |
|
||||
| `{1..100000000000}` | `37 B` (397μs) | N/A (freezes) |
|
||||
| `{1..10000000000}` | `35 B` (983μs) | N/A (freezes) |
|
||||
| `{1..1000000000}` | `34 B` (798μs) | N/A (freezes) |
|
||||
| `{1..100000000}` | `33 B` (733μs) | N/A (freezes) |
|
||||
| `{1..10000000}` | `32 B` (5ms 632μs) | `78.89 MB` (16s 388ms 569μs) |
|
||||
| `{1..1000000}` | `31 B` (1ms 381μs) | `6.89 MB` (1s 496ms 887μs) |
|
||||
| `{1..100000}` | `30 B` (950μs) | `588.89 kB` (146ms 921μs) |
|
||||
| `{1..10000}` | `29 B` (1ms 114μs) | `48.89 kB` (14ms 187μs) |
|
||||
| `{1..1000}` | `28 B` (760μs) | `3.89 kB` (1ms 453μs) |
|
||||
| `{1..100}` | `22 B` (345μs) | `291 B` (196μs) |
|
||||
| `{1..10}` | `10 B` (533μs) | `20 B` (37μs) |
|
||||
| `{1..3}` | `7 B` (190μs) | `5 B` (27μs) |
|
||||
|
||||
### Faster algorithms
|
||||
|
||||
@@ -470,16 +467,16 @@ When you need expansion, braces is still much faster.
|
||||
|
||||
_(the following results were generated using `braces.expand()` and `minimatch.braceExpand()`, respectively)_
|
||||
|
||||
| **Pattern** | **braces** | **[minimatch][]** |
|
||||
| --- | --- | --- |
|
||||
| **Pattern** | **braces** | **[minimatch](https://github.com/isaacs/minimatch)** |
|
||||
| --- | --- | --- |
|
||||
| `{1..10000000}` | `78.89 MB` (2s 698ms 642μs) | `78.89 MB` (18s 601ms 974μs) |
|
||||
| `{1..1000000}` | `6.89 MB` (458ms 576μs) | `6.89 MB` (1s 491ms 621μs) |
|
||||
| `{1..100000}` | `588.89 kB` (20ms 728μs) | `588.89 kB` (156ms 919μs) |
|
||||
| `{1..10000}` | `48.89 kB` (2ms 202μs) | `48.89 kB` (13ms 641μs) |
|
||||
| `{1..1000}` | `3.89 kB` (1ms 796μs) | `3.89 kB` (1ms 958μs) |
|
||||
| `{1..100}` | `291 B` (424μs) | `291 B` (211μs) |
|
||||
| `{1..10}` | `20 B` (487μs) | `20 B` (72μs) |
|
||||
| `{1..3}` | `5 B` (166μs) | `5 B` (27μs) |
|
||||
| `{1..1000000}` | `6.89 MB` (458ms 576μs) | `6.89 MB` (1s 491ms 621μs) |
|
||||
| `{1..100000}` | `588.89 kB` (20ms 728μs) | `588.89 kB` (156ms 919μs) |
|
||||
| `{1..10000}` | `48.89 kB` (2ms 202μs) | `48.89 kB` (13ms 641μs) |
|
||||
| `{1..1000}` | `3.89 kB` (1ms 796μs) | `3.89 kB` (1ms 958μs) |
|
||||
| `{1..100}` | `291 B` (424μs) | `291 B` (211μs) |
|
||||
| `{1..10}` | `20 B` (487μs) | `20 B` (72μs) |
|
||||
| `{1..3}` | `5 B` (166μs) | `5 B` (27μs) |
|
||||
|
||||
If you'd like to run these comparisons yourself, see [test/support/generate.js](test/support/generate.js).
|
||||
|
||||
@@ -495,40 +492,72 @@ npm i -d && npm benchmark
|
||||
|
||||
### Latest results
|
||||
|
||||
Braces is more accurate, without sacrificing performance.
|
||||
|
||||
```bash
|
||||
# range (expanded)
|
||||
braces x 29,040 ops/sec ±3.69% (91 runs sampled))
|
||||
minimatch x 4,735 ops/sec ±1.28% (90 runs sampled)
|
||||
Benchmarking: (8 of 8)
|
||||
· combination-nested
|
||||
· combination
|
||||
· escaped
|
||||
· list-basic
|
||||
· list-multiple
|
||||
· no-braces
|
||||
· sequence-basic
|
||||
· sequence-multiple
|
||||
|
||||
# range (optimized for regex)
|
||||
braces x 382,878 ops/sec ±0.56% (94 runs sampled)
|
||||
minimatch x 1,040 ops/sec ±0.44% (93 runs sampled)
|
||||
# benchmark/fixtures/combination-nested.js (52 bytes)
|
||||
brace-expansion x 4,756 ops/sec ±1.09% (86 runs sampled)
|
||||
braces x 11,202,303 ops/sec ±1.06% (88 runs sampled)
|
||||
minimatch x 4,816 ops/sec ±0.99% (87 runs sampled)
|
||||
|
||||
# nested ranges (expanded)
|
||||
braces x 19,744 ops/sec ±2.27% (92 runs sampled))
|
||||
minimatch x 4,579 ops/sec ±0.50% (93 runs sampled)
|
||||
fastest is braces
|
||||
|
||||
# nested ranges (optimized for regex)
|
||||
braces x 246,019 ops/sec ±2.02% (93 runs sampled)
|
||||
minimatch x 1,028 ops/sec ±0.39% (94 runs sampled)
|
||||
# benchmark/fixtures/combination.js (51 bytes)
|
||||
brace-expansion x 625 ops/sec ±0.87% (87 runs sampled)
|
||||
braces x 11,031,884 ops/sec ±0.72% (90 runs sampled)
|
||||
minimatch x 637 ops/sec ±0.84% (88 runs sampled)
|
||||
|
||||
# set (expanded)
|
||||
braces x 138,641 ops/sec ±0.53% (95 runs sampled)
|
||||
minimatch x 219,582 ops/sec ±0.98% (94 runs sampled)
|
||||
fastest is braces
|
||||
|
||||
# set (optimized for regex)
|
||||
braces x 388,408 ops/sec ±0.41% (95 runs sampled)
|
||||
minimatch x 44,724 ops/sec ±0.91% (89 runs sampled)
|
||||
# benchmark/fixtures/escaped.js (44 bytes)
|
||||
brace-expansion x 163,325 ops/sec ±1.05% (87 runs sampled)
|
||||
braces x 10,655,071 ops/sec ±1.22% (88 runs sampled)
|
||||
minimatch x 147,495 ops/sec ±0.96% (88 runs sampled)
|
||||
|
||||
# nested sets (expanded)
|
||||
braces x 84,966 ops/sec ±0.48% (94 runs sampled)
|
||||
minimatch x 140,720 ops/sec ±0.37% (95 runs sampled)
|
||||
fastest is braces
|
||||
|
||||
# nested sets (optimized for regex)
|
||||
braces x 263,340 ops/sec ±2.06% (92 runs sampled)
|
||||
minimatch x 28,714 ops/sec ±0.40% (90 runs sampled)
|
||||
# benchmark/fixtures/list-basic.js (40 bytes)
|
||||
brace-expansion x 99,726 ops/sec ±1.07% (83 runs sampled)
|
||||
braces x 10,596,584 ops/sec ±0.98% (88 runs sampled)
|
||||
minimatch x 100,069 ops/sec ±1.17% (86 runs sampled)
|
||||
|
||||
fastest is braces
|
||||
|
||||
# benchmark/fixtures/list-multiple.js (52 bytes)
|
||||
brace-expansion x 34,348 ops/sec ±1.08% (88 runs sampled)
|
||||
braces x 9,264,131 ops/sec ±1.12% (88 runs sampled)
|
||||
minimatch x 34,893 ops/sec ±0.87% (87 runs sampled)
|
||||
|
||||
fastest is braces
|
||||
|
||||
# benchmark/fixtures/no-braces.js (48 bytes)
|
||||
brace-expansion x 275,368 ops/sec ±1.18% (89 runs sampled)
|
||||
braces x 9,134,677 ops/sec ±0.95% (88 runs sampled)
|
||||
minimatch x 3,755,954 ops/sec ±1.13% (89 runs sampled)
|
||||
|
||||
fastest is braces
|
||||
|
||||
# benchmark/fixtures/sequence-basic.js (41 bytes)
|
||||
brace-expansion x 5,492 ops/sec ±1.35% (87 runs sampled)
|
||||
braces x 8,485,034 ops/sec ±1.28% (89 runs sampled)
|
||||
minimatch x 5,341 ops/sec ±1.17% (87 runs sampled)
|
||||
|
||||
fastest is braces
|
||||
|
||||
# benchmark/fixtures/sequence-multiple.js (51 bytes)
|
||||
brace-expansion x 116 ops/sec ±0.77% (77 runs sampled)
|
||||
braces x 9,445,118 ops/sec ±1.32% (84 runs sampled)
|
||||
minimatch x 109 ops/sec ±1.16% (76 runs sampled)
|
||||
|
||||
fastest is braces
|
||||
```
|
||||
|
||||
## About
|
||||
@@ -564,30 +593,48 @@ $ npm install -g verbose/verb#dev verb-generate-readme && verb
|
||||
|
||||
</details>
|
||||
|
||||
### Related projects
|
||||
|
||||
You might also be interested in these projects:
|
||||
|
||||
* [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.")
|
||||
* [extglob](https://www.npmjs.com/package/extglob): Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob… [more](https://github.com/micromatch/extglob) | [homepage](https://github.com/micromatch/extglob "Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob patterns.")
|
||||
* [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.")
|
||||
* [nanomatch](https://www.npmjs.com/package/nanomatch): Fast, minimal glob matcher for node.js. Similar to micromatch, minimatch and multimatch, but complete Bash… [more](https://github.com/micromatch/nanomatch) | [homepage](https://github.com/micromatch/nanomatch "Fast, minimal glob matcher for node.js. Similar to micromatch, minimatch and multimatch, but complete Bash 4.3 wildcard support only (no support for exglobs, posix brackets or braces)")
|
||||
|
||||
### Contributors
|
||||
|
||||
| **Commits** | **Contributor** |
|
||||
| --- | --- |
|
||||
| 197 | [jonschlinkert](https://github.com/jonschlinkert) |
|
||||
| 4 | [doowb](https://github.com/doowb) |
|
||||
| 1 | [es128](https://github.com/es128) |
|
||||
| 1 | [eush77](https://github.com/eush77) |
|
||||
| 1 | [hemanth](https://github.com/hemanth) |
|
||||
| 1 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |
|
||||
| **Commits** | **Contributor** |
|
||||
| --- | --- |
|
||||
| 188 | [jonschlinkert](https://github.com/jonschlinkert) |
|
||||
| 4 | [doowb](https://github.com/doowb) |
|
||||
| 1 | [es128](https://github.com/es128) |
|
||||
| 1 | [eush77](https://github.com/eush77) |
|
||||
| 1 | [hemanth](https://github.com/hemanth) |
|
||||
|
||||
### Author
|
||||
|
||||
**Jon Schlinkert**
|
||||
|
||||
* [GitHub Profile](https://github.com/jonschlinkert)
|
||||
* [Twitter Profile](https://twitter.com/jonschlinkert)
|
||||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
||||
* [linkedin/in/jonschlinkert](https://linkedin.com/in/jonschlinkert)
|
||||
* [github/jonschlinkert](https://github.com/jonschlinkert)
|
||||
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
|
||||
|
||||
### License
|
||||
|
||||
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
|
||||
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
|
||||
Released under the [MIT License](LICENSE).
|
||||
|
||||
***
|
||||
|
||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 08, 2019._
|
||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on February 17, 2018._
|
||||
|
||||
<hr class="footnotes-sep">
|
||||
<section class="footnotes">
|
||||
<ol class="footnotes-list">
|
||||
<li id="fn1" class="footnote-item">this is the largest safe integer allowed in JavaScript. <a href="#fnref1" class="footnote-backref">↩</a>
|
||||
|
||||
</li>
|
||||
</ol>
|
||||
</section>
|
||||
376
node_modules/braces/index.js
generated
vendored
376
node_modules/braces/index.js
generated
vendored
@@ -1,17 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
const stringify = require('./lib/stringify');
|
||||
const compile = require('./lib/compile');
|
||||
const expand = require('./lib/expand');
|
||||
const parse = require('./lib/parse');
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
var toRegex = require('to-regex');
|
||||
var unique = require('array-unique');
|
||||
var extend = require('extend-shallow');
|
||||
|
||||
/**
|
||||
* Expand the given pattern or create a regex-compatible string.
|
||||
* Local dependencies
|
||||
*/
|
||||
|
||||
var compilers = require('./lib/compilers');
|
||||
var parsers = require('./lib/parsers');
|
||||
var Braces = require('./lib/braces');
|
||||
var utils = require('./lib/utils');
|
||||
var MAX_LENGTH = 1024 * 64;
|
||||
var cache = {};
|
||||
|
||||
/**
|
||||
* Convert the given `braces` pattern into a regex-compatible string. By default, only one string is generated for every input string. Set `options.expand` to true to return an array of patterns (similar to Bash or minimatch. Before using `options.expand`, it's recommended that you read the [performance notes](#performance)).
|
||||
*
|
||||
* ```js
|
||||
* const braces = require('braces');
|
||||
* console.log(braces('{a,b,c}', { compile: true })); //=> ['(a|b|c)']
|
||||
* console.log(braces('{a,b,c}')); //=> ['a', 'b', 'c']
|
||||
* var braces = require('braces');
|
||||
* console.log(braces('{a,b,c}'));
|
||||
* //=> ['(a|b|c)']
|
||||
*
|
||||
* console.log(braces('{a,b,c}', {expand: true}));
|
||||
* //=> ['a', 'b', 'c']
|
||||
* ```
|
||||
* @param {String} `str`
|
||||
* @param {Object} `options`
|
||||
@@ -19,95 +36,38 @@ const parse = require('./lib/parse');
|
||||
* @api public
|
||||
*/
|
||||
|
||||
const braces = (input, options = {}) => {
|
||||
let output = [];
|
||||
function braces(pattern, options) {
|
||||
var key = utils.createKey(String(pattern), options);
|
||||
var arr = [];
|
||||
|
||||
if (Array.isArray(input)) {
|
||||
for (let pattern of input) {
|
||||
let result = braces.create(pattern, options);
|
||||
if (Array.isArray(result)) {
|
||||
output.push(...result);
|
||||
} else {
|
||||
output.push(result);
|
||||
}
|
||||
var disabled = options && options.cache === false;
|
||||
if (!disabled && cache.hasOwnProperty(key)) {
|
||||
return cache[key];
|
||||
}
|
||||
|
||||
if (Array.isArray(pattern)) {
|
||||
for (var i = 0; i < pattern.length; i++) {
|
||||
arr.push.apply(arr, braces.create(pattern[i], options));
|
||||
}
|
||||
} else {
|
||||
output = [].concat(braces.create(input, options));
|
||||
arr = braces.create(pattern, options);
|
||||
}
|
||||
|
||||
if (options && options.expand === true && options.nodupes === true) {
|
||||
output = [...new Set(output)];
|
||||
if (options && options.nodupes === true) {
|
||||
arr = unique(arr);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the given `str` with the given `options`.
|
||||
*
|
||||
* ```js
|
||||
* // braces.parse(pattern, [, options]);
|
||||
* const ast = braces.parse('a/{b,c}/d');
|
||||
* console.log(ast);
|
||||
* ```
|
||||
* @param {String} pattern Brace pattern to parse
|
||||
* @param {Object} options
|
||||
* @return {Object} Returns an AST
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.parse = (input, options = {}) => parse(input, options);
|
||||
|
||||
/**
|
||||
* Creates a braces string from an AST, or an AST node.
|
||||
*
|
||||
* ```js
|
||||
* const braces = require('braces');
|
||||
* let ast = braces.parse('foo/{a,b}/bar');
|
||||
* console.log(stringify(ast.nodes[2])); //=> '{a,b}'
|
||||
* ```
|
||||
* @param {String} `input` Brace pattern or AST.
|
||||
* @param {Object} `options`
|
||||
* @return {Array} Returns an array of expanded values.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.stringify = (input, options = {}) => {
|
||||
if (typeof input === 'string') {
|
||||
return stringify(braces.parse(input, options), options);
|
||||
if (!disabled) {
|
||||
cache[key] = arr;
|
||||
}
|
||||
return stringify(input, options);
|
||||
};
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles a brace pattern into a regex-compatible, optimized string.
|
||||
* This method is called by the main [braces](#braces) function by default.
|
||||
* Expands a brace pattern into an array. This method is called by the main [braces](#braces) function when `options.expand` is true. Before using this method it's recommended that you read the [performance notes](#performance)) and advantages of using [.optimize](#optimize) instead.
|
||||
*
|
||||
* ```js
|
||||
* const braces = require('braces');
|
||||
* console.log(braces.compile('a/{b,c}/d'));
|
||||
* //=> ['a/(b|c)/d']
|
||||
* ```
|
||||
* @param {String} `input` Brace pattern or AST.
|
||||
* @param {Object} `options`
|
||||
* @return {Array} Returns an array of expanded values.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.compile = (input, options = {}) => {
|
||||
if (typeof input === 'string') {
|
||||
input = braces.parse(input, options);
|
||||
}
|
||||
return compile(input, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Expands a brace pattern into an array. This method is called by the
|
||||
* main [braces](#braces) function when `options.expand` is true. Before
|
||||
* using this method it's recommended that you read the [performance notes](#performance))
|
||||
* and advantages of using [.compile](#compile) instead.
|
||||
*
|
||||
* ```js
|
||||
* const braces = require('braces');
|
||||
* var braces = require('braces');
|
||||
* console.log(braces.expand('a/{b,c}/d'));
|
||||
* //=> ['a/b/d', 'a/c/d'];
|
||||
* ```
|
||||
@@ -117,33 +77,33 @@ braces.compile = (input, options = {}) => {
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.expand = (input, options = {}) => {
|
||||
if (typeof input === 'string') {
|
||||
input = braces.parse(input, options);
|
||||
}
|
||||
|
||||
let result = expand(input, options);
|
||||
|
||||
// filter out empty strings if specified
|
||||
if (options.noempty === true) {
|
||||
result = result.filter(Boolean);
|
||||
}
|
||||
|
||||
// filter out duplicates if specified
|
||||
if (options.nodupes === true) {
|
||||
result = [...new Set(result)];
|
||||
}
|
||||
|
||||
return result;
|
||||
braces.expand = function(pattern, options) {
|
||||
return braces.create(pattern, extend({}, options, {expand: true}));
|
||||
};
|
||||
|
||||
/**
|
||||
* Processes a brace pattern and returns either an expanded array
|
||||
* (if `options.expand` is true), a highly optimized regex-compatible string.
|
||||
* This method is called by the main [braces](#braces) function.
|
||||
* Expands a brace pattern into a regex-compatible, optimized string. This method is called by the main [braces](#braces) function by default.
|
||||
*
|
||||
* ```js
|
||||
* const braces = require('braces');
|
||||
* var braces = require('braces');
|
||||
* console.log(braces.expand('a/{b,c}/d'));
|
||||
* //=> ['a/(b|c)/d']
|
||||
* ```
|
||||
* @param {String} `pattern` Brace pattern
|
||||
* @param {Object} `options`
|
||||
* @return {Array} Returns an array of expanded values.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.optimize = function(pattern, options) {
|
||||
return braces.create(pattern, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Processes a brace pattern and returns either an expanded array (if `options.expand` is true), a highly optimized regex-compatible string. This method is called by the main [braces](#braces) function.
|
||||
*
|
||||
* ```js
|
||||
* var braces = require('braces');
|
||||
* console.log(braces.create('user-{200..300}/project-{a,b,c}-{1..10}'))
|
||||
* //=> 'user-(20[0-9]|2[1-9][0-9]|300)/project-(a|b|c)-([1-9]|10)'
|
||||
* ```
|
||||
@@ -153,18 +113,206 @@ braces.expand = (input, options = {}) => {
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.create = (input, options = {}) => {
|
||||
if (input === '' || input.length < 3) {
|
||||
return [input];
|
||||
braces.create = function(pattern, options) {
|
||||
if (typeof pattern !== 'string') {
|
||||
throw new TypeError('expected a string');
|
||||
}
|
||||
|
||||
return options.expand !== true
|
||||
? braces.compile(input, options)
|
||||
: braces.expand(input, options);
|
||||
var maxLength = (options && options.maxLength) || MAX_LENGTH;
|
||||
if (pattern.length >= maxLength) {
|
||||
throw new Error('expected pattern to be less than ' + maxLength + ' characters');
|
||||
}
|
||||
|
||||
function create() {
|
||||
if (pattern === '' || pattern.length < 3) {
|
||||
return [pattern];
|
||||
}
|
||||
|
||||
if (utils.isEmptySets(pattern)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (utils.isQuotedString(pattern)) {
|
||||
return [pattern.slice(1, -1)];
|
||||
}
|
||||
|
||||
var proto = new Braces(options);
|
||||
var result = !options || options.expand !== true
|
||||
? proto.optimize(pattern, options)
|
||||
: proto.expand(pattern, options);
|
||||
|
||||
// get the generated pattern(s)
|
||||
var arr = result.output;
|
||||
|
||||
// filter out empty strings if specified
|
||||
if (options && options.noempty === true) {
|
||||
arr = arr.filter(Boolean);
|
||||
}
|
||||
|
||||
// filter out duplicates if specified
|
||||
if (options && options.nodupes === true) {
|
||||
arr = unique(arr);
|
||||
}
|
||||
|
||||
Object.defineProperty(arr, 'result', {
|
||||
enumerable: false,
|
||||
value: result
|
||||
});
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
return memoize('create', pattern, options, create);
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose "braces"
|
||||
* Create a regular expression from the given string `pattern`.
|
||||
*
|
||||
* ```js
|
||||
* var braces = require('braces');
|
||||
*
|
||||
* console.log(braces.makeRe('id-{200..300}'));
|
||||
* //=> /^(?:id-(20[0-9]|2[1-9][0-9]|300))$/
|
||||
* ```
|
||||
* @param {String} `pattern` The pattern to convert to regex.
|
||||
* @param {Object} `options`
|
||||
* @return {RegExp}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.makeRe = function(pattern, options) {
|
||||
if (typeof pattern !== 'string') {
|
||||
throw new TypeError('expected a string');
|
||||
}
|
||||
|
||||
var maxLength = (options && options.maxLength) || MAX_LENGTH;
|
||||
if (pattern.length >= maxLength) {
|
||||
throw new Error('expected pattern to be less than ' + maxLength + ' characters');
|
||||
}
|
||||
|
||||
function makeRe() {
|
||||
var arr = braces(pattern, options);
|
||||
var opts = extend({strictErrors: false}, options);
|
||||
return toRegex(arr, opts);
|
||||
}
|
||||
|
||||
return memoize('makeRe', pattern, options, makeRe);
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the given `str` with the given `options`.
|
||||
*
|
||||
* ```js
|
||||
* var braces = require('braces');
|
||||
* var ast = braces.parse('a/{b,c}/d');
|
||||
* console.log(ast);
|
||||
* // { type: 'root',
|
||||
* // errors: [],
|
||||
* // input: 'a/{b,c}/d',
|
||||
* // nodes:
|
||||
* // [ { type: 'bos', val: '' },
|
||||
* // { type: 'text', val: 'a/' },
|
||||
* // { type: 'brace',
|
||||
* // nodes:
|
||||
* // [ { type: 'brace.open', val: '{' },
|
||||
* // { type: 'text', val: 'b,c' },
|
||||
* // { type: 'brace.close', val: '}' } ] },
|
||||
* // { type: 'text', val: '/d' },
|
||||
* // { type: 'eos', val: '' } ] }
|
||||
* ```
|
||||
* @param {String} `pattern` Brace pattern to parse
|
||||
* @param {Object} `options`
|
||||
* @return {Object} Returns an AST
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.parse = function(pattern, options) {
|
||||
var proto = new Braces(options);
|
||||
return proto.parse(pattern, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Compile the given `ast` or string with the given `options`.
|
||||
*
|
||||
* ```js
|
||||
* var braces = require('braces');
|
||||
* var ast = braces.parse('a/{b,c}/d');
|
||||
* console.log(braces.compile(ast));
|
||||
* // { options: { source: 'string' },
|
||||
* // state: {},
|
||||
* // compilers:
|
||||
* // { eos: [Function],
|
||||
* // noop: [Function],
|
||||
* // bos: [Function],
|
||||
* // brace: [Function],
|
||||
* // 'brace.open': [Function],
|
||||
* // text: [Function],
|
||||
* // 'brace.close': [Function] },
|
||||
* // output: [ 'a/(b|c)/d' ],
|
||||
* // ast:
|
||||
* // { ... },
|
||||
* // parsingErrors: [] }
|
||||
* ```
|
||||
* @param {Object|String} `ast` AST from [.parse](#parse). If a string is passed it will be parsed first.
|
||||
* @param {Object} `options`
|
||||
* @return {Object} Returns an object that has an `output` property with the compiled string.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.compile = function(ast, options) {
|
||||
var proto = new Braces(options);
|
||||
return proto.compile(ast, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear the regex cache.
|
||||
*
|
||||
* ```js
|
||||
* braces.clearCache();
|
||||
* ```
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.clearCache = function() {
|
||||
cache = braces.cache = {};
|
||||
};
|
||||
|
||||
/**
|
||||
* Memoize a generated regex or function. A unique key is generated
|
||||
* from the method name, pattern, and user-defined options. Set
|
||||
* options.memoize to false to disable.
|
||||
*/
|
||||
|
||||
function memoize(type, pattern, options, fn) {
|
||||
var key = utils.createKey(type + ':' + pattern, options);
|
||||
var disabled = options && options.cache === false;
|
||||
if (disabled) {
|
||||
braces.clearCache();
|
||||
return fn(pattern, options);
|
||||
}
|
||||
|
||||
if (cache.hasOwnProperty(key)) {
|
||||
return cache[key];
|
||||
}
|
||||
|
||||
var res = fn(pattern, options);
|
||||
cache[key] = res;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose `Braces` constructor and methods
|
||||
* @type {Function}
|
||||
*/
|
||||
|
||||
braces.Braces = Braces;
|
||||
braces.compilers = compilers;
|
||||
braces.parsers = parsers;
|
||||
braces.cache = cache;
|
||||
|
||||
/**
|
||||
* Expose `braces`
|
||||
* @type {Function}
|
||||
*/
|
||||
|
||||
module.exports = braces;
|
||||
|
||||
104
node_modules/braces/lib/braces.js
generated
vendored
Normal file
104
node_modules/braces/lib/braces.js
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
'use strict';
|
||||
|
||||
var extend = require('extend-shallow');
|
||||
var Snapdragon = require('snapdragon');
|
||||
var compilers = require('./compilers');
|
||||
var parsers = require('./parsers');
|
||||
var utils = require('./utils');
|
||||
|
||||
/**
|
||||
* Customize Snapdragon parser and renderer
|
||||
*/
|
||||
|
||||
function Braces(options) {
|
||||
this.options = extend({}, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize braces
|
||||
*/
|
||||
|
||||
Braces.prototype.init = function(options) {
|
||||
if (this.isInitialized) return;
|
||||
this.isInitialized = true;
|
||||
var opts = utils.createOptions({}, this.options, options);
|
||||
this.snapdragon = this.options.snapdragon || new Snapdragon(opts);
|
||||
this.compiler = this.snapdragon.compiler;
|
||||
this.parser = this.snapdragon.parser;
|
||||
|
||||
compilers(this.snapdragon, opts);
|
||||
parsers(this.snapdragon, opts);
|
||||
|
||||
/**
|
||||
* Call Snapdragon `.parse` method. When AST is returned, we check to
|
||||
* see if any unclosed braces are left on the stack and, if so, we iterate
|
||||
* over the stack and correct the AST so that compilers are called in the correct
|
||||
* order and unbalance braces are properly escaped.
|
||||
*/
|
||||
|
||||
utils.define(this.snapdragon, 'parse', function(pattern, options) {
|
||||
var parsed = Snapdragon.prototype.parse.apply(this, arguments);
|
||||
this.parser.ast.input = pattern;
|
||||
|
||||
var stack = this.parser.stack;
|
||||
while (stack.length) {
|
||||
addParent({type: 'brace.close', val: ''}, stack.pop());
|
||||
}
|
||||
|
||||
function addParent(node, parent) {
|
||||
utils.define(node, 'parent', parent);
|
||||
parent.nodes.push(node);
|
||||
}
|
||||
|
||||
// add non-enumerable parser reference
|
||||
utils.define(parsed, 'parser', this.parser);
|
||||
return parsed;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Decorate `.parse` method
|
||||
*/
|
||||
|
||||
Braces.prototype.parse = function(ast, options) {
|
||||
if (ast && typeof ast === 'object' && ast.nodes) return ast;
|
||||
this.init(options);
|
||||
return this.snapdragon.parse(ast, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Decorate `.compile` method
|
||||
*/
|
||||
|
||||
Braces.prototype.compile = function(ast, options) {
|
||||
if (typeof ast === 'string') {
|
||||
ast = this.parse(ast, options);
|
||||
} else {
|
||||
this.init(options);
|
||||
}
|
||||
return this.snapdragon.compile(ast, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Expand
|
||||
*/
|
||||
|
||||
Braces.prototype.expand = function(pattern) {
|
||||
var ast = this.parse(pattern, {expand: true});
|
||||
return this.compile(ast, {expand: true});
|
||||
};
|
||||
|
||||
/**
|
||||
* Optimize
|
||||
*/
|
||||
|
||||
Braces.prototype.optimize = function(pattern) {
|
||||
var ast = this.parse(pattern, {optimize: true});
|
||||
return this.compile(ast, {optimize: true});
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose `Braces`
|
||||
*/
|
||||
|
||||
module.exports = Braces;
|
||||
57
node_modules/braces/lib/compile.js
generated
vendored
57
node_modules/braces/lib/compile.js
generated
vendored
@@ -1,57 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const fill = require('fill-range');
|
||||
const utils = require('./utils');
|
||||
|
||||
const compile = (ast, options = {}) => {
|
||||
let walk = (node, parent = {}) => {
|
||||
let invalidBlock = utils.isInvalidBrace(parent);
|
||||
let invalidNode = node.invalid === true && options.escapeInvalid === true;
|
||||
let invalid = invalidBlock === true || invalidNode === true;
|
||||
let prefix = options.escapeInvalid === true ? '\\' : '';
|
||||
let output = '';
|
||||
|
||||
if (node.isOpen === true) {
|
||||
return prefix + node.value;
|
||||
}
|
||||
if (node.isClose === true) {
|
||||
return prefix + node.value;
|
||||
}
|
||||
|
||||
if (node.type === 'open') {
|
||||
return invalid ? (prefix + node.value) : '(';
|
||||
}
|
||||
|
||||
if (node.type === 'close') {
|
||||
return invalid ? (prefix + node.value) : ')';
|
||||
}
|
||||
|
||||
if (node.type === 'comma') {
|
||||
return node.prev.type === 'comma' ? '' : (invalid ? node.value : '|');
|
||||
}
|
||||
|
||||
if (node.value) {
|
||||
return node.value;
|
||||
}
|
||||
|
||||
if (node.nodes && node.ranges > 0) {
|
||||
let args = utils.reduce(node.nodes);
|
||||
let range = fill(...args, { ...options, wrap: false, toRegex: true });
|
||||
|
||||
if (range.length !== 0) {
|
||||
return args.length > 1 && range.length > 1 ? `(${range})` : range;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.nodes) {
|
||||
for (let child of node.nodes) {
|
||||
output += walk(child, node);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
return walk(ast);
|
||||
};
|
||||
|
||||
module.exports = compile;
|
||||
282
node_modules/braces/lib/compilers.js
generated
vendored
Normal file
282
node_modules/braces/lib/compilers.js
generated
vendored
Normal file
@@ -0,0 +1,282 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('./utils');
|
||||
|
||||
module.exports = function(braces, options) {
|
||||
braces.compiler
|
||||
|
||||
/**
|
||||
* bos
|
||||
*/
|
||||
|
||||
.set('bos', function() {
|
||||
if (this.output) return;
|
||||
this.ast.queue = isEscaped(this.ast) ? [this.ast.val] : [];
|
||||
this.ast.count = 1;
|
||||
})
|
||||
|
||||
/**
|
||||
* Square brackets
|
||||
*/
|
||||
|
||||
.set('bracket', function(node) {
|
||||
var close = node.close;
|
||||
var open = !node.escaped ? '[' : '\\[';
|
||||
var negated = node.negated;
|
||||
var inner = node.inner;
|
||||
|
||||
inner = inner.replace(/\\(?=[\\\w]|$)/g, '\\\\');
|
||||
if (inner === ']-') {
|
||||
inner = '\\]\\-';
|
||||
}
|
||||
|
||||
if (negated && inner.indexOf('.') === -1) {
|
||||
inner += '.';
|
||||
}
|
||||
if (negated && inner.indexOf('/') === -1) {
|
||||
inner += '/';
|
||||
}
|
||||
|
||||
var val = open + negated + inner + close;
|
||||
var queue = node.parent.queue;
|
||||
var last = utils.arrayify(queue.pop());
|
||||
|
||||
queue.push(utils.join(last, val));
|
||||
queue.push.apply(queue, []);
|
||||
})
|
||||
|
||||
/**
|
||||
* Brace
|
||||
*/
|
||||
|
||||
.set('brace', function(node) {
|
||||
node.queue = isEscaped(node) ? [node.val] : [];
|
||||
node.count = 1;
|
||||
return this.mapVisit(node.nodes);
|
||||
})
|
||||
|
||||
/**
|
||||
* Open
|
||||
*/
|
||||
|
||||
.set('brace.open', function(node) {
|
||||
node.parent.open = node.val;
|
||||
})
|
||||
|
||||
/**
|
||||
* Inner
|
||||
*/
|
||||
|
||||
.set('text', function(node) {
|
||||
var queue = node.parent.queue;
|
||||
var escaped = node.escaped;
|
||||
var segs = [node.val];
|
||||
|
||||
if (node.optimize === false) {
|
||||
options = utils.extend({}, options, {optimize: false});
|
||||
}
|
||||
|
||||
if (node.multiplier > 1) {
|
||||
node.parent.count *= node.multiplier;
|
||||
}
|
||||
|
||||
if (options.quantifiers === true && utils.isQuantifier(node.val)) {
|
||||
escaped = true;
|
||||
|
||||
} else if (node.val.length > 1) {
|
||||
if (isType(node.parent, 'brace') && !isEscaped(node)) {
|
||||
var expanded = utils.expand(node.val, options);
|
||||
segs = expanded.segs;
|
||||
|
||||
if (expanded.isOptimized) {
|
||||
node.parent.isOptimized = true;
|
||||
}
|
||||
|
||||
// if nothing was expanded, we probably have a literal brace
|
||||
if (!segs.length) {
|
||||
var val = (expanded.val || node.val);
|
||||
if (options.unescape !== false) {
|
||||
// unescape unexpanded brace sequence/set separators
|
||||
val = val.replace(/\\([,.])/g, '$1');
|
||||
// strip quotes
|
||||
val = val.replace(/["'`]/g, '');
|
||||
}
|
||||
|
||||
segs = [val];
|
||||
escaped = true;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (node.val === ',') {
|
||||
if (options.expand) {
|
||||
node.parent.queue.push(['']);
|
||||
segs = [''];
|
||||
} else {
|
||||
segs = ['|'];
|
||||
}
|
||||
} else {
|
||||
escaped = true;
|
||||
}
|
||||
|
||||
if (escaped && isType(node.parent, 'brace')) {
|
||||
if (node.parent.nodes.length <= 4 && node.parent.count === 1) {
|
||||
node.parent.escaped = true;
|
||||
} else if (node.parent.length <= 3) {
|
||||
node.parent.escaped = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasQueue(node.parent)) {
|
||||
node.parent.queue = segs;
|
||||
return;
|
||||
}
|
||||
|
||||
var last = utils.arrayify(queue.pop());
|
||||
if (node.parent.count > 1 && options.expand) {
|
||||
last = multiply(last, node.parent.count);
|
||||
node.parent.count = 1;
|
||||
}
|
||||
|
||||
queue.push(utils.join(utils.flatten(last), segs.shift()));
|
||||
queue.push.apply(queue, segs);
|
||||
})
|
||||
|
||||
/**
|
||||
* Close
|
||||
*/
|
||||
|
||||
.set('brace.close', function(node) {
|
||||
var queue = node.parent.queue;
|
||||
var prev = node.parent.parent;
|
||||
var last = prev.queue.pop();
|
||||
var open = node.parent.open;
|
||||
var close = node.val;
|
||||
|
||||
if (open && close && isOptimized(node, options)) {
|
||||
open = '(';
|
||||
close = ')';
|
||||
}
|
||||
|
||||
// if a close brace exists, and the previous segment is one character
|
||||
// don't wrap the result in braces or parens
|
||||
var ele = utils.last(queue);
|
||||
if (node.parent.count > 1 && options.expand) {
|
||||
ele = multiply(queue.pop(), node.parent.count);
|
||||
node.parent.count = 1;
|
||||
queue.push(ele);
|
||||
}
|
||||
|
||||
if (close && typeof ele === 'string' && ele.length === 1) {
|
||||
open = '';
|
||||
close = '';
|
||||
}
|
||||
|
||||
if ((isLiteralBrace(node, options) || noInner(node)) && !node.parent.hasEmpty) {
|
||||
queue.push(utils.join(open, queue.pop() || ''));
|
||||
queue = utils.flatten(utils.join(queue, close));
|
||||
}
|
||||
|
||||
if (typeof last === 'undefined') {
|
||||
prev.queue = [queue];
|
||||
} else {
|
||||
prev.queue.push(utils.flatten(utils.join(last, queue)));
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* eos
|
||||
*/
|
||||
|
||||
.set('eos', function(node) {
|
||||
if (this.input) return;
|
||||
|
||||
if (options.optimize !== false) {
|
||||
this.output = utils.last(utils.flatten(this.ast.queue));
|
||||
} else if (Array.isArray(utils.last(this.ast.queue))) {
|
||||
this.output = utils.flatten(this.ast.queue.pop());
|
||||
} else {
|
||||
this.output = utils.flatten(this.ast.queue);
|
||||
}
|
||||
|
||||
if (node.parent.count > 1 && options.expand) {
|
||||
this.output = multiply(this.output, node.parent.count);
|
||||
}
|
||||
|
||||
this.output = utils.arrayify(this.output);
|
||||
this.ast.queue = [];
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Multiply the segments in the current brace level
|
||||
*/
|
||||
|
||||
function multiply(queue, n, options) {
|
||||
return utils.flatten(utils.repeat(utils.arrayify(queue), n));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if `node` is escaped
|
||||
*/
|
||||
|
||||
function isEscaped(node) {
|
||||
return node.escaped === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if regex parens should be used for sets. If the parent `type`
|
||||
* is not `brace`, then we're on a root node, which means we should never
|
||||
* expand segments and open/close braces should be `{}` (since this indicates
|
||||
* a brace is missing from the set)
|
||||
*/
|
||||
|
||||
function isOptimized(node, options) {
|
||||
if (node.parent.isOptimized) return true;
|
||||
return isType(node.parent, 'brace')
|
||||
&& !isEscaped(node.parent)
|
||||
&& options.expand !== true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the value in `node` should be wrapped in a literal brace.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
function isLiteralBrace(node, options) {
|
||||
return isEscaped(node.parent) || options.optimize !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given `node` does not have an inner value.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
function noInner(node, type) {
|
||||
if (node.parent.queue.length === 1) {
|
||||
return true;
|
||||
}
|
||||
var nodes = node.parent.nodes;
|
||||
return nodes.length === 3
|
||||
&& isType(nodes[0], 'brace.open')
|
||||
&& !isType(nodes[1], 'text')
|
||||
&& isType(nodes[2], 'brace.close');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given `node` is the given `type`
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
function isType(node, type) {
|
||||
return typeof node !== 'undefined' && node.type === type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given `node` has a non-empty queue.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
function hasQueue(node) {
|
||||
return Array.isArray(node.queue) && node.queue.length;
|
||||
}
|
||||
57
node_modules/braces/lib/constants.js
generated
vendored
57
node_modules/braces/lib/constants.js
generated
vendored
@@ -1,57 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
MAX_LENGTH: 1024 * 64,
|
||||
|
||||
// Digits
|
||||
CHAR_0: '0', /* 0 */
|
||||
CHAR_9: '9', /* 9 */
|
||||
|
||||
// Alphabet chars.
|
||||
CHAR_UPPERCASE_A: 'A', /* A */
|
||||
CHAR_LOWERCASE_A: 'a', /* a */
|
||||
CHAR_UPPERCASE_Z: 'Z', /* Z */
|
||||
CHAR_LOWERCASE_Z: 'z', /* z */
|
||||
|
||||
CHAR_LEFT_PARENTHESES: '(', /* ( */
|
||||
CHAR_RIGHT_PARENTHESES: ')', /* ) */
|
||||
|
||||
CHAR_ASTERISK: '*', /* * */
|
||||
|
||||
// Non-alphabetic chars.
|
||||
CHAR_AMPERSAND: '&', /* & */
|
||||
CHAR_AT: '@', /* @ */
|
||||
CHAR_BACKSLASH: '\\', /* \ */
|
||||
CHAR_BACKTICK: '`', /* ` */
|
||||
CHAR_CARRIAGE_RETURN: '\r', /* \r */
|
||||
CHAR_CIRCUMFLEX_ACCENT: '^', /* ^ */
|
||||
CHAR_COLON: ':', /* : */
|
||||
CHAR_COMMA: ',', /* , */
|
||||
CHAR_DOLLAR: '$', /* . */
|
||||
CHAR_DOT: '.', /* . */
|
||||
CHAR_DOUBLE_QUOTE: '"', /* " */
|
||||
CHAR_EQUAL: '=', /* = */
|
||||
CHAR_EXCLAMATION_MARK: '!', /* ! */
|
||||
CHAR_FORM_FEED: '\f', /* \f */
|
||||
CHAR_FORWARD_SLASH: '/', /* / */
|
||||
CHAR_HASH: '#', /* # */
|
||||
CHAR_HYPHEN_MINUS: '-', /* - */
|
||||
CHAR_LEFT_ANGLE_BRACKET: '<', /* < */
|
||||
CHAR_LEFT_CURLY_BRACE: '{', /* { */
|
||||
CHAR_LEFT_SQUARE_BRACKET: '[', /* [ */
|
||||
CHAR_LINE_FEED: '\n', /* \n */
|
||||
CHAR_NO_BREAK_SPACE: '\u00A0', /* \u00A0 */
|
||||
CHAR_PERCENT: '%', /* % */
|
||||
CHAR_PLUS: '+', /* + */
|
||||
CHAR_QUESTION_MARK: '?', /* ? */
|
||||
CHAR_RIGHT_ANGLE_BRACKET: '>', /* > */
|
||||
CHAR_RIGHT_CURLY_BRACE: '}', /* } */
|
||||
CHAR_RIGHT_SQUARE_BRACKET: ']', /* ] */
|
||||
CHAR_SEMICOLON: ';', /* ; */
|
||||
CHAR_SINGLE_QUOTE: '\'', /* ' */
|
||||
CHAR_SPACE: ' ', /* */
|
||||
CHAR_TAB: '\t', /* \t */
|
||||
CHAR_UNDERSCORE: '_', /* _ */
|
||||
CHAR_VERTICAL_LINE: '|', /* | */
|
||||
CHAR_ZERO_WIDTH_NOBREAK_SPACE: '\uFEFF' /* \uFEFF */
|
||||
};
|
||||
113
node_modules/braces/lib/expand.js
generated
vendored
113
node_modules/braces/lib/expand.js
generated
vendored
@@ -1,113 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const fill = require('fill-range');
|
||||
const stringify = require('./stringify');
|
||||
const utils = require('./utils');
|
||||
|
||||
const append = (queue = '', stash = '', enclose = false) => {
|
||||
let result = [];
|
||||
|
||||
queue = [].concat(queue);
|
||||
stash = [].concat(stash);
|
||||
|
||||
if (!stash.length) return queue;
|
||||
if (!queue.length) {
|
||||
return enclose ? utils.flatten(stash).map(ele => `{${ele}}`) : stash;
|
||||
}
|
||||
|
||||
for (let item of queue) {
|
||||
if (Array.isArray(item)) {
|
||||
for (let value of item) {
|
||||
result.push(append(value, stash, enclose));
|
||||
}
|
||||
} else {
|
||||
for (let ele of stash) {
|
||||
if (enclose === true && typeof ele === 'string') ele = `{${ele}}`;
|
||||
result.push(Array.isArray(ele) ? append(item, ele, enclose) : (item + ele));
|
||||
}
|
||||
}
|
||||
}
|
||||
return utils.flatten(result);
|
||||
};
|
||||
|
||||
const expand = (ast, options = {}) => {
|
||||
let rangeLimit = options.rangeLimit === void 0 ? 1000 : options.rangeLimit;
|
||||
|
||||
let walk = (node, parent = {}) => {
|
||||
node.queue = [];
|
||||
|
||||
let p = parent;
|
||||
let q = parent.queue;
|
||||
|
||||
while (p.type !== 'brace' && p.type !== 'root' && p.parent) {
|
||||
p = p.parent;
|
||||
q = p.queue;
|
||||
}
|
||||
|
||||
if (node.invalid || node.dollar) {
|
||||
q.push(append(q.pop(), stringify(node, options)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.type === 'brace' && node.invalid !== true && node.nodes.length === 2) {
|
||||
q.push(append(q.pop(), ['{}']));
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.nodes && node.ranges > 0) {
|
||||
let args = utils.reduce(node.nodes);
|
||||
|
||||
if (utils.exceedsLimit(...args, options.step, rangeLimit)) {
|
||||
throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
|
||||
}
|
||||
|
||||
let range = fill(...args, options);
|
||||
if (range.length === 0) {
|
||||
range = stringify(node, options);
|
||||
}
|
||||
|
||||
q.push(append(q.pop(), range));
|
||||
node.nodes = [];
|
||||
return;
|
||||
}
|
||||
|
||||
let enclose = utils.encloseBrace(node);
|
||||
let queue = node.queue;
|
||||
let block = node;
|
||||
|
||||
while (block.type !== 'brace' && block.type !== 'root' && block.parent) {
|
||||
block = block.parent;
|
||||
queue = block.queue;
|
||||
}
|
||||
|
||||
for (let i = 0; i < node.nodes.length; i++) {
|
||||
let child = node.nodes[i];
|
||||
|
||||
if (child.type === 'comma' && node.type === 'brace') {
|
||||
if (i === 1) queue.push('');
|
||||
queue.push('');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (child.type === 'close') {
|
||||
q.push(append(q.pop(), queue, enclose));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (child.value && child.type !== 'open') {
|
||||
queue.push(append(queue.pop(), child.value));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (child.nodes) {
|
||||
walk(child, node);
|
||||
}
|
||||
}
|
||||
|
||||
return queue;
|
||||
};
|
||||
|
||||
return utils.flatten(walk(ast));
|
||||
};
|
||||
|
||||
module.exports = expand;
|
||||
333
node_modules/braces/lib/parse.js
generated
vendored
333
node_modules/braces/lib/parse.js
generated
vendored
@@ -1,333 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const stringify = require('./stringify');
|
||||
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
|
||||
const {
|
||||
MAX_LENGTH,
|
||||
CHAR_BACKSLASH, /* \ */
|
||||
CHAR_BACKTICK, /* ` */
|
||||
CHAR_COMMA, /* , */
|
||||
CHAR_DOT, /* . */
|
||||
CHAR_LEFT_PARENTHESES, /* ( */
|
||||
CHAR_RIGHT_PARENTHESES, /* ) */
|
||||
CHAR_LEFT_CURLY_BRACE, /* { */
|
||||
CHAR_RIGHT_CURLY_BRACE, /* } */
|
||||
CHAR_LEFT_SQUARE_BRACKET, /* [ */
|
||||
CHAR_RIGHT_SQUARE_BRACKET, /* ] */
|
||||
CHAR_DOUBLE_QUOTE, /* " */
|
||||
CHAR_SINGLE_QUOTE, /* ' */
|
||||
CHAR_NO_BREAK_SPACE,
|
||||
CHAR_ZERO_WIDTH_NOBREAK_SPACE
|
||||
} = require('./constants');
|
||||
|
||||
/**
|
||||
* parse
|
||||
*/
|
||||
|
||||
const parse = (input, options = {}) => {
|
||||
if (typeof input !== 'string') {
|
||||
throw new TypeError('Expected a string');
|
||||
}
|
||||
|
||||
let opts = options || {};
|
||||
let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
||||
if (input.length > max) {
|
||||
throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
|
||||
}
|
||||
|
||||
let ast = { type: 'root', input, nodes: [] };
|
||||
let stack = [ast];
|
||||
let block = ast;
|
||||
let prev = ast;
|
||||
let brackets = 0;
|
||||
let length = input.length;
|
||||
let index = 0;
|
||||
let depth = 0;
|
||||
let value;
|
||||
let memo = {};
|
||||
|
||||
/**
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
const advance = () => input[index++];
|
||||
const push = node => {
|
||||
if (node.type === 'text' && prev.type === 'dot') {
|
||||
prev.type = 'text';
|
||||
}
|
||||
|
||||
if (prev && prev.type === 'text' && node.type === 'text') {
|
||||
prev.value += node.value;
|
||||
return;
|
||||
}
|
||||
|
||||
block.nodes.push(node);
|
||||
node.parent = block;
|
||||
node.prev = prev;
|
||||
prev = node;
|
||||
return node;
|
||||
};
|
||||
|
||||
push({ type: 'bos' });
|
||||
|
||||
while (index < length) {
|
||||
block = stack[stack.length - 1];
|
||||
value = advance();
|
||||
|
||||
/**
|
||||
* Invalid chars
|
||||
*/
|
||||
|
||||
if (value === CHAR_ZERO_WIDTH_NOBREAK_SPACE || value === CHAR_NO_BREAK_SPACE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escaped chars
|
||||
*/
|
||||
|
||||
if (value === CHAR_BACKSLASH) {
|
||||
push({ type: 'text', value: (options.keepEscaping ? value : '') + advance() });
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Right square bracket (literal): ']'
|
||||
*/
|
||||
|
||||
if (value === CHAR_RIGHT_SQUARE_BRACKET) {
|
||||
push({ type: 'text', value: '\\' + value });
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Left square bracket: '['
|
||||
*/
|
||||
|
||||
if (value === CHAR_LEFT_SQUARE_BRACKET) {
|
||||
brackets++;
|
||||
|
||||
let closed = true;
|
||||
let next;
|
||||
|
||||
while (index < length && (next = advance())) {
|
||||
value += next;
|
||||
|
||||
if (next === CHAR_LEFT_SQUARE_BRACKET) {
|
||||
brackets++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (next === CHAR_BACKSLASH) {
|
||||
value += advance();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
||||
brackets--;
|
||||
|
||||
if (brackets === 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
push({ type: 'text', value });
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parentheses
|
||||
*/
|
||||
|
||||
if (value === CHAR_LEFT_PARENTHESES) {
|
||||
block = push({ type: 'paren', nodes: [] });
|
||||
stack.push(block);
|
||||
push({ type: 'text', value });
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value === CHAR_RIGHT_PARENTHESES) {
|
||||
if (block.type !== 'paren') {
|
||||
push({ type: 'text', value });
|
||||
continue;
|
||||
}
|
||||
block = stack.pop();
|
||||
push({ type: 'text', value });
|
||||
block = stack[stack.length - 1];
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Quotes: '|"|`
|
||||
*/
|
||||
|
||||
if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
|
||||
let open = value;
|
||||
let next;
|
||||
|
||||
if (options.keepQuotes !== true) {
|
||||
value = '';
|
||||
}
|
||||
|
||||
while (index < length && (next = advance())) {
|
||||
if (next === CHAR_BACKSLASH) {
|
||||
value += next + advance();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (next === open) {
|
||||
if (options.keepQuotes === true) value += next;
|
||||
break;
|
||||
}
|
||||
|
||||
value += next;
|
||||
}
|
||||
|
||||
push({ type: 'text', value });
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Left curly brace: '{'
|
||||
*/
|
||||
|
||||
if (value === CHAR_LEFT_CURLY_BRACE) {
|
||||
depth++;
|
||||
|
||||
let dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
|
||||
let brace = {
|
||||
type: 'brace',
|
||||
open: true,
|
||||
close: false,
|
||||
dollar,
|
||||
depth,
|
||||
commas: 0,
|
||||
ranges: 0,
|
||||
nodes: []
|
||||
};
|
||||
|
||||
block = push(brace);
|
||||
stack.push(block);
|
||||
push({ type: 'open', value });
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Right curly brace: '}'
|
||||
*/
|
||||
|
||||
if (value === CHAR_RIGHT_CURLY_BRACE) {
|
||||
if (block.type !== 'brace') {
|
||||
push({ type: 'text', value });
|
||||
continue;
|
||||
}
|
||||
|
||||
let type = 'close';
|
||||
block = stack.pop();
|
||||
block.close = true;
|
||||
|
||||
push({ type, value });
|
||||
depth--;
|
||||
|
||||
block = stack[stack.length - 1];
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Comma: ','
|
||||
*/
|
||||
|
||||
if (value === CHAR_COMMA && depth > 0) {
|
||||
if (block.ranges > 0) {
|
||||
block.ranges = 0;
|
||||
let open = block.nodes.shift();
|
||||
block.nodes = [open, { type: 'text', value: stringify(block) }];
|
||||
}
|
||||
|
||||
push({ type: 'comma', value });
|
||||
block.commas++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dot: '.'
|
||||
*/
|
||||
|
||||
if (value === CHAR_DOT && depth > 0 && block.commas === 0) {
|
||||
let siblings = block.nodes;
|
||||
|
||||
if (depth === 0 || siblings.length === 0) {
|
||||
push({ type: 'text', value });
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prev.type === 'dot') {
|
||||
block.range = [];
|
||||
prev.value += value;
|
||||
prev.type = 'range';
|
||||
|
||||
if (block.nodes.length !== 3 && block.nodes.length !== 5) {
|
||||
block.invalid = true;
|
||||
block.ranges = 0;
|
||||
prev.type = 'text';
|
||||
continue;
|
||||
}
|
||||
|
||||
block.ranges++;
|
||||
block.args = [];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prev.type === 'range') {
|
||||
siblings.pop();
|
||||
|
||||
let before = siblings[siblings.length - 1];
|
||||
before.value += prev.value + value;
|
||||
prev = before;
|
||||
block.ranges--;
|
||||
continue;
|
||||
}
|
||||
|
||||
push({ type: 'dot', value });
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Text
|
||||
*/
|
||||
|
||||
push({ type: 'text', value });
|
||||
}
|
||||
|
||||
// Mark imbalanced braces and brackets as invalid
|
||||
do {
|
||||
block = stack.pop();
|
||||
|
||||
if (block.type !== 'root') {
|
||||
block.nodes.forEach(node => {
|
||||
if (!node.nodes) {
|
||||
if (node.type === 'open') node.isOpen = true;
|
||||
if (node.type === 'close') node.isClose = true;
|
||||
if (!node.nodes) node.type = 'text';
|
||||
node.invalid = true;
|
||||
}
|
||||
});
|
||||
|
||||
// get the location of the block on parent.nodes (block's siblings)
|
||||
let parent = stack[stack.length - 1];
|
||||
let index = parent.nodes.indexOf(block);
|
||||
// replace the (invalid) block with it's nodes
|
||||
parent.nodes.splice(index, 1, ...block.nodes);
|
||||
}
|
||||
} while (stack.length > 0);
|
||||
|
||||
push({ type: 'eos' });
|
||||
return ast;
|
||||
};
|
||||
|
||||
module.exports = parse;
|
||||
360
node_modules/braces/lib/parsers.js
generated
vendored
Normal file
360
node_modules/braces/lib/parsers.js
generated
vendored
Normal file
@@ -0,0 +1,360 @@
|
||||
'use strict';
|
||||
|
||||
var Node = require('snapdragon-node');
|
||||
var utils = require('./utils');
|
||||
|
||||
/**
|
||||
* Braces parsers
|
||||
*/
|
||||
|
||||
module.exports = function(braces, options) {
|
||||
braces.parser
|
||||
.set('bos', function() {
|
||||
if (!this.parsed) {
|
||||
this.ast = this.nodes[0] = new Node(this.ast);
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Character parsers
|
||||
*/
|
||||
|
||||
.set('escape', function() {
|
||||
var pos = this.position();
|
||||
var m = this.match(/^(?:\\(.)|\$\{)/);
|
||||
if (!m) return;
|
||||
|
||||
var prev = this.prev();
|
||||
var last = utils.last(prev.nodes);
|
||||
|
||||
var node = pos(new Node({
|
||||
type: 'text',
|
||||
multiplier: 1,
|
||||
val: m[0]
|
||||
}));
|
||||
|
||||
if (node.val === '\\\\') {
|
||||
return node;
|
||||
}
|
||||
|
||||
if (node.val === '${') {
|
||||
var str = this.input;
|
||||
var idx = -1;
|
||||
var ch;
|
||||
|
||||
while ((ch = str[++idx])) {
|
||||
this.consume(1);
|
||||
node.val += ch;
|
||||
if (ch === '\\') {
|
||||
node.val += str[++idx];
|
||||
continue;
|
||||
}
|
||||
if (ch === '}') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.options.unescape !== false) {
|
||||
node.val = node.val.replace(/\\([{}])/g, '$1');
|
||||
}
|
||||
|
||||
if (last.val === '"' && this.input.charAt(0) === '"') {
|
||||
last.val = node.val;
|
||||
this.consume(1);
|
||||
return;
|
||||
}
|
||||
|
||||
return concatNodes.call(this, pos, node, prev, options);
|
||||
})
|
||||
|
||||
/**
|
||||
* Brackets: "[...]" (basic, this is overridden by
|
||||
* other parsers in more advanced implementations)
|
||||
*/
|
||||
|
||||
.set('bracket', function() {
|
||||
var isInside = this.isInside('brace');
|
||||
var pos = this.position();
|
||||
var m = this.match(/^(?:\[([!^]?)([^\]]{2,}|\]-)(\]|[^*+?]+)|\[)/);
|
||||
if (!m) return;
|
||||
|
||||
var prev = this.prev();
|
||||
var val = m[0];
|
||||
var negated = m[1] ? '^' : '';
|
||||
var inner = m[2] || '';
|
||||
var close = m[3] || '';
|
||||
|
||||
if (isInside && prev.type === 'brace') {
|
||||
prev.text = prev.text || '';
|
||||
prev.text += val;
|
||||
}
|
||||
|
||||
var esc = this.input.slice(0, 2);
|
||||
if (inner === '' && esc === '\\]') {
|
||||
inner += esc;
|
||||
this.consume(2);
|
||||
|
||||
var str = this.input;
|
||||
var idx = -1;
|
||||
var ch;
|
||||
|
||||
while ((ch = str[++idx])) {
|
||||
this.consume(1);
|
||||
if (ch === ']') {
|
||||
close = ch;
|
||||
break;
|
||||
}
|
||||
inner += ch;
|
||||
}
|
||||
}
|
||||
|
||||
return pos(new Node({
|
||||
type: 'bracket',
|
||||
val: val,
|
||||
escaped: close !== ']',
|
||||
negated: negated,
|
||||
inner: inner,
|
||||
close: close
|
||||
}));
|
||||
})
|
||||
|
||||
/**
|
||||
* Empty braces (we capture these early to
|
||||
* speed up processing in the compiler)
|
||||
*/
|
||||
|
||||
.set('multiplier', function() {
|
||||
var isInside = this.isInside('brace');
|
||||
var pos = this.position();
|
||||
var m = this.match(/^\{((?:,|\{,+\})+)\}/);
|
||||
if (!m) return;
|
||||
|
||||
this.multiplier = true;
|
||||
var prev = this.prev();
|
||||
var val = m[0];
|
||||
|
||||
if (isInside && prev.type === 'brace') {
|
||||
prev.text = prev.text || '';
|
||||
prev.text += val;
|
||||
}
|
||||
|
||||
var node = pos(new Node({
|
||||
type: 'text',
|
||||
multiplier: 1,
|
||||
match: m,
|
||||
val: val
|
||||
}));
|
||||
|
||||
return concatNodes.call(this, pos, node, prev, options);
|
||||
})
|
||||
|
||||
/**
|
||||
* Open
|
||||
*/
|
||||
|
||||
.set('brace.open', function() {
|
||||
var pos = this.position();
|
||||
var m = this.match(/^\{(?!(?:[^\\}]?|,+)\})/);
|
||||
if (!m) return;
|
||||
|
||||
var prev = this.prev();
|
||||
var last = utils.last(prev.nodes);
|
||||
|
||||
// if the last parsed character was an extglob character
|
||||
// we need to _not optimize_ the brace pattern because
|
||||
// it might be mistaken for an extglob by a downstream parser
|
||||
if (last && last.val && isExtglobChar(last.val.slice(-1))) {
|
||||
last.optimize = false;
|
||||
}
|
||||
|
||||
var open = pos(new Node({
|
||||
type: 'brace.open',
|
||||
val: m[0]
|
||||
}));
|
||||
|
||||
var node = pos(new Node({
|
||||
type: 'brace',
|
||||
nodes: []
|
||||
}));
|
||||
|
||||
node.push(open);
|
||||
prev.push(node);
|
||||
this.push('brace', node);
|
||||
})
|
||||
|
||||
/**
|
||||
* Close
|
||||
*/
|
||||
|
||||
.set('brace.close', function() {
|
||||
var pos = this.position();
|
||||
var m = this.match(/^\}/);
|
||||
if (!m || !m[0]) return;
|
||||
|
||||
var brace = this.pop('brace');
|
||||
var node = pos(new Node({
|
||||
type: 'brace.close',
|
||||
val: m[0]
|
||||
}));
|
||||
|
||||
if (!this.isType(brace, 'brace')) {
|
||||
if (this.options.strict) {
|
||||
throw new Error('missing opening "{"');
|
||||
}
|
||||
node.type = 'text';
|
||||
node.multiplier = 0;
|
||||
node.escaped = true;
|
||||
return node;
|
||||
}
|
||||
|
||||
var prev = this.prev();
|
||||
var last = utils.last(prev.nodes);
|
||||
if (last.text) {
|
||||
var lastNode = utils.last(last.nodes);
|
||||
if (lastNode.val === ')' && /[!@*?+]\(/.test(last.text)) {
|
||||
var open = last.nodes[0];
|
||||
var text = last.nodes[1];
|
||||
if (open.type === 'brace.open' && text && text.type === 'text') {
|
||||
text.optimize = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (brace.nodes.length > 2) {
|
||||
var first = brace.nodes[1];
|
||||
if (first.type === 'text' && first.val === ',') {
|
||||
brace.nodes.splice(1, 1);
|
||||
brace.nodes.push(first);
|
||||
}
|
||||
}
|
||||
|
||||
brace.push(node);
|
||||
})
|
||||
|
||||
/**
|
||||
* Capture boundary characters
|
||||
*/
|
||||
|
||||
.set('boundary', function() {
|
||||
var pos = this.position();
|
||||
var m = this.match(/^[$^](?!\{)/);
|
||||
if (!m) return;
|
||||
return pos(new Node({
|
||||
type: 'text',
|
||||
val: m[0]
|
||||
}));
|
||||
})
|
||||
|
||||
/**
|
||||
* One or zero, non-comma characters wrapped in braces
|
||||
*/
|
||||
|
||||
.set('nobrace', function() {
|
||||
var isInside = this.isInside('brace');
|
||||
var pos = this.position();
|
||||
var m = this.match(/^\{[^,]?\}/);
|
||||
if (!m) return;
|
||||
|
||||
var prev = this.prev();
|
||||
var val = m[0];
|
||||
|
||||
if (isInside && prev.type === 'brace') {
|
||||
prev.text = prev.text || '';
|
||||
prev.text += val;
|
||||
}
|
||||
|
||||
return pos(new Node({
|
||||
type: 'text',
|
||||
multiplier: 0,
|
||||
val: val
|
||||
}));
|
||||
})
|
||||
|
||||
/**
|
||||
* Text
|
||||
*/
|
||||
|
||||
.set('text', function() {
|
||||
var isInside = this.isInside('brace');
|
||||
var pos = this.position();
|
||||
var m = this.match(/^((?!\\)[^${}[\]])+/);
|
||||
if (!m) return;
|
||||
|
||||
var prev = this.prev();
|
||||
var val = m[0];
|
||||
|
||||
if (isInside && prev.type === 'brace') {
|
||||
prev.text = prev.text || '';
|
||||
prev.text += val;
|
||||
}
|
||||
|
||||
var node = pos(new Node({
|
||||
type: 'text',
|
||||
multiplier: 1,
|
||||
val: val
|
||||
}));
|
||||
|
||||
return concatNodes.call(this, pos, node, prev, options);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the character is an extglob character.
|
||||
*/
|
||||
|
||||
function isExtglobChar(ch) {
|
||||
return ch === '!' || ch === '@' || ch === '*' || ch === '?' || ch === '+';
|
||||
}
|
||||
|
||||
/**
|
||||
* Combine text nodes, and calculate empty sets (`{,,}`)
|
||||
* @param {Function} `pos` Function to calculate node position
|
||||
* @param {Object} `node` AST node
|
||||
* @return {Object}
|
||||
*/
|
||||
|
||||
function concatNodes(pos, node, parent, options) {
|
||||
node.orig = node.val;
|
||||
var prev = this.prev();
|
||||
var last = utils.last(prev.nodes);
|
||||
var isEscaped = false;
|
||||
|
||||
if (node.val.length > 1) {
|
||||
var a = node.val.charAt(0);
|
||||
var b = node.val.slice(-1);
|
||||
|
||||
isEscaped = (a === '"' && b === '"')
|
||||
|| (a === "'" && b === "'")
|
||||
|| (a === '`' && b === '`');
|
||||
}
|
||||
|
||||
if (isEscaped && options.unescape !== false) {
|
||||
node.val = node.val.slice(1, node.val.length - 1);
|
||||
node.escaped = true;
|
||||
}
|
||||
|
||||
if (node.match) {
|
||||
var match = node.match[1];
|
||||
if (!match || match.indexOf('}') === -1) {
|
||||
match = node.match[0];
|
||||
}
|
||||
|
||||
// replace each set with a single ","
|
||||
var val = match.replace(/\{/g, ',').replace(/\}/g, '');
|
||||
node.multiplier *= val.length;
|
||||
node.val = '';
|
||||
}
|
||||
|
||||
var simpleText = last.type === 'text'
|
||||
&& last.multiplier === 1
|
||||
&& node.multiplier === 1
|
||||
&& node.val;
|
||||
|
||||
if (simpleText) {
|
||||
last.val += node.val;
|
||||
return;
|
||||
}
|
||||
|
||||
prev.push(node);
|
||||
}
|
||||
32
node_modules/braces/lib/stringify.js
generated
vendored
32
node_modules/braces/lib/stringify.js
generated
vendored
@@ -1,32 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = (ast, options = {}) => {
|
||||
let stringify = (node, parent = {}) => {
|
||||
let invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
|
||||
let invalidNode = node.invalid === true && options.escapeInvalid === true;
|
||||
let output = '';
|
||||
|
||||
if (node.value) {
|
||||
if ((invalidBlock || invalidNode) && utils.isOpenOrClose(node)) {
|
||||
return '\\' + node.value;
|
||||
}
|
||||
return node.value;
|
||||
}
|
||||
|
||||
if (node.value) {
|
||||
return node.value;
|
||||
}
|
||||
|
||||
if (node.nodes) {
|
||||
for (let child of node.nodes) {
|
||||
output += stringify(child);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
return stringify(ast);
|
||||
};
|
||||
|
||||
387
node_modules/braces/lib/utils.js
generated
vendored
387
node_modules/braces/lib/utils.js
generated
vendored
@@ -1,112 +1,343 @@
|
||||
'use strict';
|
||||
|
||||
exports.isInteger = num => {
|
||||
if (typeof num === 'number') {
|
||||
return Number.isInteger(num);
|
||||
}
|
||||
if (typeof num === 'string' && num.trim() !== '') {
|
||||
return Number.isInteger(Number(num));
|
||||
var splitString = require('split-string');
|
||||
var utils = module.exports;
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
utils.extend = require('extend-shallow');
|
||||
utils.flatten = require('arr-flatten');
|
||||
utils.isObject = require('isobject');
|
||||
utils.fillRange = require('fill-range');
|
||||
utils.repeat = require('repeat-element');
|
||||
utils.unique = require('array-unique');
|
||||
|
||||
utils.define = function(obj, key, val) {
|
||||
Object.defineProperty(obj, key, {
|
||||
writable: true,
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
value: val
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the given string contains only empty brace sets.
|
||||
*/
|
||||
|
||||
utils.isEmptySets = function(str) {
|
||||
return /^(?:\{,\})+$/.test(str);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the given string contains only empty brace sets.
|
||||
*/
|
||||
|
||||
utils.isQuotedString = function(str) {
|
||||
var open = str.charAt(0);
|
||||
if (open === '\'' || open === '"' || open === '`') {
|
||||
return str.slice(-1) === open;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Find a node of the given type
|
||||
* Create the key to use for memoization. The unique key is generated
|
||||
* by iterating over the options and concatenating key-value pairs
|
||||
* to the pattern string.
|
||||
*/
|
||||
|
||||
exports.find = (node, type) => node.nodes.find(node => node.type === type);
|
||||
|
||||
/**
|
||||
* Find a node of the given type
|
||||
*/
|
||||
|
||||
exports.exceedsLimit = (min, max, step = 1, limit) => {
|
||||
if (limit === false) return false;
|
||||
if (!exports.isInteger(min) || !exports.isInteger(max)) return false;
|
||||
return ((Number(max) - Number(min)) / Number(step)) >= limit;
|
||||
utils.createKey = function(pattern, options) {
|
||||
var id = pattern;
|
||||
if (typeof options === 'undefined') {
|
||||
return id;
|
||||
}
|
||||
var keys = Object.keys(options);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i];
|
||||
id += ';' + key + '=' + String(options[key]);
|
||||
}
|
||||
return id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Escape the given node with '\\' before node.value
|
||||
* Normalize options
|
||||
*/
|
||||
|
||||
exports.escapeNode = (block, n = 0, type) => {
|
||||
let node = block.nodes[n];
|
||||
if (!node) return;
|
||||
utils.createOptions = function(options) {
|
||||
var opts = utils.extend.apply(null, arguments);
|
||||
if (typeof opts.expand === 'boolean') {
|
||||
opts.optimize = !opts.expand;
|
||||
}
|
||||
if (typeof opts.optimize === 'boolean') {
|
||||
opts.expand = !opts.optimize;
|
||||
}
|
||||
if (opts.optimize === true) {
|
||||
opts.makeRe = true;
|
||||
}
|
||||
return opts;
|
||||
};
|
||||
|
||||
if ((type && node.type === type) || node.type === 'open' || node.type === 'close') {
|
||||
if (node.escaped !== true) {
|
||||
node.value = '\\' + node.value;
|
||||
node.escaped = true;
|
||||
/**
|
||||
* Join patterns in `a` to patterns in `b`
|
||||
*/
|
||||
|
||||
utils.join = function(a, b, options) {
|
||||
options = options || {};
|
||||
a = utils.arrayify(a);
|
||||
b = utils.arrayify(b);
|
||||
|
||||
if (!a.length) return b;
|
||||
if (!b.length) return a;
|
||||
|
||||
var len = a.length;
|
||||
var idx = -1;
|
||||
var arr = [];
|
||||
|
||||
while (++idx < len) {
|
||||
var val = a[idx];
|
||||
if (Array.isArray(val)) {
|
||||
for (var i = 0; i < val.length; i++) {
|
||||
val[i] = utils.join(val[i], b, options);
|
||||
}
|
||||
arr.push(val);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (var j = 0; j < b.length; j++) {
|
||||
var bval = b[j];
|
||||
|
||||
if (Array.isArray(bval)) {
|
||||
arr.push(utils.join(val, bval, options));
|
||||
} else {
|
||||
arr.push(val + bval);
|
||||
}
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the given brace node should be enclosed in literal braces
|
||||
* Split the given string on `,` if not escaped.
|
||||
*/
|
||||
|
||||
exports.encloseBrace = node => {
|
||||
if (node.type !== 'brace') return false;
|
||||
if ((node.commas >> 0 + node.ranges >> 0) === 0) {
|
||||
node.invalid = true;
|
||||
return true;
|
||||
utils.split = function(str, options) {
|
||||
var opts = utils.extend({sep: ','}, options);
|
||||
if (typeof opts.keepQuotes !== 'boolean') {
|
||||
opts.keepQuotes = true;
|
||||
}
|
||||
return false;
|
||||
if (opts.unescape === false) {
|
||||
opts.keepEscaping = true;
|
||||
}
|
||||
return splitString(str, opts, utils.escapeBrackets(opts));
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if a brace node is invalid.
|
||||
* Expand ranges or sets in the given `pattern`.
|
||||
*
|
||||
* @param {String} `str`
|
||||
* @param {Object} `options`
|
||||
* @return {Object}
|
||||
*/
|
||||
|
||||
exports.isInvalidBrace = block => {
|
||||
if (block.type !== 'brace') return false;
|
||||
if (block.invalid === true || block.dollar) return true;
|
||||
if ((block.commas >> 0 + block.ranges >> 0) === 0) {
|
||||
block.invalid = true;
|
||||
return true;
|
||||
utils.expand = function(str, options) {
|
||||
var opts = utils.extend({rangeLimit: 10000}, options);
|
||||
var segs = utils.split(str, opts);
|
||||
var tok = { segs: segs };
|
||||
|
||||
if (utils.isQuotedString(str)) {
|
||||
return tok;
|
||||
}
|
||||
if (block.open !== true || block.close !== true) {
|
||||
block.invalid = true;
|
||||
return true;
|
||||
|
||||
if (opts.rangeLimit === true) {
|
||||
opts.rangeLimit = 10000;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if a node is an open or close node
|
||||
*/
|
||||
|
||||
exports.isOpenOrClose = node => {
|
||||
if (node.type === 'open' || node.type === 'close') {
|
||||
return true;
|
||||
}
|
||||
return node.open === true || node.close === true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reduce an array of text nodes.
|
||||
*/
|
||||
|
||||
exports.reduce = nodes => nodes.reduce((acc, node) => {
|
||||
if (node.type === 'text') acc.push(node.value);
|
||||
if (node.type === 'range') node.type = 'text';
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Flatten an array
|
||||
*/
|
||||
|
||||
exports.flatten = (...args) => {
|
||||
const result = [];
|
||||
const flat = arr => {
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
let ele = arr[i];
|
||||
Array.isArray(ele) ? flat(ele, result) : ele !== void 0 && result.push(ele);
|
||||
if (segs.length > 1) {
|
||||
if (opts.optimize === false) {
|
||||
tok.val = segs[0];
|
||||
return tok;
|
||||
}
|
||||
return result;
|
||||
|
||||
tok.segs = utils.stringifyArray(tok.segs);
|
||||
} else if (segs.length === 1) {
|
||||
var arr = str.split('..');
|
||||
|
||||
if (arr.length === 1) {
|
||||
tok.val = tok.segs[tok.segs.length - 1] || tok.val || str;
|
||||
tok.segs = [];
|
||||
return tok;
|
||||
}
|
||||
|
||||
if (arr.length === 2 && arr[0] === arr[1]) {
|
||||
tok.escaped = true;
|
||||
tok.val = arr[0];
|
||||
tok.segs = [];
|
||||
return tok;
|
||||
}
|
||||
|
||||
if (arr.length > 1) {
|
||||
if (opts.optimize !== false) {
|
||||
opts.optimize = true;
|
||||
delete opts.expand;
|
||||
}
|
||||
|
||||
if (opts.optimize !== true) {
|
||||
var min = Math.min(arr[0], arr[1]);
|
||||
var max = Math.max(arr[0], arr[1]);
|
||||
var step = arr[2] || 1;
|
||||
|
||||
if (opts.rangeLimit !== false && ((max - min) / step >= opts.rangeLimit)) {
|
||||
throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
|
||||
}
|
||||
}
|
||||
|
||||
arr.push(opts);
|
||||
tok.segs = utils.fillRange.apply(null, arr);
|
||||
|
||||
if (!tok.segs.length) {
|
||||
tok.escaped = true;
|
||||
tok.val = str;
|
||||
return tok;
|
||||
}
|
||||
|
||||
if (opts.optimize === true) {
|
||||
tok.segs = utils.stringifyArray(tok.segs);
|
||||
}
|
||||
|
||||
if (tok.segs === '') {
|
||||
tok.val = str;
|
||||
} else {
|
||||
tok.val = tok.segs[0];
|
||||
}
|
||||
return tok;
|
||||
}
|
||||
} else {
|
||||
tok.val = str;
|
||||
}
|
||||
return tok;
|
||||
};
|
||||
|
||||
/**
|
||||
* Ensure commas inside brackets and parens are not split.
|
||||
* @param {Object} `tok` Token from the `split-string` module
|
||||
* @return {undefined}
|
||||
*/
|
||||
|
||||
utils.escapeBrackets = function(options) {
|
||||
return function(tok) {
|
||||
if (tok.escaped && tok.val === 'b') {
|
||||
tok.val = '\\b';
|
||||
return;
|
||||
}
|
||||
|
||||
if (tok.val !== '(' && tok.val !== '[') return;
|
||||
var opts = utils.extend({}, options);
|
||||
var brackets = [];
|
||||
var parens = [];
|
||||
var stack = [];
|
||||
var val = tok.val;
|
||||
var str = tok.str;
|
||||
var i = tok.idx - 1;
|
||||
|
||||
while (++i < str.length) {
|
||||
var ch = str[i];
|
||||
|
||||
if (ch === '\\') {
|
||||
val += (opts.keepEscaping === false ? '' : ch) + str[++i];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch === '(') {
|
||||
parens.push(ch);
|
||||
stack.push(ch);
|
||||
}
|
||||
|
||||
if (ch === '[') {
|
||||
brackets.push(ch);
|
||||
stack.push(ch);
|
||||
}
|
||||
|
||||
if (ch === ')') {
|
||||
parens.pop();
|
||||
stack.pop();
|
||||
if (!stack.length) {
|
||||
val += ch;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ch === ']') {
|
||||
brackets.pop();
|
||||
stack.pop();
|
||||
if (!stack.length) {
|
||||
val += ch;
|
||||
break;
|
||||
}
|
||||
}
|
||||
val += ch;
|
||||
}
|
||||
|
||||
tok.split = false;
|
||||
tok.val = val.slice(1);
|
||||
tok.idx = i;
|
||||
};
|
||||
flat(args);
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the given string looks like a regex quantifier
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
utils.isQuantifier = function(str) {
|
||||
return /^(?:[0-9]?,[0-9]|[0-9],)$/.test(str);
|
||||
};
|
||||
|
||||
/**
|
||||
* Cast `val` to an array.
|
||||
* @param {*} `val`
|
||||
*/
|
||||
|
||||
utils.stringifyArray = function(arr) {
|
||||
return [utils.arrayify(arr).join('|')];
|
||||
};
|
||||
|
||||
/**
|
||||
* Cast `val` to an array.
|
||||
* @param {*} `val`
|
||||
*/
|
||||
|
||||
utils.arrayify = function(arr) {
|
||||
if (typeof arr === 'undefined') {
|
||||
return [];
|
||||
}
|
||||
if (typeof arr === 'string') {
|
||||
return [arr];
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the given `str` is a non-empty string
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
utils.isString = function(str) {
|
||||
return str != null && typeof str === 'string';
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the last element from `array`
|
||||
* @param {Array} `array`
|
||||
* @return {*}
|
||||
*/
|
||||
|
||||
utils.last = function(arr, n) {
|
||||
return arr[arr.length - (n || 1)];
|
||||
};
|
||||
|
||||
utils.escapeRegex = function(str) {
|
||||
return str.replace(/\\?([!^*?()[\]{}+?/])/g, '\\$1');
|
||||
};
|
||||
|
||||
47
node_modules/braces/package.json
generated
vendored
47
node_modules/braces/package.json
generated
vendored
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "braces",
|
||||
"description": "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.",
|
||||
"version": "3.0.2",
|
||||
"version": "2.3.2",
|
||||
"homepage": "https://github.com/micromatch/braces",
|
||||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
||||
"contributors": [
|
||||
@@ -22,20 +22,42 @@
|
||||
],
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha",
|
||||
"benchmark": "node benchmark"
|
||||
},
|
||||
"dependencies": {
|
||||
"fill-range": "^7.0.1"
|
||||
"arr-flatten": "^1.1.0",
|
||||
"array-unique": "^0.3.2",
|
||||
"extend-shallow": "^2.0.1",
|
||||
"fill-range": "^4.0.0",
|
||||
"isobject": "^3.0.1",
|
||||
"repeat-element": "^1.1.2",
|
||||
"snapdragon": "^0.8.1",
|
||||
"snapdragon-node": "^2.0.1",
|
||||
"split-string": "^3.0.2",
|
||||
"to-regex": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ansi-colors": "^3.2.4",
|
||||
"bash-path": "^2.0.1",
|
||||
"gulp-format-md": "^2.0.0",
|
||||
"mocha": "^6.1.1"
|
||||
"ansi-cyan": "^0.1.1",
|
||||
"benchmarked": "^2.0.0",
|
||||
"brace-expansion": "^1.1.8",
|
||||
"cross-spawn": "^5.1.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",
|
||||
"is-windows": "^1.0.1",
|
||||
"minimatch": "^3.0.4",
|
||||
"mocha": "^3.2.0",
|
||||
"noncharacters": "^1.1.0",
|
||||
"text-table": "^0.2.0",
|
||||
"time-diff": "^0.3.1",
|
||||
"yargs-parser": "^8.0.0"
|
||||
},
|
||||
"keywords": [
|
||||
"alpha",
|
||||
@@ -72,6 +94,15 @@
|
||||
},
|
||||
"plugins": [
|
||||
"gulp-format-md"
|
||||
]
|
||||
],
|
||||
"related": {
|
||||
"list": [
|
||||
"expand-brackets",
|
||||
"extglob",
|
||||
"fill-range",
|
||||
"micromatch",
|
||||
"nanomatch"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user