update, text, response
This commit is contained in:
2
node_modules/to-regex-range/LICENSE
generated
vendored
2
node_modules/to-regex-range/LICENSE
generated
vendored
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-present, Jon Schlinkert.
|
||||
Copyright (c) 2015-2017, Jon Schlinkert
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
190
node_modules/to-regex-range/README.md
generated
vendored
190
node_modules/to-regex-range/README.md
generated
vendored
@@ -1,9 +1,7 @@
|
||||
# to-regex-range [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [](https://www.npmjs.com/package/to-regex-range) [](https://npmjs.org/package/to-regex-range) [](https://npmjs.org/package/to-regex-range) [](https://travis-ci.org/micromatch/to-regex-range)
|
||||
# to-regex-range [](https://www.npmjs.com/package/to-regex-range) [](https://npmjs.org/package/to-regex-range) [](https://npmjs.org/package/to-regex-range) [](https://travis-ci.org/micromatch/to-regex-range)
|
||||
|
||||
> Pass two numbers, get a regex-compatible source string for matching ranges. Validated against more than 2.78 million test assertions.
|
||||
|
||||
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://www.npmjs.com/):
|
||||
@@ -12,6 +10,12 @@ Install with [npm](https://www.npmjs.com/):
|
||||
$ npm install --save to-regex-range
|
||||
```
|
||||
|
||||
Install with [yarn](https://yarnpkg.com):
|
||||
|
||||
```sh
|
||||
$ yarn add to-regex-range
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary><strong>What does this do?</strong></summary>
|
||||
|
||||
@@ -22,8 +26,8 @@ This libary generates the `source` string to be passed to `new RegExp()` for mat
|
||||
**Example**
|
||||
|
||||
```js
|
||||
const toRegexRange = require('to-regex-range');
|
||||
const regex = new RegExp(toRegexRange('15', '95'));
|
||||
var toRegexRange = require('to-regex-range');
|
||||
var regex = new RegExp(toRegexRange('15', '95'));
|
||||
```
|
||||
|
||||
A string is returned so that you can do whatever you need with it before passing it to `new RegExp()` (like adding `^` or `$` boundaries, defining flags, or combining it another string).
|
||||
@@ -59,13 +63,13 @@ If you're interested in learning more about [character classes](http://www.regul
|
||||
|
||||
### Heavily tested
|
||||
|
||||
As of April 07, 2019, this library runs [>1m test assertions](./test/test.js) against generated regex-ranges to provide brute-force verification that results are correct.
|
||||
As of April 27, 2017, this library runs [2,783,483 test assertions](./test/test.js) against generated regex-ranges to provide brute-force verification that results are indeed correct.
|
||||
|
||||
Tests run in ~280ms on my MacBook Pro, 2.5 GHz Intel Core i7.
|
||||
Tests run in ~870ms on my MacBook Pro, 2.5 GHz Intel Core i7.
|
||||
|
||||
### Optimized
|
||||
### Highly optimized
|
||||
|
||||
Generated regular expressions are optimized:
|
||||
Generated regular expressions are highly optimized:
|
||||
|
||||
* duplicate sequences and character classes are reduced using quantifiers
|
||||
* smart enough to use `?` conditionals when number(s) or range(s) can be positive or negative
|
||||
@@ -80,20 +84,20 @@ Generated regular expressions are optimized:
|
||||
Add this library to your javascript application with the following line of code
|
||||
|
||||
```js
|
||||
const toRegexRange = require('to-regex-range');
|
||||
var toRegexRange = require('to-regex-range');
|
||||
```
|
||||
|
||||
The main export is a function that takes two integers: the `min` value and `max` value (formatted as strings or numbers).
|
||||
|
||||
```js
|
||||
const source = toRegexRange('15', '95');
|
||||
var source = toRegexRange('15', '95');
|
||||
//=> 1[5-9]|[2-8][0-9]|9[0-5]
|
||||
|
||||
const regex = new RegExp(`^${source}$`);
|
||||
console.log(regex.test('14')); //=> false
|
||||
console.log(regex.test('50')); //=> true
|
||||
console.log(regex.test('94')); //=> true
|
||||
console.log(regex.test('96')); //=> false
|
||||
var re = new RegExp('^' + source + '$');
|
||||
console.log(re.test('14')); //=> false
|
||||
console.log(re.test('50')); //=> true
|
||||
console.log(re.test('94')); //=> true
|
||||
console.log(re.test('96')); //=> false
|
||||
```
|
||||
|
||||
## Options
|
||||
@@ -110,7 +114,7 @@ Wrap the returned value in parentheses when there is more than one regex conditi
|
||||
console.log(toRegexRange('-10', '10'));
|
||||
//=> -[1-9]|-?10|[0-9]
|
||||
|
||||
console.log(toRegexRange('-10', '10', { capture: true }));
|
||||
console.log(toRegexRange('-10', '10', {capture: true}));
|
||||
//=> (-[1-9]|-?10|[0-9])
|
||||
```
|
||||
|
||||
@@ -126,7 +130,7 @@ Use the regex shorthand for `[0-9]`:
|
||||
console.log(toRegexRange('0', '999999'));
|
||||
//=> [0-9]|[1-9][0-9]{1,5}
|
||||
|
||||
console.log(toRegexRange('0', '999999', { shorthand: true }));
|
||||
console.log(toRegexRange('0', '999999', {shorthand: true}));
|
||||
//=> \d|[1-9]\d{1,5}
|
||||
```
|
||||
|
||||
@@ -136,60 +140,58 @@ console.log(toRegexRange('0', '999999', { shorthand: true }));
|
||||
|
||||
**Default**: `true`
|
||||
|
||||
This option relaxes matching for leading zeros when when ranges are zero-padded.
|
||||
This option only applies to **negative zero-padded ranges**. By default, when a negative zero-padded range is defined, the number of leading zeros is relaxed using `-0*`.
|
||||
|
||||
```js
|
||||
const source = toRegexRange('-0010', '0010');
|
||||
const regex = new RegExp(`^${source}$`);
|
||||
console.log(regex.test('-10')); //=> true
|
||||
console.log(regex.test('-010')); //=> true
|
||||
console.log(regex.test('-0010')); //=> true
|
||||
console.log(regex.test('10')); //=> true
|
||||
console.log(regex.test('010')); //=> true
|
||||
console.log(regex.test('0010')); //=> true
|
||||
console.log(toRegexRange('-001', '100'));
|
||||
//=> -0*1|0{2}[0-9]|0[1-9][0-9]|100
|
||||
|
||||
console.log(toRegexRange('-001', '100', {relaxZeros: false}));
|
||||
//=> -0{2}1|0{2}[0-9]|0[1-9][0-9]|100
|
||||
```
|
||||
|
||||
When `relaxZeros` is false, matching is strict:
|
||||
<details>
|
||||
<summary><strong>Why are zeros relaxed for negative zero-padded ranges by default?</strong></summary>
|
||||
|
||||
Consider the following.
|
||||
|
||||
```js
|
||||
const source = toRegexRange('-0010', '0010', { relaxZeros: false });
|
||||
const regex = new RegExp(`^${source}$`);
|
||||
console.log(regex.test('-10')); //=> false
|
||||
console.log(regex.test('-010')); //=> false
|
||||
console.log(regex.test('-0010')); //=> true
|
||||
console.log(regex.test('10')); //=> false
|
||||
console.log(regex.test('010')); //=> false
|
||||
console.log(regex.test('0010')); //=> true
|
||||
var regex = toRegexRange('-001', '100');
|
||||
```
|
||||
|
||||
_Note that `-001` and `100` are both three digits long_.
|
||||
|
||||
In most zero-padding implementations, only a single leading zero is enough to indicate that zero-padding should be applied. Thus, the leading zeros would be "corrected" on the negative range in the example to `-01`, instead of `-001`, to make total length of each string no greater than the length of the largest number in the range (in other words, `-001` is 4 digits, but `100` is only three digits).
|
||||
|
||||
If zeros were not relaxed by default, you might expect the resulting regex of the above pattern to match `-001` - given that it's defined that way in the arguments - _but it wouldn't_. It would, however, match `-01`. This gets even more ambiguous with large ranges, like `-01` to `1000000`.
|
||||
|
||||
Thus, we relax zeros by default to provide a more predictable experience for users.
|
||||
|
||||
</details>
|
||||
|
||||
## Examples
|
||||
|
||||
| **Range** | **Result** | **Compile time** |
|
||||
| --- | --- | --- |
|
||||
| `toRegexRange(-10, 10)` | `-[1-9]\|-?10\|[0-9]` | _132μs_ |
|
||||
| `toRegexRange(-100, -10)` | `-1[0-9]\|-[2-9][0-9]\|-100` | _50μs_ |
|
||||
| `toRegexRange(-100, 100)` | `-[1-9]\|-?[1-9][0-9]\|-?100\|[0-9]` | _42μs_ |
|
||||
| `toRegexRange(001, 100)` | `0{0,2}[1-9]\|0?[1-9][0-9]\|100` | _109μs_ |
|
||||
| `toRegexRange(001, 555)` | `0{0,2}[1-9]\|0?[1-9][0-9]\|[1-4][0-9]{2}\|5[0-4][0-9]\|55[0-5]` | _51μs_ |
|
||||
| `toRegexRange(0010, 1000)` | `0{0,2}1[0-9]\|0{0,2}[2-9][0-9]\|0?[1-9][0-9]{2}\|1000` | _31μs_ |
|
||||
| `toRegexRange(1, 50)` | `[1-9]\|[1-4][0-9]\|50` | _24μs_ |
|
||||
| `toRegexRange(1, 55)` | `[1-9]\|[1-4][0-9]\|5[0-5]` | _23μs_ |
|
||||
| `toRegexRange(1, 555)` | `[1-9]\|[1-9][0-9]\|[1-4][0-9]{2}\|5[0-4][0-9]\|55[0-5]` | _30μs_ |
|
||||
| `toRegexRange(1, 5555)` | `[1-9]\|[1-9][0-9]{1,2}\|[1-4][0-9]{3}\|5[0-4][0-9]{2}\|55[0-4][0-9]\|555[0-5]` | _43μs_ |
|
||||
| `toRegexRange(111, 555)` | `11[1-9]\|1[2-9][0-9]\|[2-4][0-9]{2}\|5[0-4][0-9]\|55[0-5]` | _38μs_ |
|
||||
| `toRegexRange(29, 51)` | `29\|[34][0-9]\|5[01]` | _24μs_ |
|
||||
| `toRegexRange(31, 877)` | `3[1-9]\|[4-9][0-9]\|[1-7][0-9]{2}\|8[0-6][0-9]\|87[0-7]` | _32μs_ |
|
||||
| `toRegexRange(5, 5)` | `5` | _8μs_ |
|
||||
| `toRegexRange(5, 6)` | `5\|6` | _11μs_ |
|
||||
| `toRegexRange(1, 2)` | `1\|2` | _6μs_ |
|
||||
| `toRegexRange(1, 5)` | `[1-5]` | _15μs_ |
|
||||
| `toRegexRange(1, 10)` | `[1-9]\|10` | _22μs_ |
|
||||
| `toRegexRange(1, 100)` | `[1-9]\|[1-9][0-9]\|100` | _25μs_ |
|
||||
| `toRegexRange(1, 1000)` | `[1-9]\|[1-9][0-9]{1,2}\|1000` | _31μs_ |
|
||||
| `toRegexRange(1, 10000)` | `[1-9]\|[1-9][0-9]{1,3}\|10000` | _34μs_ |
|
||||
| `toRegexRange(1, 100000)` | `[1-9]\|[1-9][0-9]{1,4}\|100000` | _36μs_ |
|
||||
| `toRegexRange(1, 1000000)` | `[1-9]\|[1-9][0-9]{1,5}\|1000000` | _42μs_ |
|
||||
| `toRegexRange(1, 10000000)` | `[1-9]\|[1-9][0-9]{1,6}\|10000000` | _42μs_ |
|
||||
| **Range** | **Result** | **Compile time** |
|
||||
| --- | --- | --- |
|
||||
| `toRegexRange('5, 5')` | `5` | _33μs_ |
|
||||
| `toRegexRange('5, 6')` | `5\|6` | _53μs_ |
|
||||
| `toRegexRange('29, 51')` | `29\|[34][0-9]\|5[01]` | _699μs_ |
|
||||
| `toRegexRange('31, 877')` | `3[1-9]\|[4-9][0-9]\|[1-7][0-9]{2}\|8[0-6][0-9]\|87[0-7]` | _711μs_ |
|
||||
| `toRegexRange('111, 555')` | `11[1-9]\|1[2-9][0-9]\|[2-4][0-9]{2}\|5[0-4][0-9]\|55[0-5]` | _62μs_ |
|
||||
| `toRegexRange('-10, 10')` | `-[1-9]\|-?10\|[0-9]` | _74μs_ |
|
||||
| `toRegexRange('-100, -10')` | `-1[0-9]\|-[2-9][0-9]\|-100` | _49μs_ |
|
||||
| `toRegexRange('-100, 100')` | `-[1-9]\|-?[1-9][0-9]\|-?100\|[0-9]` | _45μs_ |
|
||||
| `toRegexRange('001, 100')` | `0{2}[1-9]\|0[1-9][0-9]\|100` | _158μs_ |
|
||||
| `toRegexRange('0010, 1000')` | `0{2}1[0-9]\|0{2}[2-9][0-9]\|0[1-9][0-9]{2}\|1000` | _61μs_ |
|
||||
| `toRegexRange('1, 2')` | `1\|2` | _10μs_ |
|
||||
| `toRegexRange('1, 5')` | `[1-5]` | _24μs_ |
|
||||
| `toRegexRange('1, 10')` | `[1-9]\|10` | _23μs_ |
|
||||
| `toRegexRange('1, 100')` | `[1-9]\|[1-9][0-9]\|100` | _30μs_ |
|
||||
| `toRegexRange('1, 1000')` | `[1-9]\|[1-9][0-9]{1,2}\|1000` | _52μs_ |
|
||||
| `toRegexRange('1, 10000')` | `[1-9]\|[1-9][0-9]{1,3}\|10000` | _47μs_ |
|
||||
| `toRegexRange('1, 100000')` | `[1-9]\|[1-9][0-9]{1,4}\|100000` | _44μs_ |
|
||||
| `toRegexRange('1, 1000000')` | `[1-9]\|[1-9][0-9]{1,5}\|1000000` | _49μs_ |
|
||||
| `toRegexRange('1, 10000000')` | `[1-9]\|[1-9][0-9]{1,6}\|10000000` | _63μs_ |
|
||||
|
||||
## Heads up!
|
||||
|
||||
@@ -232,26 +234,19 @@ Inspired by the python library [range-regex](https://github.com/dimka665/range-r
|
||||
|
||||
## About
|
||||
|
||||
<details>
|
||||
<summary><strong>Contributing</strong></summary>
|
||||
### Related projects
|
||||
|
||||
* [expand-range](https://www.npmjs.com/package/expand-range): Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. See… [more](https://github.com/jonschlinkert/expand-range) | [homepage](https://github.com/jonschlinkert/expand-range "Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. See the benchmarks. Used by micromatch.")
|
||||
* [fill-range](https://www.npmjs.com/package/fill-range): Fill in a range of numbers or letters, optionally passing an increment or `step` to… [more](https://github.com/jonschlinkert/fill-range) | [homepage](https://github.com/jonschlinkert/fill-range "Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`")
|
||||
* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | [homepage](https://github.com/jonschlinkert/micromatch "Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.")
|
||||
* [repeat-element](https://www.npmjs.com/package/repeat-element): Create an array by repeating the given value n times. | [homepage](https://github.com/jonschlinkert/repeat-element "Create an array by repeating the given value n times.")
|
||||
* [repeat-string](https://www.npmjs.com/package/repeat-string): Repeat the given string n times. Fastest implementation for repeating a string. | [homepage](https://github.com/jonschlinkert/repeat-string "Repeat the given string n times. Fastest implementation for repeating a string.")
|
||||
|
||||
### Contributing
|
||||
|
||||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Running Tests</strong></summary>
|
||||
|
||||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
||||
|
||||
```sh
|
||||
$ npm install && npm test
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Building docs</strong></summary>
|
||||
### Building docs
|
||||
|
||||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
||||
|
||||
@@ -261,45 +256,26 @@ To generate the readme, run the following command:
|
||||
$ npm install -g verbose/verb#dev verb-generate-readme && verb
|
||||
```
|
||||
|
||||
</details>
|
||||
### Running tests
|
||||
|
||||
### Related projects
|
||||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
||||
|
||||
You might also be interested in these projects:
|
||||
|
||||
* [expand-range](https://www.npmjs.com/package/expand-range): Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used… [more](https://github.com/jonschlinkert/expand-range) | [homepage](https://github.com/jonschlinkert/expand-range "Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used by micromatch.")
|
||||
* [fill-range](https://www.npmjs.com/package/fill-range): Fill in a range of numbers or letters, optionally passing an increment or `step` to… [more](https://github.com/jonschlinkert/fill-range) | [homepage](https://github.com/jonschlinkert/fill-range "Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`")
|
||||
* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | [homepage](https://github.com/micromatch/micromatch "Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.")
|
||||
* [repeat-element](https://www.npmjs.com/package/repeat-element): Create an array by repeating the given value n times. | [homepage](https://github.com/jonschlinkert/repeat-element "Create an array by repeating the given value n times.")
|
||||
* [repeat-string](https://www.npmjs.com/package/repeat-string): Repeat the given string n times. Fastest implementation for repeating a string. | [homepage](https://github.com/jonschlinkert/repeat-string "Repeat the given string n times. Fastest implementation for repeating a string.")
|
||||
|
||||
### Contributors
|
||||
|
||||
| **Commits** | **Contributor** |
|
||||
| --- | --- |
|
||||
| 63 | [jonschlinkert](https://github.com/jonschlinkert) |
|
||||
| 3 | [doowb](https://github.com/doowb) |
|
||||
| 2 | [realityking](https://github.com/realityking) |
|
||||
```sh
|
||||
$ npm install && npm test
|
||||
```
|
||||
|
||||
### Author
|
||||
|
||||
**Jon Schlinkert**
|
||||
|
||||
* [GitHub Profile](https://github.com/jonschlinkert)
|
||||
* [Twitter Profile](https://twitter.com/jonschlinkert)
|
||||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
||||
|
||||
Please consider supporting me on Patreon, or [start your own Patreon page](https://patreon.com/invite/bxpbvm)!
|
||||
|
||||
<a href="https://www.patreon.com/jonschlinkert">
|
||||
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" height="50">
|
||||
</a>
|
||||
* [github/jonschlinkert](https://github.com/jonschlinkert)
|
||||
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
|
||||
|
||||
### License
|
||||
|
||||
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
|
||||
Copyright © 2017, [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 07, 2019._
|
||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on April 27, 2017._
|
||||
282
node_modules/to-regex-range/index.js
generated
vendored
282
node_modules/to-regex-range/index.js
generated
vendored
@@ -1,120 +1,113 @@
|
||||
/*!
|
||||
* to-regex-range <https://github.com/micromatch/to-regex-range>
|
||||
* to-regex-range <https://github.com/jonschlinkert/to-regex-range>
|
||||
*
|
||||
* Copyright (c) 2015-present, Jon Schlinkert.
|
||||
* Copyright (c) 2015, 2017, Jon Schlinkert.
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const isNumber = require('is-number');
|
||||
var repeat = require('repeat-string');
|
||||
var isNumber = require('is-number');
|
||||
var cache = {};
|
||||
|
||||
const toRegexRange = (min, max, options) => {
|
||||
function toRegexRange(min, max, options) {
|
||||
if (isNumber(min) === false) {
|
||||
throw new TypeError('toRegexRange: expected the first argument to be a number');
|
||||
throw new RangeError('toRegexRange: first argument is invalid.');
|
||||
}
|
||||
|
||||
if (max === void 0 || min === max) {
|
||||
if (typeof max === 'undefined' || min === max) {
|
||||
return String(min);
|
||||
}
|
||||
|
||||
if (isNumber(max) === false) {
|
||||
throw new TypeError('toRegexRange: expected the second argument to be a number.');
|
||||
throw new RangeError('toRegexRange: second argument is invalid.');
|
||||
}
|
||||
|
||||
let opts = { relaxZeros: true, ...options };
|
||||
if (typeof opts.strictZeros === 'boolean') {
|
||||
opts.relaxZeros = opts.strictZeros === false;
|
||||
options = options || {};
|
||||
var relax = String(options.relaxZeros);
|
||||
var shorthand = String(options.shorthand);
|
||||
var capture = String(options.capture);
|
||||
var key = min + ':' + max + '=' + relax + shorthand + capture;
|
||||
if (cache.hasOwnProperty(key)) {
|
||||
return cache[key].result;
|
||||
}
|
||||
|
||||
let relax = String(opts.relaxZeros);
|
||||
let shorthand = String(opts.shorthand);
|
||||
let capture = String(opts.capture);
|
||||
let wrap = String(opts.wrap);
|
||||
let cacheKey = min + ':' + max + '=' + relax + shorthand + capture + wrap;
|
||||
|
||||
if (toRegexRange.cache.hasOwnProperty(cacheKey)) {
|
||||
return toRegexRange.cache[cacheKey].result;
|
||||
}
|
||||
|
||||
let a = Math.min(min, max);
|
||||
let b = Math.max(min, max);
|
||||
var a = Math.min(min, max);
|
||||
var b = Math.max(min, max);
|
||||
|
||||
if (Math.abs(a - b) === 1) {
|
||||
let result = min + '|' + max;
|
||||
if (opts.capture) {
|
||||
return `(${result})`;
|
||||
var result = min + '|' + max;
|
||||
if (options.capture) {
|
||||
return '(' + result + ')';
|
||||
}
|
||||
if (opts.wrap === false) {
|
||||
return result;
|
||||
}
|
||||
return `(?:${result})`;
|
||||
return result;
|
||||
}
|
||||
|
||||
let isPadded = hasPadding(min) || hasPadding(max);
|
||||
let state = { min, max, a, b };
|
||||
let positives = [];
|
||||
let negatives = [];
|
||||
var isPadded = padding(min) || padding(max);
|
||||
var positives = [];
|
||||
var negatives = [];
|
||||
|
||||
var tok = {min: min, max: max, a: a, b: b};
|
||||
if (isPadded) {
|
||||
state.isPadded = isPadded;
|
||||
state.maxLen = String(state.max).length;
|
||||
tok.isPadded = isPadded;
|
||||
tok.maxLen = String(tok.max).length;
|
||||
}
|
||||
|
||||
if (a < 0) {
|
||||
let newMin = b < 0 ? Math.abs(b) : 1;
|
||||
negatives = splitToPatterns(newMin, Math.abs(a), state, opts);
|
||||
a = state.a = 0;
|
||||
var newMin = b < 0 ? Math.abs(b) : 1;
|
||||
var newMax = Math.abs(a);
|
||||
negatives = splitToPatterns(newMin, newMax, tok, options);
|
||||
a = tok.a = 0;
|
||||
}
|
||||
|
||||
if (b >= 0) {
|
||||
positives = splitToPatterns(a, b, state, opts);
|
||||
positives = splitToPatterns(a, b, tok, options);
|
||||
}
|
||||
|
||||
state.negatives = negatives;
|
||||
state.positives = positives;
|
||||
state.result = collatePatterns(negatives, positives, opts);
|
||||
tok.negatives = negatives;
|
||||
tok.positives = positives;
|
||||
tok.result = siftPatterns(negatives, positives, options);
|
||||
|
||||
if (opts.capture === true) {
|
||||
state.result = `(${state.result})`;
|
||||
} else if (opts.wrap !== false && (positives.length + negatives.length) > 1) {
|
||||
state.result = `(?:${state.result})`;
|
||||
if (options.capture && (positives.length + negatives.length) > 1) {
|
||||
tok.result = '(' + tok.result + ')';
|
||||
}
|
||||
|
||||
toRegexRange.cache[cacheKey] = state;
|
||||
return state.result;
|
||||
};
|
||||
cache[key] = tok;
|
||||
return tok.result;
|
||||
}
|
||||
|
||||
function collatePatterns(neg, pos, options) {
|
||||
let onlyNegative = filterPatterns(neg, pos, '-', false, options) || [];
|
||||
let onlyPositive = filterPatterns(pos, neg, '', false, options) || [];
|
||||
let intersected = filterPatterns(neg, pos, '-?', true, options) || [];
|
||||
let subpatterns = onlyNegative.concat(intersected).concat(onlyPositive);
|
||||
function siftPatterns(neg, pos, options) {
|
||||
var onlyNegative = filterPatterns(neg, pos, '-', false, options) || [];
|
||||
var onlyPositive = filterPatterns(pos, neg, '', false, options) || [];
|
||||
var intersected = filterPatterns(neg, pos, '-?', true, options) || [];
|
||||
var subpatterns = onlyNegative.concat(intersected).concat(onlyPositive);
|
||||
return subpatterns.join('|');
|
||||
}
|
||||
|
||||
function splitToRanges(min, max) {
|
||||
let nines = 1;
|
||||
let zeros = 1;
|
||||
min = Number(min);
|
||||
max = Number(max);
|
||||
|
||||
let stop = countNines(min, nines);
|
||||
let stops = new Set([max]);
|
||||
var nines = 1;
|
||||
var stops = [max];
|
||||
var stop = +countNines(min, nines);
|
||||
|
||||
while (min <= stop && stop <= max) {
|
||||
stops.add(stop);
|
||||
stops = push(stops, stop);
|
||||
nines += 1;
|
||||
stop = countNines(min, nines);
|
||||
stop = +countNines(min, nines);
|
||||
}
|
||||
|
||||
var zeros = 1;
|
||||
stop = countZeros(max + 1, zeros) - 1;
|
||||
|
||||
while (min < stop && stop <= max) {
|
||||
stops.add(stop);
|
||||
stops = push(stops, stop);
|
||||
zeros += 1;
|
||||
stop = countZeros(max + 1, zeros) - 1;
|
||||
}
|
||||
|
||||
stops = [...stops];
|
||||
stops.sort(compare);
|
||||
return stops;
|
||||
}
|
||||
@@ -128,64 +121,69 @@ function splitToRanges(min, max) {
|
||||
|
||||
function rangeToPattern(start, stop, options) {
|
||||
if (start === stop) {
|
||||
return { pattern: start, count: [], digits: 0 };
|
||||
return {pattern: String(start), digits: []};
|
||||
}
|
||||
|
||||
let zipped = zip(start, stop);
|
||||
let digits = zipped.length;
|
||||
let pattern = '';
|
||||
let count = 0;
|
||||
var zipped = zip(String(start), String(stop));
|
||||
var len = zipped.length, i = -1;
|
||||
|
||||
for (let i = 0; i < digits; i++) {
|
||||
let [startDigit, stopDigit] = zipped[i];
|
||||
var pattern = '';
|
||||
var digits = 0;
|
||||
|
||||
while (++i < len) {
|
||||
var numbers = zipped[i];
|
||||
var startDigit = numbers[0];
|
||||
var stopDigit = numbers[1];
|
||||
|
||||
if (startDigit === stopDigit) {
|
||||
pattern += startDigit;
|
||||
|
||||
} else if (startDigit !== '0' || stopDigit !== '9') {
|
||||
pattern += toCharacterClass(startDigit, stopDigit, options);
|
||||
pattern += toCharacterClass(startDigit, stopDigit);
|
||||
|
||||
} else {
|
||||
count++;
|
||||
digits += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (count) {
|
||||
pattern += options.shorthand === true ? '\\d' : '[0-9]';
|
||||
if (digits) {
|
||||
pattern += options.shorthand ? '\\d' : '[0-9]';
|
||||
}
|
||||
|
||||
return { pattern, count: [count], digits };
|
||||
return { pattern: pattern, digits: [digits] };
|
||||
}
|
||||
|
||||
function splitToPatterns(min, max, tok, options) {
|
||||
let ranges = splitToRanges(min, max);
|
||||
let tokens = [];
|
||||
let start = min;
|
||||
let prev;
|
||||
var ranges = splitToRanges(min, max);
|
||||
var len = ranges.length;
|
||||
var idx = -1;
|
||||
|
||||
for (let i = 0; i < ranges.length; i++) {
|
||||
let max = ranges[i];
|
||||
let obj = rangeToPattern(String(start), String(max), options);
|
||||
let zeros = '';
|
||||
var tokens = [];
|
||||
var start = min;
|
||||
var prev;
|
||||
|
||||
while (++idx < len) {
|
||||
var range = ranges[idx];
|
||||
var obj = rangeToPattern(start, range, options);
|
||||
var zeros = '';
|
||||
|
||||
if (!tok.isPadded && prev && prev.pattern === obj.pattern) {
|
||||
if (prev.count.length > 1) {
|
||||
prev.count.pop();
|
||||
if (prev.digits.length > 1) {
|
||||
prev.digits.pop();
|
||||
}
|
||||
|
||||
prev.count.push(obj.count[0]);
|
||||
prev.string = prev.pattern + toQuantifier(prev.count);
|
||||
start = max + 1;
|
||||
prev.digits.push(obj.digits[0]);
|
||||
prev.string = prev.pattern + toQuantifier(prev.digits);
|
||||
start = range + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tok.isPadded) {
|
||||
zeros = padZeros(max, tok, options);
|
||||
zeros = padZeros(range, tok);
|
||||
}
|
||||
|
||||
obj.string = zeros + obj.pattern + toQuantifier(obj.count);
|
||||
obj.string = zeros + obj.pattern + toQuantifier(obj.digits);
|
||||
tokens.push(obj);
|
||||
start = max + 1;
|
||||
start = range + 1;
|
||||
prev = obj;
|
||||
}
|
||||
|
||||
@@ -193,31 +191,40 @@ function splitToPatterns(min, max, tok, options) {
|
||||
}
|
||||
|
||||
function filterPatterns(arr, comparison, prefix, intersection, options) {
|
||||
let result = [];
|
||||
var res = [];
|
||||
|
||||
for (let ele of arr) {
|
||||
let { string } = ele;
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var tok = arr[i];
|
||||
var ele = tok.string;
|
||||
|
||||
// only push if _both_ are negative...
|
||||
if (!intersection && !contains(comparison, 'string', string)) {
|
||||
result.push(prefix + string);
|
||||
if (options.relaxZeros !== false) {
|
||||
if (prefix === '-' && ele.charAt(0) === '0') {
|
||||
if (ele.charAt(1) === '{') {
|
||||
ele = '0*' + ele.replace(/^0\{\d+\}/, '');
|
||||
} else {
|
||||
ele = '0*' + ele.slice(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// or _both_ are positive
|
||||
if (intersection && contains(comparison, 'string', string)) {
|
||||
result.push(prefix + string);
|
||||
if (!intersection && !contains(comparison, 'string', ele)) {
|
||||
res.push(prefix + ele);
|
||||
}
|
||||
|
||||
if (intersection && contains(comparison, 'string', ele)) {
|
||||
res.push(prefix + ele);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zip strings
|
||||
* Zip strings (`for in` can be used on string characters)
|
||||
*/
|
||||
|
||||
function zip(a, b) {
|
||||
let arr = [];
|
||||
for (let i = 0; i < a.length; i++) arr.push([a[i], b[i]]);
|
||||
var arr = [];
|
||||
for (var ch in a) arr.push([a[ch], b[ch]]);
|
||||
return arr;
|
||||
}
|
||||
|
||||
@@ -225,12 +232,22 @@ function compare(a, b) {
|
||||
return a > b ? 1 : b > a ? -1 : 0;
|
||||
}
|
||||
|
||||
function push(arr, ele) {
|
||||
if (arr.indexOf(ele) === -1) arr.push(ele);
|
||||
return arr;
|
||||
}
|
||||
|
||||
function contains(arr, key, val) {
|
||||
return arr.some(ele => ele[key] === val);
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (arr[i][key] === val) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function countNines(min, len) {
|
||||
return Number(String(min).slice(0, -len) + '9'.repeat(len));
|
||||
return String(min).slice(0, -len) + repeat('9', len);
|
||||
}
|
||||
|
||||
function countZeros(integer, zeros) {
|
||||
@@ -238,49 +255,38 @@ function countZeros(integer, zeros) {
|
||||
}
|
||||
|
||||
function toQuantifier(digits) {
|
||||
let [start = 0, stop = ''] = digits;
|
||||
if (stop || start > 1) {
|
||||
return `{${start + (stop ? ',' + stop : '')}}`;
|
||||
var start = digits[0];
|
||||
var stop = digits[1] ? (',' + digits[1]) : '';
|
||||
if (!stop && (!start || start === 1)) {
|
||||
return '';
|
||||
}
|
||||
return '';
|
||||
return '{' + start + stop + '}';
|
||||
}
|
||||
|
||||
function toCharacterClass(a, b, options) {
|
||||
return `[${a}${(b - a === 1) ? '' : '-'}${b}]`;
|
||||
function toCharacterClass(a, b) {
|
||||
return '[' + a + ((b - a === 1) ? '' : '-') + b + ']';
|
||||
}
|
||||
|
||||
function hasPadding(str) {
|
||||
return /^-?(0+)\d/.test(str);
|
||||
function padding(str) {
|
||||
return /^-?(0+)\d/.exec(str);
|
||||
}
|
||||
|
||||
function padZeros(value, tok, options) {
|
||||
if (!tok.isPadded) {
|
||||
return value;
|
||||
}
|
||||
|
||||
let diff = Math.abs(tok.maxLen - String(value).length);
|
||||
let relax = options.relaxZeros !== false;
|
||||
|
||||
switch (diff) {
|
||||
case 0:
|
||||
return '';
|
||||
case 1:
|
||||
return relax ? '0?' : '0';
|
||||
case 2:
|
||||
return relax ? '0{0,2}' : '00';
|
||||
default: {
|
||||
return relax ? `0{0,${diff}}` : `0{${diff}}`;
|
||||
function padZeros(val, tok) {
|
||||
if (tok.isPadded) {
|
||||
var diff = Math.abs(tok.maxLen - String(val).length);
|
||||
switch (diff) {
|
||||
case 0:
|
||||
return '';
|
||||
case 1:
|
||||
return '0';
|
||||
default: {
|
||||
return '0{' + diff + '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache
|
||||
*/
|
||||
|
||||
toRegexRange.cache = {};
|
||||
toRegexRange.clearCache = () => (toRegexRange.cache = {});
|
||||
|
||||
/**
|
||||
* Expose `toRegexRange`
|
||||
*/
|
||||
|
||||
68
node_modules/to-regex-range/package.json
generated
vendored
68
node_modules/to-regex-range/package.json
generated
vendored
@@ -1,13 +1,9 @@
|
||||
{
|
||||
"name": "to-regex-range",
|
||||
"description": "Pass two numbers, get a regex-compatible source string for matching ranges. Validated against more than 2.78 million test assertions.",
|
||||
"version": "5.0.1",
|
||||
"version": "2.1.1",
|
||||
"homepage": "https://github.com/micromatch/to-regex-range",
|
||||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
||||
"contributors": [
|
||||
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
|
||||
"Rouven Weßling (www.rouvenwessling.de)"
|
||||
],
|
||||
"repository": "micromatch/to-regex-range",
|
||||
"bugs": {
|
||||
"url": "https://github.com/micromatch/to-regex-range/issues"
|
||||
@@ -18,49 +14,56 @@
|
||||
],
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=8.0"
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"dependencies": {
|
||||
"is-number": "^7.0.0"
|
||||
"is-number": "^3.0.0",
|
||||
"repeat-string": "^1.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"fill-range": "^6.0.0",
|
||||
"gulp-format-md": "^2.0.0",
|
||||
"mocha": "^6.0.2",
|
||||
"fill-range": "^3.1.1",
|
||||
"gulp-format-md": "^0.1.12",
|
||||
"mocha": "^3.2.0",
|
||||
"text-table": "^0.2.0",
|
||||
"time-diff": "^0.3.1"
|
||||
},
|
||||
"keywords": [
|
||||
"alpha",
|
||||
"alphabetical",
|
||||
"bash",
|
||||
"brace",
|
||||
"date",
|
||||
"expand",
|
||||
"expansion",
|
||||
"expression",
|
||||
"glob",
|
||||
"match",
|
||||
"match date",
|
||||
"match number",
|
||||
"match numbers",
|
||||
"match year",
|
||||
"matches",
|
||||
"matching",
|
||||
"number",
|
||||
"numbers",
|
||||
"numerical",
|
||||
"range",
|
||||
"ranges",
|
||||
"regex",
|
||||
"regexp",
|
||||
"regular",
|
||||
"regular expression",
|
||||
"sequence"
|
||||
"sequence",
|
||||
"sh",
|
||||
"to",
|
||||
"year"
|
||||
],
|
||||
"verb": {
|
||||
"layout": "default",
|
||||
"related": {
|
||||
"list": [
|
||||
"expand-range",
|
||||
"fill-range",
|
||||
"micromatch",
|
||||
"repeat-element",
|
||||
"repeat-string"
|
||||
]
|
||||
},
|
||||
"toc": false,
|
||||
"layout": "default",
|
||||
"tasks": [
|
||||
"readme"
|
||||
],
|
||||
@@ -70,19 +73,14 @@
|
||||
"lint": {
|
||||
"reflinks": true
|
||||
},
|
||||
"helpers": {
|
||||
"examples": {
|
||||
"displayName": "examples"
|
||||
}
|
||||
},
|
||||
"related": {
|
||||
"list": [
|
||||
"expand-range",
|
||||
"fill-range",
|
||||
"micromatch",
|
||||
"repeat-element",
|
||||
"repeat-string"
|
||||
]
|
||||
}
|
||||
"helpers": [
|
||||
"./examples.js"
|
||||
],
|
||||
"reflinks": [
|
||||
"0-5",
|
||||
"0-9",
|
||||
"1-5",
|
||||
"1-9"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user