expand-range
Version:
Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used by micromatch.
156 lines (102 loc) • 5.76 kB
Markdown
# expand-range [](https://www.npmjs.com/package/expand-range) [](https://npmjs.org/package/expand-range) [](https://npmjs.org/package/expand-range) [](https://travis-ci.org/jonschlinkert/expand-range)
> Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used by micromatch.
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save expand-range
```
## Example usage
```js
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' ]
```
**Params**
* `start`: the number or letter to start with
* `end`: the number or letter to end with
* `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**
```js
expand('a..e')
//=> ['a', 'b', 'c', 'd', 'e']
expand('a..e..2')
//=> ['a', 'c', 'e']
expand('A..E..2')
//=> ['A', 'C', 'E']
expand('1..3')
//=> ['1', '2', '3']
expand('0..-5')
//=> [ '0', '-1', '-2', '-3', '-4', '-5' ]
expand('-9..9..3')
//=> [ '-9', '-6', '-3', '0', '3', '6', '9' ])
expand('-1..-10..-2')
//=> [ '-1', '-3', '-5', '-7', '-9' ]
expand('1..10..2')
//=> [ '1', '3', '5', '7', '9' ]
```
### Custom function
Optionally pass a custom function as the second argument:
```js
expand('a..e', function (val, isNumber, pad, i) {
if (!isNumber) {
return String.fromCharCode(val) + i;
}
return val;
});
//=> ['a0', 'b1', 'c2', 'd3', 'e4']
```
## Benchmarks
```sh
[object Object]
```
## History
### v2.0.0
**Changes**
* 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.
## About
<details>
<summary><strong>Contributing</strong></summary>
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
</details>
<details>
<summary><strong>Running Tests</strong></summary>
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm install && npm test
```
</details>
<details>
<summary><strong>Building docs</strong></summary>
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
</details>
### Related projects
You might also be interested in these projects:
* [braces](https://www.npmjs.com/package/braces): Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support… [more](https://github.com/micromatch/braces) | [homepage](https://github.com/micromatch/braces "Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support for the Bash 4.3 braces specification, without sacrificing speed.")
* [fill-range](https://www.npmjs.com/package/fill-range): Fill in a range of numbers or letters, optionally passing an increment or `step` to… [more](https://github.com/jonschlinkert/fill-range) | [homepage](https://github.com/jonschlinkert/fill-range "Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`")
* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | [homepage](https://github.com/micromatch/micromatch "Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.")
### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 65 | [jonschlinkert](https://github.com/jonschlinkert) |
| 1 | [dcohenb](https://github.com/dcohenb) |
| 1 | [stevelacy](https://github.com/stevelacy) |
### Author
**Jon Schlinkert**
* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
### License
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 November 26, 2018._