Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50654 views
1
2
// Turn something like {a,b{c,d},}x{e,f} into
3
// ["axe", "axf", "bcxe", "bcxf", "bdxe", "bdxf", "xe", "xf"]
4
// Only {,} groups are expanded. While in many cases {x,y} is
5
// functionally equivalent to @(x|y), for the purpose of globbing
6
// files, only {x,y} gets expanded as multiple patterns.
7
minimatch.patternSet = patternSet
8
function patternSet (pattern) {
9
if (!pattern.match(/{/) || !pattern.match(/}/)) {
10
// shortcut - no sets.
11
return [pattern]
12
}
13
14
// a{b,c{d,e},{f,g}h}x{y,z}
15
//
16
// t=[before set, set, after set]
17
// t=["a", ["b", "c{d,e}", "{f,g}h"], "x{y,z}"]
18
19
// start walking, and note the position of the first {
20
// and the corresponding }
21
var p = pattern.indexOf("{")
22
, l = pattern.length
23
, d = 0
24
, escaping = false
25
, inClass = false
26
while (++ p < l) {
27
switch (pattern.charAt(p)) {
28
case "{":
29
d ++
30
continue
31
case "}":
32
33
34
35
// t[2] = patternSet(t[2])
36
// t = [t[0]].concat([t[1].map(patternSet)]).concat([t[2]])
37
//
38
// t=["a",[["b"],[["cd","ce"]],[["fh","gh"]]],["xy","xz"]]
39
//
40
// // first turn into
41
// // [["ab"], ["acd", "ace"], ["afh", "agh"]]
42
// return t[1].map(function (p) {
43
// return p.map(function (p) {
44
// return t[0] + p
45
// })
46
// })
47
// // flatten into ["ab", "acd", "ace", "afh", "agh"]
48
// .reduce(function (l, r) {
49
// return l.concat(r)
50
// }, [])
51
// // tack all the endings onto each one
52
// .map(function (p) {
53
// return t[2].map(function (e) {
54
// return p + e
55
// })
56
// })
57
// // flatten again
58
// .reduce(function (l, r) {
59
// return l.concat(r)
60
// }, [])
61
}
62
63
64