1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | var extend = require('extend-shallow');
|
11 | var fill = require('fill-range');
|
12 |
|
13 | module.exports = function expandRange(str, options, fn) {
|
14 | if (typeof str !== 'string') {
|
15 | throw new TypeError('expand-range expects a string.');
|
16 | }
|
17 |
|
18 | if (typeof options === 'function') {
|
19 | fn = options;
|
20 | options = undefined;
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 | var opts = extend({}, options);
|
26 |
|
27 | if (typeof fn === 'function') {
|
28 | opts.transform = fn;
|
29 | }
|
30 |
|
31 | if (typeof options === 'boolean') {
|
32 | opts.makeRe = true;
|
33 | }
|
34 |
|
35 |
|
36 | var segs = str.split('..');
|
37 | var len = segs.length;
|
38 | if (len > 3) { return str; }
|
39 |
|
40 |
|
41 | if (len === 1) { return segs; }
|
42 |
|
43 |
|
44 | if (fn === true) {
|
45 | opts.toRegex = true;
|
46 | fn = undefined;
|
47 | }
|
48 |
|
49 |
|
50 | opts.capture = true;
|
51 | segs.push(opts);
|
52 |
|
53 | return fill.apply(null, segs);
|
54 | };
|