brace-expansion 1.1.13 → 1.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +12 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -62,10 +62,13 @@ function parseCommaParts(str) {
62
62
  return parts;
63
63
  }
64
64
 
65
- function expandTop(str) {
65
+ function expandTop(str, options) {
66
66
  if (!str)
67
67
  return [];
68
68
 
69
+ options = options || {};
70
+ var max = options.max == null ? Infinity : options.max;
71
+
69
72
  // I don't know why Bash 4.3 does this, but it does.
70
73
  // Anything starting with {} will have the first two bytes preserved
71
74
  // but *only* at the top level, so {},a}b will not expand to anything,
@@ -76,7 +79,7 @@ function expandTop(str) {
76
79
  str = '\\{\\}' + str.substr(2);
77
80
  }
78
81
 
79
- return expand(escapeBraces(str), true).map(unescapeBraces);
82
+ return expand(escapeBraces(str), max, true).map(unescapeBraces);
80
83
  }
81
84
 
82
85
  function identity(e) {
@@ -97,7 +100,7 @@ function gte(i, y) {
97
100
  return i >= y;
98
101
  }
99
102
 
100
- function expand(str, isTop) {
103
+ function expand(str, max, isTop) {
101
104
  var expansions = [];
102
105
 
103
106
  var m = balanced('{', '}', str);
@@ -111,7 +114,7 @@ function expand(str, isTop) {
111
114
  // {a},b}
112
115
  if (m.post.match(/,(?!,).*\}/)) {
113
116
  str = m.pre + '{' + m.body + escClose + m.post;
114
- return expand(str);
117
+ return expand(str, max, true);
115
118
  }
116
119
  return [str];
117
120
  }
@@ -123,10 +126,10 @@ function expand(str, isTop) {
123
126
  n = parseCommaParts(m.body);
124
127
  if (n.length === 1) {
125
128
  // x{{a,b}}y ==> x{a}y x{b}y
126
- n = expand(n[0], false).map(embrace);
129
+ n = expand(n[0], max, false).map(embrace);
127
130
  if (n.length === 1) {
128
131
  var post = m.post.length
129
- ? expand(m.post, false)
132
+ ? expand(m.post, max, false)
130
133
  : [''];
131
134
  return post.map(function(p) {
132
135
  return m.pre + n[0] + p;
@@ -141,7 +144,7 @@ function expand(str, isTop) {
141
144
  // no need to expand pre, since it is guaranteed to be free of brace-sets
142
145
  var pre = m.pre;
143
146
  var post = m.post.length
144
- ? expand(m.post, false)
147
+ ? expand(m.post, max, false)
145
148
  : [''];
146
149
 
147
150
  var N;
@@ -185,11 +188,11 @@ function expand(str, isTop) {
185
188
  N.push(c);
186
189
  }
187
190
  } else {
188
- N = concatMap(n, function(el) { return expand(el, false) });
191
+ N = concatMap(n, function(el) { return expand(el, max, false) });
189
192
  }
190
193
 
191
194
  for (var j = 0; j < N.length; j++) {
192
- for (var k = 0; k < post.length; k++) {
195
+ for (var k = 0; k < post.length && expansions.length < max; k++) {
193
196
  var expansion = pre + N[j] + post[k];
194
197
  if (!isTop || isSequence || expansion)
195
198
  expansions.push(expansion);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "brace-expansion",
3
3
  "description": "Brace expansion as known from sh/bash",
4
- "version": "1.1.13",
4
+ "version": "1.1.14",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git://github.com/juliangruber/brace-expansion.git"