1 # fill-range [![NPM version](https://badge.fury.io/js/fill-range.svg)](http://badge.fury.io/js/fill-range) [![Build Status](https://travis-ci.org/jonschlinkert/fill-range.svg)](https://travis-ci.org/jonschlinkert/fill-range)
3 > Fill in a range of numbers or letters, optionally passing an increment or multiplier to use.
5 ## Install with [npm](npmjs.org)
8 npm i fill-range --save
14 * [Invalid ranges](#invalid-ranges)
15 * [Custom function](#custom-function)
16 * [Special characters](#special-characters)
18 + [pipe and tilde](#pipe-and-tilde)
19 + [angle bracket](#angle-bracket)
20 + [question mark](#question-mark)
21 - [Other useful libs](#other-useful-libs)
22 - [Running tests](#running-tests)
23 - [Contributing](#contributing)
27 _(Table of contents generated by [verb])_
34 var range = require('fill-range');
37 //=> ['a', 'b', 'c', 'd', 'e']
43 range(start, stop, step, options, fn);
46 - `start`: **{String|Number}** the number or letter to start with
47 - `end`: **{String|Number}** the number or letter to end with
48 - `step`: **{String|Number}** optionally pass the step to use. works for letters or numbers.
49 - `options`: **{Object}**:
50 + `makeRe`: return a regex-compatible string (still returned as an array for consistency)
51 + `step`: pass the step on the options as an alternative to passing it as an argument
52 + `silent`: `true` by default, set to false to throw errors for invalid ranges.
53 - `fn`: **{Function}** optionally [pass a function](#custom-function) to modify each character
66 //=> [ '0', '-1', '-2', '-3', '-4', '-5' ]
69 //=> [ '-9', '-6', '-3', '0', '3', '6', '9' ])
71 range('-1', '-10', '-2')
72 //=> [ '-1', '-3', '-5', '-7', '-9' ]
75 //=> [ '1', '3', '5', '7', '9' ]
78 //=> ['a', 'b', 'c', 'd', 'e']
89 When an invalid range is passed, `null` is returned.
102 If you want errors to be throw, pass `silent: false` on the options:
107 Optionally pass a custom function as the third or fourth argument:
110 range('a', 'e', function (val, isNumber, pad, i) {
112 return String.fromCharCode(val) + i;
116 //=> ['a0', 'b1', 'c2', 'd3', 'e4']
119 ### Special characters
121 A special character may be passed as the third arg instead of a step increment. These characters can be pretty useful for brace expansion, creating file paths, test fixtures and similar use case.
124 range('a', 'z', SPECIAL_CHARACTER_HERE);
127 **Supported characters**
129 - `+`: repeat the given string `n` times
130 - `|`: create a regex-ready string, instead of an array
131 - `>`: join values to single array element
132 - `?`: randomize the given pattern using [randomatic]
138 Repeat the first argument the number of times passed on the second argument.
146 range('abc', 2, '+');
152 Characters: _(`|` and `~`)_
154 Creates a regex-capable string (either a logical `or` or a character class) from the expanded arguments.
159 range('a', 'c', '|');
162 range('a', 'c', '~');
165 range('a', 'z', '|5');
166 //=> ['(a|f|k|p|u|z)'
169 **Automatic separator correction**
173 > `Range out of order in character class`
175 Fill-range detects invalid sequences and uses the correct syntax. For example:
182 range('a', 'z', '~5');
183 // which would result in this
184 //=> ['[a-f-k-p-u-z]']
186 range('10', '20', '~');
187 // which would result in this
193 fill-range corrects them to this:
196 range('a', 'z', '~5');
197 //=> ['(a|f|k|p|u|z)'
199 range('10', '20', '~');
207 Joins all values in the returned array to a single value.
212 range('a', 'e', '>');
215 range('5', '8', '>');
218 range('2', '20', '2>');
219 //=> ['2468101214161820']
227 Uses [randomatic] to generate randomized alpha, numeric, or alpha-numeric patterns based on the provided arguments.
231 _(actual results would obviously be randomized)_
233 Generate a 5-character, uppercase, alphabetical string:
240 Generate a 5-digit random number:
247 Generate a 10-character alpha-numeric string:
250 range('A0', 10, '?');
254 See the [randomatic] repo for all available options and or to create issues or feature requests related to randomization.
257 * [micromatch](https://github.com/jonschlinkert/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just use `micromatch.isMatch()` instead of `minimatch()`, or use `micromatch()` instead of `multimatch()`.
258 * [expand-range](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.
259 * [braces](https://github.com/jonschlinkert/braces): Fastest brace expansion for node.js, with the most complete support for the Bash 4.3 braces specification.
260 * [is-glob](https://github.com/jonschlinkert/is-glob): Returns `true` if the given string looks like a glob pattern.
263 Install dev dependencies:
270 Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/fill-range/issues)
276 + [github/jonschlinkert](https://github.com/jonschlinkert)
277 + [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
280 Copyright (c) 2014-2015 Jon Schlinkert
281 Released under the MIT license
285 _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on April 07, 2015._
287 [randomatic]: https://github.com/jonschlinkert/randomatic
288 [expand-range]: https://github.com/jonschlinkert/expand-range
289 [micromatch]: https://github.com/jonschlinkert/micromatch
290 [braces]: https://github.com/jonschlinkert/braces