Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80538 views
1
module.exports = minimatch
2
minimatch.Minimatch = Minimatch
3
4
var path = { sep: '/' }
5
try {
6
path = require('path')
7
} catch (er) {}
8
9
var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
10
var expand = require('brace-expansion')
11
12
// any single thing other than /
13
// don't need to escape / when using new RegExp()
14
var qmark = '[^/]'
15
16
// * => any number of characters
17
var star = qmark + '*?'
18
19
// ** when dots are allowed. Anything goes, except .. and .
20
// not (^ or / followed by one or two dots followed by $ or /),
21
// followed by anything, any number of times.
22
var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'
23
24
// not a ^ or / followed by a dot,
25
// followed by anything, any number of times.
26
var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'
27
28
// characters that need to be escaped in RegExp.
29
var reSpecials = charSet('().*{}+?[]^$\\!')
30
31
// "abc" -> { a:true, b:true, c:true }
32
function charSet (s) {
33
return s.split('').reduce(function (set, c) {
34
set[c] = true
35
return set
36
}, {})
37
}
38
39
// normalizes slashes.
40
var slashSplit = /\/+/
41
42
minimatch.filter = filter
43
function filter (pattern, options) {
44
options = options || {}
45
return function (p, i, list) {
46
return minimatch(p, pattern, options)
47
}
48
}
49
50
function ext (a, b) {
51
a = a || {}
52
b = b || {}
53
var t = {}
54
Object.keys(b).forEach(function (k) {
55
t[k] = b[k]
56
})
57
Object.keys(a).forEach(function (k) {
58
t[k] = a[k]
59
})
60
return t
61
}
62
63
minimatch.defaults = function (def) {
64
if (!def || !Object.keys(def).length) return minimatch
65
66
var orig = minimatch
67
68
var m = function minimatch (p, pattern, options) {
69
return orig.minimatch(p, pattern, ext(def, options))
70
}
71
72
m.Minimatch = function Minimatch (pattern, options) {
73
return new orig.Minimatch(pattern, ext(def, options))
74
}
75
76
return m
77
}
78
79
Minimatch.defaults = function (def) {
80
if (!def || !Object.keys(def).length) return Minimatch
81
return minimatch.defaults(def).Minimatch
82
}
83
84
function minimatch (p, pattern, options) {
85
if (typeof pattern !== 'string') {
86
throw new TypeError('glob pattern string required')
87
}
88
89
if (!options) options = {}
90
91
// shortcut: comments match nothing.
92
if (!options.nocomment && pattern.charAt(0) === '#') {
93
return false
94
}
95
96
// "" only matches ""
97
if (pattern.trim() === '') return p === ''
98
99
return new Minimatch(pattern, options).match(p)
100
}
101
102
function Minimatch (pattern, options) {
103
if (!(this instanceof Minimatch)) {
104
return new Minimatch(pattern, options)
105
}
106
107
if (typeof pattern !== 'string') {
108
throw new TypeError('glob pattern string required')
109
}
110
111
if (!options) options = {}
112
pattern = pattern.trim()
113
114
// windows support: need to use /, not \
115
if (path.sep !== '/') {
116
pattern = pattern.split(path.sep).join('/')
117
}
118
119
this.options = options
120
this.set = []
121
this.pattern = pattern
122
this.regexp = null
123
this.negate = false
124
this.comment = false
125
this.empty = false
126
127
// make the set of regexps etc.
128
this.make()
129
}
130
131
Minimatch.prototype.debug = function () {}
132
133
Minimatch.prototype.make = make
134
function make () {
135
// don't do it more than once.
136
if (this._made) return
137
138
var pattern = this.pattern
139
var options = this.options
140
141
// empty patterns and comments match nothing.
142
if (!options.nocomment && pattern.charAt(0) === '#') {
143
this.comment = true
144
return
145
}
146
if (!pattern) {
147
this.empty = true
148
return
149
}
150
151
// step 1: figure out negation, etc.
152
this.parseNegate()
153
154
// step 2: expand braces
155
var set = this.globSet = this.braceExpand()
156
157
if (options.debug) this.debug = console.error
158
159
this.debug(this.pattern, set)
160
161
// step 3: now we have a set, so turn each one into a series of path-portion
162
// matching patterns.
163
// These will be regexps, except in the case of "**", which is
164
// set to the GLOBSTAR object for globstar behavior,
165
// and will not contain any / characters
166
set = this.globParts = set.map(function (s) {
167
return s.split(slashSplit)
168
})
169
170
this.debug(this.pattern, set)
171
172
// glob --> regexps
173
set = set.map(function (s, si, set) {
174
return s.map(this.parse, this)
175
}, this)
176
177
this.debug(this.pattern, set)
178
179
// filter out everything that didn't compile properly.
180
set = set.filter(function (s) {
181
return s.indexOf(false) === -1
182
})
183
184
this.debug(this.pattern, set)
185
186
this.set = set
187
}
188
189
Minimatch.prototype.parseNegate = parseNegate
190
function parseNegate () {
191
var pattern = this.pattern
192
var negate = false
193
var options = this.options
194
var negateOffset = 0
195
196
if (options.nonegate) return
197
198
for (var i = 0, l = pattern.length
199
; i < l && pattern.charAt(i) === '!'
200
; i++) {
201
negate = !negate
202
negateOffset++
203
}
204
205
if (negateOffset) this.pattern = pattern.substr(negateOffset)
206
this.negate = negate
207
}
208
209
// Brace expansion:
210
// a{b,c}d -> abd acd
211
// a{b,}c -> abc ac
212
// a{0..3}d -> a0d a1d a2d a3d
213
// a{b,c{d,e}f}g -> abg acdfg acefg
214
// a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
215
//
216
// Invalid sets are not expanded.
217
// a{2..}b -> a{2..}b
218
// a{b}c -> a{b}c
219
minimatch.braceExpand = function (pattern, options) {
220
return braceExpand(pattern, options)
221
}
222
223
Minimatch.prototype.braceExpand = braceExpand
224
225
function braceExpand (pattern, options) {
226
if (!options) {
227
if (this instanceof Minimatch) {
228
options = this.options
229
} else {
230
options = {}
231
}
232
}
233
234
pattern = typeof pattern === 'undefined'
235
? this.pattern : pattern
236
237
if (typeof pattern === 'undefined') {
238
throw new Error('undefined pattern')
239
}
240
241
if (options.nobrace ||
242
!pattern.match(/\{.*\}/)) {
243
// shortcut. no need to expand.
244
return [pattern]
245
}
246
247
return expand(pattern)
248
}
249
250
// parse a component of the expanded set.
251
// At this point, no pattern may contain "/" in it
252
// so we're going to return a 2d array, where each entry is the full
253
// pattern, split on '/', and then turned into a regular expression.
254
// A regexp is made at the end which joins each array with an
255
// escaped /, and another full one which joins each regexp with |.
256
//
257
// Following the lead of Bash 4.1, note that "**" only has special meaning
258
// when it is the *only* thing in a path portion. Otherwise, any series
259
// of * is equivalent to a single *. Globstar behavior is enabled by
260
// default, and can be disabled by setting options.noglobstar.
261
Minimatch.prototype.parse = parse
262
var SUBPARSE = {}
263
function parse (pattern, isSub) {
264
var options = this.options
265
266
// shortcuts
267
if (!options.noglobstar && pattern === '**') return GLOBSTAR
268
if (pattern === '') return ''
269
270
var re = ''
271
var hasMagic = !!options.nocase
272
var escaping = false
273
// ? => one single character
274
var patternListStack = []
275
var plType
276
var stateChar
277
var inClass = false
278
var reClassStart = -1
279
var classStart = -1
280
// . and .. never match anything that doesn't start with .,
281
// even when options.dot is set.
282
var patternStart = pattern.charAt(0) === '.' ? '' // anything
283
// not (start or / followed by . or .. followed by / or end)
284
: options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))'
285
: '(?!\\.)'
286
var self = this
287
288
function clearStateChar () {
289
if (stateChar) {
290
// we had some state-tracking character
291
// that wasn't consumed by this pass.
292
switch (stateChar) {
293
case '*':
294
re += star
295
hasMagic = true
296
break
297
case '?':
298
re += qmark
299
hasMagic = true
300
break
301
default:
302
re += '\\' + stateChar
303
break
304
}
305
self.debug('clearStateChar %j %j', stateChar, re)
306
stateChar = false
307
}
308
}
309
310
for (var i = 0, len = pattern.length, c
311
; (i < len) && (c = pattern.charAt(i))
312
; i++) {
313
this.debug('%s\t%s %s %j', pattern, i, re, c)
314
315
// skip over any that are escaped.
316
if (escaping && reSpecials[c]) {
317
re += '\\' + c
318
escaping = false
319
continue
320
}
321
322
switch (c) {
323
case '/':
324
// completely not allowed, even escaped.
325
// Should already be path-split by now.
326
return false
327
328
case '\\':
329
clearStateChar()
330
escaping = true
331
continue
332
333
// the various stateChar values
334
// for the "extglob" stuff.
335
case '?':
336
case '*':
337
case '+':
338
case '@':
339
case '!':
340
this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c)
341
342
// all of those are literals inside a class, except that
343
// the glob [!a] means [^a] in regexp
344
if (inClass) {
345
this.debug(' in class')
346
if (c === '!' && i === classStart + 1) c = '^'
347
re += c
348
continue
349
}
350
351
// if we already have a stateChar, then it means
352
// that there was something like ** or +? in there.
353
// Handle the stateChar, then proceed with this one.
354
self.debug('call clearStateChar %j', stateChar)
355
clearStateChar()
356
stateChar = c
357
// if extglob is disabled, then +(asdf|foo) isn't a thing.
358
// just clear the statechar *now*, rather than even diving into
359
// the patternList stuff.
360
if (options.noext) clearStateChar()
361
continue
362
363
case '(':
364
if (inClass) {
365
re += '('
366
continue
367
}
368
369
if (!stateChar) {
370
re += '\\('
371
continue
372
}
373
374
plType = stateChar
375
patternListStack.push({ type: plType, start: i - 1, reStart: re.length })
376
// negation is (?:(?!js)[^/]*)
377
re += stateChar === '!' ? '(?:(?!' : '(?:'
378
this.debug('plType %j %j', stateChar, re)
379
stateChar = false
380
continue
381
382
case ')':
383
if (inClass || !patternListStack.length) {
384
re += '\\)'
385
continue
386
}
387
388
clearStateChar()
389
hasMagic = true
390
re += ')'
391
plType = patternListStack.pop().type
392
// negation is (?:(?!js)[^/]*)
393
// The others are (?:<pattern>)<type>
394
switch (plType) {
395
case '!':
396
re += '[^/]*?)'
397
break
398
case '?':
399
case '+':
400
case '*':
401
re += plType
402
break
403
case '@': break // the default anyway
404
}
405
continue
406
407
case '|':
408
if (inClass || !patternListStack.length || escaping) {
409
re += '\\|'
410
escaping = false
411
continue
412
}
413
414
clearStateChar()
415
re += '|'
416
continue
417
418
// these are mostly the same in regexp and glob
419
case '[':
420
// swallow any state-tracking char before the [
421
clearStateChar()
422
423
if (inClass) {
424
re += '\\' + c
425
continue
426
}
427
428
inClass = true
429
classStart = i
430
reClassStart = re.length
431
re += c
432
continue
433
434
case ']':
435
// a right bracket shall lose its special
436
// meaning and represent itself in
437
// a bracket expression if it occurs
438
// first in the list. -- POSIX.2 2.8.3.2
439
if (i === classStart + 1 || !inClass) {
440
re += '\\' + c
441
escaping = false
442
continue
443
}
444
445
// handle the case where we left a class open.
446
// "[z-a]" is valid, equivalent to "\[z-a\]"
447
if (inClass) {
448
// split where the last [ was, make sure we don't have
449
// an invalid re. if so, re-walk the contents of the
450
// would-be class to re-translate any characters that
451
// were passed through as-is
452
// TODO: It would probably be faster to determine this
453
// without a try/catch and a new RegExp, but it's tricky
454
// to do safely. For now, this is safe and works.
455
var cs = pattern.substring(classStart + 1, i)
456
try {
457
RegExp('[' + cs + ']')
458
} catch (er) {
459
// not a valid class!
460
var sp = this.parse(cs, SUBPARSE)
461
re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
462
hasMagic = hasMagic || sp[1]
463
inClass = false
464
continue
465
}
466
}
467
468
// finish up the class.
469
hasMagic = true
470
inClass = false
471
re += c
472
continue
473
474
default:
475
// swallow any state char that wasn't consumed
476
clearStateChar()
477
478
if (escaping) {
479
// no need
480
escaping = false
481
} else if (reSpecials[c]
482
&& !(c === '^' && inClass)) {
483
re += '\\'
484
}
485
486
re += c
487
488
} // switch
489
} // for
490
491
// handle the case where we left a class open.
492
// "[abc" is valid, equivalent to "\[abc"
493
if (inClass) {
494
// split where the last [ was, and escape it
495
// this is a huge pita. We now have to re-walk
496
// the contents of the would-be class to re-translate
497
// any characters that were passed through as-is
498
cs = pattern.substr(classStart + 1)
499
sp = this.parse(cs, SUBPARSE)
500
re = re.substr(0, reClassStart) + '\\[' + sp[0]
501
hasMagic = hasMagic || sp[1]
502
}
503
504
// handle the case where we had a +( thing at the *end*
505
// of the pattern.
506
// each pattern list stack adds 3 chars, and we need to go through
507
// and escape any | chars that were passed through as-is for the regexp.
508
// Go through and escape them, taking care not to double-escape any
509
// | chars that were already escaped.
510
for (var pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
511
var tail = re.slice(pl.reStart + 3)
512
// maybe some even number of \, then maybe 1 \, followed by a |
513
tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
514
if (!$2) {
515
// the | isn't already escaped, so escape it.
516
$2 = '\\'
517
}
518
519
// need to escape all those slashes *again*, without escaping the
520
// one that we need for escaping the | character. As it works out,
521
// escaping an even number of slashes can be done by simply repeating
522
// it exactly after itself. That's why this trick works.
523
//
524
// I am sorry that you have to see this.
525
return $1 + $1 + $2 + '|'
526
})
527
528
this.debug('tail=%j\n %s', tail, tail)
529
var t = pl.type === '*' ? star
530
: pl.type === '?' ? qmark
531
: '\\' + pl.type
532
533
hasMagic = true
534
re = re.slice(0, pl.reStart) + t + '\\(' + tail
535
}
536
537
// handle trailing things that only matter at the very end.
538
clearStateChar()
539
if (escaping) {
540
// trailing \\
541
re += '\\\\'
542
}
543
544
// only need to apply the nodot start if the re starts with
545
// something that could conceivably capture a dot
546
var addPatternStart = false
547
switch (re.charAt(0)) {
548
case '.':
549
case '[':
550
case '(': addPatternStart = true
551
}
552
553
// if the re is not "" at this point, then we need to make sure
554
// it doesn't match against an empty path part.
555
// Otherwise a/* will match a/, which it should not.
556
if (re !== '' && hasMagic) re = '(?=.)' + re
557
558
if (addPatternStart) re = patternStart + re
559
560
// parsing just a piece of a larger pattern.
561
if (isSub === SUBPARSE) {
562
return [re, hasMagic]
563
}
564
565
// skip the regexp for non-magical patterns
566
// unescape anything in it, though, so that it'll be
567
// an exact match against a file etc.
568
if (!hasMagic) {
569
return globUnescape(pattern)
570
}
571
572
var flags = options.nocase ? 'i' : ''
573
var regExp = new RegExp('^' + re + '$', flags)
574
575
regExp._glob = pattern
576
regExp._src = re
577
578
return regExp
579
}
580
581
minimatch.makeRe = function (pattern, options) {
582
return new Minimatch(pattern, options || {}).makeRe()
583
}
584
585
Minimatch.prototype.makeRe = makeRe
586
function makeRe () {
587
if (this.regexp || this.regexp === false) return this.regexp
588
589
// at this point, this.set is a 2d array of partial
590
// pattern strings, or "**".
591
//
592
// It's better to use .match(). This function shouldn't
593
// be used, really, but it's pretty convenient sometimes,
594
// when you just want to work with a regex.
595
var set = this.set
596
597
if (!set.length) {
598
this.regexp = false
599
return this.regexp
600
}
601
var options = this.options
602
603
var twoStar = options.noglobstar ? star
604
: options.dot ? twoStarDot
605
: twoStarNoDot
606
var flags = options.nocase ? 'i' : ''
607
608
var re = set.map(function (pattern) {
609
return pattern.map(function (p) {
610
return (p === GLOBSTAR) ? twoStar
611
: (typeof p === 'string') ? regExpEscape(p)
612
: p._src
613
}).join('\\\/')
614
}).join('|')
615
616
// must match entire pattern
617
// ending in a * or ** will make it less strict.
618
re = '^(?:' + re + ')$'
619
620
// can match anything, as long as it's not this.
621
if (this.negate) re = '^(?!' + re + ').*$'
622
623
try {
624
this.regexp = new RegExp(re, flags)
625
} catch (ex) {
626
this.regexp = false
627
}
628
return this.regexp
629
}
630
631
minimatch.match = function (list, pattern, options) {
632
options = options || {}
633
var mm = new Minimatch(pattern, options)
634
list = list.filter(function (f) {
635
return mm.match(f)
636
})
637
if (mm.options.nonull && !list.length) {
638
list.push(pattern)
639
}
640
return list
641
}
642
643
Minimatch.prototype.match = match
644
function match (f, partial) {
645
this.debug('match', f, this.pattern)
646
// short-circuit in the case of busted things.
647
// comments, etc.
648
if (this.comment) return false
649
if (this.empty) return f === ''
650
651
if (f === '/' && partial) return true
652
653
var options = this.options
654
655
// windows: need to use /, not \
656
if (path.sep !== '/') {
657
f = f.split(path.sep).join('/')
658
}
659
660
// treat the test path as a set of pathparts.
661
f = f.split(slashSplit)
662
this.debug(this.pattern, 'split', f)
663
664
// just ONE of the pattern sets in this.set needs to match
665
// in order for it to be valid. If negating, then just one
666
// match means that we have failed.
667
// Either way, return on the first hit.
668
669
var set = this.set
670
this.debug(this.pattern, 'set', set)
671
672
// Find the basename of the path by looking for the last non-empty segment
673
var filename
674
var i
675
for (i = f.length - 1; i >= 0; i--) {
676
filename = f[i]
677
if (filename) break
678
}
679
680
for (i = 0; i < set.length; i++) {
681
var pattern = set[i]
682
var file = f
683
if (options.matchBase && pattern.length === 1) {
684
file = [filename]
685
}
686
var hit = this.matchOne(file, pattern, partial)
687
if (hit) {
688
if (options.flipNegate) return true
689
return !this.negate
690
}
691
}
692
693
// didn't get any hits. this is success if it's a negative
694
// pattern, failure otherwise.
695
if (options.flipNegate) return false
696
return this.negate
697
}
698
699
// set partial to true to test if, for example,
700
// "/a/b" matches the start of "/*/b/*/d"
701
// Partial means, if you run out of file before you run
702
// out of pattern, then that's fine, as long as all
703
// the parts match.
704
Minimatch.prototype.matchOne = function (file, pattern, partial) {
705
var options = this.options
706
707
this.debug('matchOne',
708
{ 'this': this, file: file, pattern: pattern })
709
710
this.debug('matchOne', file.length, pattern.length)
711
712
for (var fi = 0,
713
pi = 0,
714
fl = file.length,
715
pl = pattern.length
716
; (fi < fl) && (pi < pl)
717
; fi++, pi++) {
718
this.debug('matchOne loop')
719
var p = pattern[pi]
720
var f = file[fi]
721
722
this.debug(pattern, p, f)
723
724
// should be impossible.
725
// some invalid regexp stuff in the set.
726
if (p === false) return false
727
728
if (p === GLOBSTAR) {
729
this.debug('GLOBSTAR', [pattern, p, f])
730
731
// "**"
732
// a/**/b/**/c would match the following:
733
// a/b/x/y/z/c
734
// a/x/y/z/b/c
735
// a/b/x/b/x/c
736
// a/b/c
737
// To do this, take the rest of the pattern after
738
// the **, and see if it would match the file remainder.
739
// If so, return success.
740
// If not, the ** "swallows" a segment, and try again.
741
// This is recursively awful.
742
//
743
// a/**/b/**/c matching a/b/x/y/z/c
744
// - a matches a
745
// - doublestar
746
// - matchOne(b/x/y/z/c, b/**/c)
747
// - b matches b
748
// - doublestar
749
// - matchOne(x/y/z/c, c) -> no
750
// - matchOne(y/z/c, c) -> no
751
// - matchOne(z/c, c) -> no
752
// - matchOne(c, c) yes, hit
753
var fr = fi
754
var pr = pi + 1
755
if (pr === pl) {
756
this.debug('** at the end')
757
// a ** at the end will just swallow the rest.
758
// We have found a match.
759
// however, it will not swallow /.x, unless
760
// options.dot is set.
761
// . and .. are *never* matched by **, for explosively
762
// exponential reasons.
763
for (; fi < fl; fi++) {
764
if (file[fi] === '.' || file[fi] === '..' ||
765
(!options.dot && file[fi].charAt(0) === '.')) return false
766
}
767
return true
768
}
769
770
// ok, let's see if we can swallow whatever we can.
771
while (fr < fl) {
772
var swallowee = file[fr]
773
774
this.debug('\nglobstar while', file, fr, pattern, pr, swallowee)
775
776
// XXX remove this slice. Just pass the start index.
777
if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
778
this.debug('globstar found match!', fr, fl, swallowee)
779
// found a match.
780
return true
781
} else {
782
// can't swallow "." or ".." ever.
783
// can only swallow ".foo" when explicitly asked.
784
if (swallowee === '.' || swallowee === '..' ||
785
(!options.dot && swallowee.charAt(0) === '.')) {
786
this.debug('dot detected!', file, fr, pattern, pr)
787
break
788
}
789
790
// ** swallows a segment, and continue.
791
this.debug('globstar swallow a segment, and continue')
792
fr++
793
}
794
}
795
796
// no match was found.
797
// However, in partial mode, we can't say this is necessarily over.
798
// If there's more *pattern* left, then
799
if (partial) {
800
// ran out of file
801
this.debug('\n>>> no match, partial?', file, fr, pattern, pr)
802
if (fr === fl) return true
803
}
804
return false
805
}
806
807
// something other than **
808
// non-magic patterns just have to match exactly
809
// patterns with magic have been turned into regexps.
810
var hit
811
if (typeof p === 'string') {
812
if (options.nocase) {
813
hit = f.toLowerCase() === p.toLowerCase()
814
} else {
815
hit = f === p
816
}
817
this.debug('string match', p, f, hit)
818
} else {
819
hit = f.match(p)
820
this.debug('pattern match', p, f, hit)
821
}
822
823
if (!hit) return false
824
}
825
826
// Note: ending in / means that we'll get a final ""
827
// at the end of the pattern. This can only match a
828
// corresponding "" at the end of the file.
829
// If the file ends in /, then it can only match a
830
// a pattern that ends in /, unless the pattern just
831
// doesn't have any more for it. But, a/b/ should *not*
832
// match "a/b/*", even though "" matches against the
833
// [^/]*? pattern, except in partial mode, where it might
834
// simply not be reached yet.
835
// However, a/b/ should still satisfy a/*
836
837
// now either we fell off the end of the pattern, or we're done.
838
if (fi === fl && pi === pl) {
839
// ran out of pattern and filename at the same time.
840
// an exact hit!
841
return true
842
} else if (fi === fl) {
843
// ran out of file, but still had pattern left.
844
// this is ok if we're doing the match as part of
845
// a glob fs traversal.
846
return partial
847
} else if (pi === pl) {
848
// ran out of pattern, still have file left.
849
// this is only acceptable if we're on the very last
850
// empty segment of a file with a trailing slash.
851
// a/* should match a/b/
852
var emptyFileEnd = (fi === fl - 1) && (file[fi] === '')
853
return emptyFileEnd
854
}
855
856
// should be unreachable.
857
throw new Error('wtf?')
858
}
859
860
// replace stuff like \* with *
861
function globUnescape (s) {
862
return s.replace(/\\(.)/g, '$1')
863
}
864
865
function regExpEscape (s) {
866
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
867
}
868
869