UNPKG

5.76 kBMarkdownView Raw
1# 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)
2
3> Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used by micromatch.
4
5Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
6
7## Install
8
9Install with [npm](https://www.npmjs.com/):
10
11```sh
12$ npm install --save expand-range
13```
14
15## Example usage
16
17```js
18var expand = require('expand-range');
19expand('start..end..step', options);
20
21// examples
22console.log(expand('1..3')) //=> ['1', '2', '3']
23console.log(expand('1..10..3')) //=> [ '1', '4', '7', '10' ]
24```
25
26**Params**
27
28* `start`: the number or letter to start with
29* `end`: the number or letter to end with
30* `step`: (optional) the step/increment to use. works with letters and numbers.
31* `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)
32
33This 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.
34
35**Examples**
36
37```js
38expand('a..e')
39//=> ['a', 'b', 'c', 'd', 'e']
40
41expand('a..e..2')
42//=> ['a', 'c', 'e']
43
44expand('A..E..2')
45//=> ['A', 'C', 'E']
46
47expand('1..3')
48//=> ['1', '2', '3']
49
50expand('0..-5')
51//=> [ '0', '-1', '-2', '-3', '-4', '-5' ]
52
53expand('-9..9..3')
54//=> [ '-9', '-6', '-3', '0', '3', '6', '9' ])
55
56expand('-1..-10..-2')
57//=> [ '-1', '-3', '-5', '-7', '-9' ]
58
59expand('1..10..2')
60//=> [ '1', '3', '5', '7', '9' ]
61```
62
63### Custom function
64
65Optionally pass a custom function as the second argument:
66
67```js
68expand('a..e', function (val, isNumber, pad, i) {
69 if (!isNumber) {
70 return String.fromCharCode(val) + i;
71 }
72 return val;
73});
74//=> ['a0', 'b1', 'c2', 'd3', 'e4']
75```
76
77## Benchmarks
78
79```sh
80[object Object]
81```
82
83## History
84
85### v2.0.0
86
87**Changes**
88
89* Special `step` characters are no longer supported, as the same thing can be accomplished with a custom transform function.
90* 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.
91
92## About
93
94<details>
95<summary><strong>Contributing</strong></summary>
96
97Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
98
99</details>
100
101<details>
102<summary><strong>Running Tests</strong></summary>
103
104Running 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:
105
106```sh
107$ npm install && npm test
108```
109
110</details>
111
112<details>
113<summary><strong>Building docs</strong></summary>
114
115_(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.)_
116
117To generate the readme, run the following command:
118
119```sh
120$ npm install -g verbose/verb#dev verb-generate-readme && verb
121```
122
123</details>
124
125### Related projects
126
127You might also be interested in these projects:
128
129* [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.")
130* [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`")
131* [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.")
132
133### Contributors
134
135| **Commits** | **Contributor** |
136| --- | --- |
137| 65 | [jonschlinkert](https://github.com/jonschlinkert) |
138| 1 | [dcohenb](https://github.com/dcohenb) |
139| 1 | [stevelacy](https://github.com/stevelacy) |
140
141### Author
142
143**Jon Schlinkert**
144
145* [GitHub Profile](https://github.com/jonschlinkert)
146* [Twitter Profile](https://twitter.com/jonschlinkert)
147* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
148
149### License
150
151Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
152Released under the [MIT License](LICENSE).
153
154***
155
156_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on November 26, 2018._
\No newline at end of file