.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / fill-range / README.md
1 # fill-range [![NPM version](https://img.shields.io/npm/v/fill-range.svg?style=flat)](https://www.npmjs.com/package/fill-range) [![NPM monthly downloads](https://img.shields.io/npm/dm/fill-range.svg?style=flat)](https://npmjs.org/package/fill-range) [![NPM total downloads](https://img.shields.io/npm/dt/fill-range.svg?style=flat)](https://npmjs.org/package/fill-range) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/fill-range.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/fill-range)
2
3 > Fill in a range of numbers or letters, optionally passing an increment or multiplier to use.
4
5 Please 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](#install)
8 - [Usage](#usage)
9   * [Invalid ranges](#invalid-ranges)
10   * [Custom function](#custom-function)
11   * [Special characters](#special-characters)
12     + [plus](#plus)
13     + [pipe and tilde](#pipe-and-tilde)
14     + [angle bracket](#angle-bracket)
15     + [question mark](#question-mark)
16 - [About](#about)
17
18 _(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
19
20 ## Install
21
22 Install with [npm](https://www.npmjs.com/):
23
24 ```sh
25 $ npm install --save fill-range
26 ```
27
28 ## Usage
29
30 ```js
31 var range = require('fill-range');
32
33 range('a', 'e');
34 //=> ['a', 'b', 'c', 'd', 'e']
35 ```
36
37 **Params**
38
39 ```js
40 range(start, stop, step, options, fn);
41 ```
42
43 * `start`: **{String|Number}** the number or letter to start with
44 * `end`: **{String|Number}** the number or letter to end with
45 * `step`: **{String|Number}** optionally pass the step to use. works for letters or numbers.
46 * `options`: **{Object}**:
47   - `makeRe`: return a regex-compatible string (still returned as an array for consistency)
48   - `step`: pass the step on the options as an alternative to passing it as an argument
49   - `silent`: `true` by default, set to false to throw errors for invalid ranges.
50 * `fn`: **{Function}** optionally [pass a function](#custom-function) to modify each character
51
52 **Examples**
53
54 ```js
55 range(1, 3)
56 //=> ['1', '2', '3']
57
58 range('1', '3')
59 //=> ['1', '2', '3']
60
61 range('0', '-5')
62 //=> [ '0', '-1', '-2', '-3', '-4', '-5' ]
63
64 range(-9, 9, 3)
65 //=> [ '-9', '-6', '-3', '0', '3', '6', '9' ])
66
67 range('-1', '-10', '-2')
68 //=> [ '-1', '-3', '-5', '-7', '-9' ]
69
70 range('1', '10', '2')
71 //=> [ '1', '3', '5', '7', '9' ]
72
73 range('a', 'e')
74 //=> ['a', 'b', 'c', 'd', 'e']
75
76 range('a', 'e', 2)
77 //=> ['a', 'c', 'e']
78
79 range('A', 'E', 2)
80 //=> ['A', 'C', 'E']
81 ```
82
83 ### Invalid ranges
84
85 When an invalid range is passed, `null` is returned.
86
87 ```js
88 range('1.1', '2');
89 //=> null
90
91 range('a', '2');
92 //=> null
93
94 range(1, 10, 'foo');
95 //=> null
96 ```
97
98 If you want errors to be throw, pass `silent: false` on the options:
99
100 ### Custom function
101
102 Optionally pass a custom function as the third or fourth argument:
103
104 ```js
105 range('a', 'e', function (val, isNumber, pad, i) {
106   if (!isNumber) {
107     return String.fromCharCode(val) + i;
108   }
109   return val;
110 });
111 //=> ['a0', 'b1', 'c2', 'd3', 'e4']
112 ```
113
114 ### Special characters
115
116 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.
117
118 ```js
119 range('a', 'z', SPECIAL_CHARACTER_HERE);
120 ```
121
122 **Supported characters**
123
124 * `+`: repeat the given string `n` times
125 * `|`: create a regex-ready string, instead of an array
126 * `>`: join values to single array element
127 * `?`: randomize the given pattern using [randomatic]
128
129 #### plus
130
131 Character: _(`+`)_
132
133 Repeat the first argument the number of times passed on the second argument.
134
135 **Examples:**
136
137 ```js
138 range('a', 3, '+');
139 //=> ['a', 'a', 'a']
140
141 range('abc', 2, '+');
142 //=> ['abc', 'abc']
143 ```
144
145 #### pipe and tilde
146
147 Characters: _(`|` and `~`)_
148
149 Creates a regex-capable string (either a logical `or` or a character class) from the expanded arguments.
150
151 **Examples:**
152
153 ```js
154 range('a', 'c', '|');
155 //=> ['(a|b|c)'
156
157 range('a', 'c', '~');
158 //=> ['[a-c]'
159
160 range('a', 'z', '|5');
161 //=> ['(a|f|k|p|u|z)'
162 ```
163
164 **Automatic separator correction**
165
166 To avoid this error:
167
168 > `Range out of order in character class`
169
170 Fill-range detects invalid sequences and uses the correct syntax. For example:
171
172 **invalid** (regex)
173
174 If you pass these:
175
176 ```js
177 range('a', 'z', '~5');
178 // which would result in this
179 //=> ['[a-f-k-p-u-z]']
180
181 range('10', '20', '~');
182 // which would result in this
183 //=> ['[10-20]']
184 ```
185
186 **valid** (regex)
187
188 fill-range corrects them to this:
189
190 ```js
191 range('a', 'z', '~5');
192 //=> ['(a|f|k|p|u|z)'
193
194 range('10', '20', '~');
195 //=> ['(10-20)'
196 ```
197
198 #### angle bracket
199
200 Character: _(`>`)_
201
202 Joins all values in the returned array to a single value.
203
204 **Examples:**
205
206 ```js
207 range('a', 'e', '>');
208 //=> ['abcde']
209
210 range('5', '8', '>');
211 //=> ['5678']
212
213 range('2', '20', '2>');
214 //=> ['2468101214161820']
215 ```
216
217 #### question mark
218
219 Character: _(`?`)_
220
221 Uses [randomatic] to generate randomized alpha, numeric, or alpha-numeric patterns based on the provided arguments.
222
223 **Examples:**
224
225 _(actual results would obviously be randomized)_
226
227 Generate a 5-character, uppercase, alphabetical string:
228
229 ```js
230 range('A', 5, '?');
231 //=> ['NSHAK']
232 ```
233
234 Generate a 5-digit random number:
235
236 ```js
237 range('0', 5, '?');
238 //=> ['36583']
239 ```
240
241 Generate a 10-character alpha-numeric string:
242
243 ```js
244 range('A0', 10, '?');
245 //=> ['5YJD60VQNN']
246 ```
247
248 See the [randomatic] repo for all available options and or to create issues or feature requests related to randomization.
249
250 ## About
251
252 <details>
253 <summary><strong>Contributing</strong></summary>
254
255 Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
256
257 </details>
258
259 <details>
260 <summary><strong>Running Tests</strong></summary>
261
262 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:
263
264 ```sh
265 $ npm install && npm test
266 ```
267
268 </details>
269
270 <details>
271 <summary><strong>Building docs</strong></summary>
272
273 _(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.)_
274
275 To generate the readme, run the following command:
276
277 ```sh
278 $ npm install -g verbose/verb#dev verb-generate-readme && verb
279 ```
280
281 </details>
282
283 ### Related projects
284
285 You might also be interested in these projects:
286
287 * [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.")
288 * [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].")
289 * [is-glob](https://www.npmjs.com/package/is-glob): Returns `true` if the given string looks like a glob pattern or an extglob pattern… [more](https://github.com/jonschlinkert/is-glob) | [homepage](https://github.com/jonschlinkert/is-glob "Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a bet")
290 * [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.")
291
292 ### Contributors
293
294 | **Commits** | **Contributor** | 
295 | --- | --- |
296 | 111 | [jonschlinkert](https://github.com/jonschlinkert) |
297 | 2 | [paulmillr](https://github.com/paulmillr) |
298 | 1 | [edorivai](https://github.com/edorivai) |
299 | 1 | [realityking](https://github.com/realityking) |
300 | 1 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |
301
302 ### Author
303
304 **Jon Schlinkert**
305
306 * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
307 * [GitHub Profile](https://github.com/jonschlinkert)
308 * [Twitter Profile](https://twitter.com/jonschlinkert)
309
310 ### License
311
312 Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
313 Released under the [MIT License](LICENSE).
314
315 ***
316
317 _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 08, 2018._