expand-range
Advanced tools
Comparing version 1.8.2 to 2.0.0
41
index.js
/*! | ||
* expand-range <https://github.com/jonschlinkert/expand-range> | ||
* | ||
* Copyright (c) 2014-2015, Jon Schlinkert. | ||
* Licensed under the MIT license. | ||
* Copyright (c) 2014-2015, 2017, Jon Schlinkert. | ||
* Released under the MIT License. | ||
*/ | ||
@@ -10,2 +10,3 @@ | ||
var extend = require('extend-shallow'); | ||
var fill = require('fill-range'); | ||
@@ -20,26 +21,36 @@ | ||
fn = options; | ||
options = {}; | ||
options = undefined; | ||
} | ||
// shallow clone options, to ensure we | ||
// don't mutate the object upstream | ||
var opts = extend({}, options); | ||
if (typeof fn === 'function') { | ||
opts.transform = fn; | ||
} | ||
if (typeof options === 'boolean') { | ||
options = {}; | ||
options.makeRe = true; | ||
opts.makeRe = true; | ||
} | ||
// create arguments to pass to fill-range | ||
var opts = options || {}; | ||
var args = str.split('..'); | ||
var len = args.length; | ||
var segs = str.split('..'); | ||
var len = segs.length; | ||
if (len > 3) { return str; } | ||
// if only one argument, it can't expand so return it | ||
if (len === 1) { return args; } | ||
// if only one segment, it can't expand so return it | ||
if (len === 1) { return segs; } | ||
// if `true`, tell fill-range to regexify the string | ||
if (typeof fn === 'boolean' && fn === true) { | ||
opts.makeRe = true; | ||
// if fn is "true", tell fill-range to regexify the string | ||
if (fn === true) { | ||
opts.toRegex = true; | ||
fn = undefined; | ||
} | ||
args.push(opts); | ||
return fill.apply(null, args.concat(fn)); | ||
// wrap the result in parentheses, when regexified and necessary | ||
opts.capture = true; | ||
segs.push(opts); | ||
return fill.apply(null, segs); | ||
}; |
{ | ||
"name": "expand-range", | ||
"description": "Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. See the benchmarks. Used by micromatch.", | ||
"version": "1.8.2", | ||
"description": "Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used by [micromatch].", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/jonschlinkert/expand-range", | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"contributors": [ | ||
"Daniel Cohen (http://dcb.co.il)", | ||
"Jon Schlinkert (http://twitter.com/jonschlinkert)" | ||
], | ||
"repository": "jonschlinkert/expand-range", | ||
@@ -23,11 +27,11 @@ "bugs": { | ||
"dependencies": { | ||
"fill-range": "^2.1.0" | ||
"fill-range": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"benchmarked": "^0.2.4", | ||
"brace-expansion": "^1.1.4", | ||
"glob": "^7.0.3", | ||
"gulp-format-md": "^0.1.9", | ||
"minimatch": "^3.0.0", | ||
"mocha": "^2.4.5" | ||
"benchmarked": "^1.1.1", | ||
"brace-expansion": "^1.1.7", | ||
"glob": "^7.1.1", | ||
"gulp-format-md": "^0.1.12", | ||
"minimatch": "^3.0.4", | ||
"mocha": "^3.3.0" | ||
}, | ||
@@ -56,3 +60,5 @@ "keywords": [ | ||
"reflinks": [ | ||
"verb" | ||
"verb", | ||
"fill-range", | ||
"micromatch" | ||
], | ||
@@ -69,5 +75,5 @@ "toc": false, | ||
"list": [ | ||
"micromatch", | ||
"braces", | ||
"fill-range", | ||
"braces" | ||
"micromatch" | ||
] | ||
@@ -74,0 +80,0 @@ } |
119
README.md
@@ -1,4 +0,4 @@ | ||
# expand-range [![NPM version](https://img.shields.io/npm/v/expand-range.svg?style=flat)](https://www.npmjs.com/package/expand-range) [![NPM downloads](https://img.shields.io/npm/dm/expand-range.svg?style=flat)](https://npmjs.org/package/expand-range) [![Build Status](https://img.shields.io/travis/jonschlinkert/expand-range.svg?style=flat)](https://travis-ci.org/jonschlinkert/expand-range) | ||
# expand-range [![NPM version](https://img.shields.io/npm/v/expand-range.svg?style=flat)](https://www.npmjs.com/package/expand-range) [![NPM monthly downloads](https://img.shields.io/npm/dm/expand-range.svg?style=flat)](https://npmjs.org/package/expand-range) [![NPM total downloads](https://img.shields.io/npm/dt/expand-range.svg?style=flat)](https://npmjs.org/package/expand-range) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/expand-range.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/expand-range) | ||
Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. See the benchmarks. Used by micromatch. | ||
> Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used by [micromatch](https://github.com/jonschlinkert/micromatch). | ||
@@ -10,7 +10,5 @@ ## Install | ||
```sh | ||
$ npm install expand-range --save | ||
$ npm install --save expand-range | ||
``` | ||
Wraps [fill-range] to do range expansion using `..` separated strings. See [fill-range] for the full list of options and features. | ||
## Example usage | ||
@@ -20,2 +18,7 @@ | ||
var expand = require('expand-range'); | ||
expand('start..end..step', options); | ||
// examples | ||
console.log(expand('1..3')) //=> ['1', '2', '3'] | ||
console.log(expand('1..10..3')) //=> [ '1', '4', '7', '10' ] | ||
``` | ||
@@ -25,10 +28,9 @@ | ||
```js | ||
expand(start, stop, increment); | ||
``` | ||
* `start`: the number or letter to start with | ||
* `end`: the number or letter to end with | ||
* `increment`: optionally pass the increment to use. works for letters or numbers | ||
* `step`: (optional) the step/increment to use. works with letters and numbers. | ||
* `options`: Options object to pass to [fill-range](https://github.com/jonschlinkert/fill-range), or a transform function (see [fill-range](https://github.com/jonschlinkert/fill-range) readme for details and documentation) | ||
This library wraps [fill-range](https://github.com/jonschlinkert/fill-range) to support range expansion using `..` separated strings. See [fill-range](https://github.com/jonschlinkert/fill-range) for the full list of options and features. | ||
**Examples** | ||
@@ -79,58 +81,85 @@ | ||
```sh | ||
Benchmarking: (4 of 4) | ||
· alpha-lower | ||
· alpha-upper | ||
· padded | ||
· range | ||
# benchmark/fixtures/alpha-lower.js (29 bytes) | ||
brace-expansion x 145,653 ops/sec ±0.89% (87 runs sampled) | ||
expand-range x 453,213 ops/sec ±1.66% (85 runs sampled) | ||
minimatch x 152,193 ops/sec ±1.17% (86 runs sampled) | ||
brace-expansion x 105,234 ops/sec ±0.65% (87 runs sampled) | ||
expand-range x 364,206 ops/sec ±1.08% (90 runs sampled) | ||
minimatch x 93,343 ops/sec ±1.61% (86 runs sampled) | ||
fastest is expand-range | ||
# benchmark/fixtures/alpha-upper.js (29 bytes) | ||
brace-expansion x 149,975 ops/sec ±1.10% (88 runs sampled) | ||
expand-range x 459,390 ops/sec ±1.27% (84 runs sampled) | ||
minimatch x 155,253 ops/sec ±1.25% (88 runs sampled) | ||
brace-expansion x 94,729 ops/sec ±0.49% (89 runs sampled) | ||
expand-range x 347,926 ops/sec ±1.11% (83 runs sampled) | ||
minimatch x 89,997 ops/sec ±1.10% (87 runs sampled) | ||
fastest is expand-range | ||
# benchmark/fixtures/padded.js (33 bytes) | ||
brace-expansion x 14,694 ops/sec ±1.37% (85 runs sampled) | ||
expand-range x 169,393 ops/sec ±1.76% (80 runs sampled) | ||
minimatch x 15,052 ops/sec ±1.15% (88 runs sampled) | ||
brace-expansion x 9,948 ops/sec ±0.99% (85 runs sampled) | ||
expand-range x 209,741 ops/sec ±8.85% (83 runs sampled) | ||
minimatch x 9,125 ops/sec ±0.95% (85 runs sampled) | ||
fastest is expand-range | ||
# benchmark/fixtures/range.js (29 bytes) | ||
brace-expansion x 142,968 ops/sec ±1.35% (86 runs sampled) | ||
expand-range x 465,579 ops/sec ±1.43% (86 runs sampled) | ||
minimatch x 126,872 ops/sec ±1.18% (90 runs sampled) | ||
brace-expansion x 75,911 ops/sec ±1.63% (85 runs sampled) | ||
expand-range x 525,728 ops/sec ±1.63% (85 runs sampled) | ||
minimatch x 69,066 ops/sec ±0.55% (86 runs sampled) | ||
fastest is expand-range | ||
``` | ||
## Related projects | ||
## History | ||
You might also be interested in these projects: | ||
### v2.0.0 | ||
* [braces](https://www.npmjs.com/package/braces): Fastest brace expansion for node.js, with the most complete support for the Bash 4.3 braces… [more](https://www.npmjs.com/package/braces) | [homepage](https://github.com/jonschlinkert/braces) | ||
* [fill-range](https://www.npmjs.com/package/fill-range): Fill in a range of numbers or letters, optionally passing an increment or multiplier to… [more](https://www.npmjs.com/package/fill-range) | [homepage](https://github.com/jonschlinkert/fill-range) | ||
* [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) | ||
**Changes** | ||
## Contributing | ||
* Special `step` characters are no longer supported, as the same thing can be accomplished with a custom transform function. | ||
* The signature in the [transform function](https://github.com/jonschlinkert/fill-range#optionstransform) has changed. See [fill-range](https://github.com/jonschlinkert/fill-range) for more details. | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/expand-range/issues/new). | ||
## About | ||
## Building docs | ||
### Related projects | ||
Generate readme and API documentation with [verb](https://github.com/verbose/verb): | ||
* [braces](https://www.npmjs.com/package/braces): Fast, comprehensive, bash-like brace expansion implemented in JavaScript. Complete support for the Bash 4.3 braces… [more](https://github.com/micromatch/braces) | [homepage](https://github.com/micromatch/braces "Fast, comprehensive, bash-like brace expansion implemented in JavaScript. Complete support for the Bash 4.3 braces specification, without sacrificing speed.") | ||
* [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.") | ||
```sh | ||
$ npm install verb && npm run docs | ||
``` | ||
### Contributing | ||
Or, if [verb](https://github.com/verbose/verb) is installed globally: | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). | ||
### Contributors | ||
| **Commits** | **Contributor** | | ||
| --- | --- | | ||
| 58 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 1 | [dcohenb](https://github.com/dcohenb) | | ||
### 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.)_ | ||
To generate the readme, run the following command: | ||
```sh | ||
$ verb | ||
$ npm install -g verbose/verb#dev verb-generate-readme && verb | ||
``` | ||
## Running tests | ||
### Running tests | ||
Install dev dependencies: | ||
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 -d && npm test | ||
$ npm install && npm test | ||
``` | ||
## Author | ||
### Author | ||
@@ -140,11 +169,11 @@ **Jon Schlinkert** | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert) | ||
## License | ||
### License | ||
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT license](https://github.com/jonschlinkert/expand-range/blob/master/LICENSE). | ||
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT License](LICENSE). | ||
*** | ||
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on May 05, 2016._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 08, 2017._ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10244
42
174
+ Addedextend-shallow@2.0.1(transitive)
+ Addedfill-range@4.0.0(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedis-number@3.0.0(transitive)
+ Addedto-regex-range@2.1.1(transitive)
- Removedfill-range@2.2.4(transitive)
- Removedis-number@2.1.04.0.0(transitive)
- Removedisarray@1.0.0(transitive)
- Removedisobject@2.1.0(transitive)
- Removedkind-of@6.0.3(transitive)
- Removedmath-random@1.0.4(transitive)
- Removedrandomatic@3.1.1(transitive)
- Removedrepeat-element@1.1.4(transitive)
Updatedfill-range@^4.0.0