MCPcopy
hub / github.com/shelljs/shelljs / expand

Function expand

src/common.js:297–326  ·  view source on GitHub ↗
(list)

Source from the content-addressed store, hash-verified

295// expand(['file*.js']) = ['file1.js', 'file2.js', ...]
296// (if the files 'file1.js', 'file2.js', etc, exist in the current dir)
297function expand(list) {
298 if (!Array.isArray(list)) {
299 throw new TypeError('must be an array');
300 }
301 var expanded = [];
302 list.forEach(function (listEl) {
303 // Don't expand non-strings
304 if (typeof listEl !== 'string') {
305 expanded.push(listEl);
306 } else {
307 var ret;
308 var globOpts = globOptions();
309 try {
310 ret = glob.sync(listEl, globOpts);
311 } catch (e) {
312 // if glob fails, interpret the string literally
313 ret = [listEl];
314 }
315 // if nothing matched, interpret the string literally
316 ret = ret.length > 0 ? ret.sort() : [listEl];
317 if (globOpts.nodir) {
318 ret = ret.filter(function (file) {
319 return !statNoFollowLinks(file).isDirectory();
320 });
321 }
322 expanded = expanded.concat(ret);
323 }
324 });
325 return expanded;
326}
327exports.expand = expand;
328
329// Normalizes Buffer creation, using Buffer.alloc if possible.

Callers 1

wrapFunction · 0.85

Calls 2

globOptionsFunction · 0.85
statNoFollowLinksFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…