-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
54 lines (42 loc) · 1.21 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*!
* expand-range <https://github.com/jonschlinkert/expand-range>
*
* Copyright (c) 2014-2015, 2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
var extend = require('extend-shallow');
var fill = require('fill-range');
module.exports = function expandRange(str, options, fn) {
if (typeof str !== 'string') {
throw new TypeError('expand-range expects a string.');
}
if (typeof options === 'function') {
fn = options;
options = undefined;
}
// shallow clone options, to ensure we
// don't mutate the object upstream
var opts = extend({}, options);
if (typeof fn === 'function') {
opts.transform = fn;
}
if (typeof options === 'boolean') {
opts.makeRe = true;
}
// create arguments to pass to fill-range
var segs = str.split('..');
var len = segs.length;
if (len > 3) { return str; }
// if only one segment, it can't expand so return it
if (len === 1) { return segs; }
// if fn is "true", tell fill-range to regexify the string
if (fn === true) {
opts.toRegex = true;
fn = undefined;
}
// wrap the result in parentheses, when regexified and necessary
opts.capture = true;
segs.push(opts);
return fill.apply(null, segs);
};