minimatch
Advanced tools
Comparing version 2.0.5 to 2.0.6
397
browser.js
@@ -5,29 +5,32 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var path = require('path'); | ||
var sep = '/' | ||
try { | ||
sep = require('path').sep | ||
} catch (er) {} | ||
var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {} | ||
, expand = require("brace-expansion") | ||
var expand = require('brace-expansion') | ||
// any single thing other than / | ||
// don't need to escape / when using new RegExp() | ||
, qmark = "[^/]" | ||
// any single thing other than / | ||
// don't need to escape / when using new RegExp() | ||
var qmark = '[^/]' | ||
// * => any number of characters | ||
, star = qmark + "*?" | ||
// * => any number of characters | ||
var star = qmark + '*?' | ||
// ** when dots are allowed. Anything goes, except .. and . | ||
// not (^ or / followed by one or two dots followed by $ or /), | ||
// followed by anything, any number of times. | ||
, twoStarDot = "(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?" | ||
// ** when dots are allowed. Anything goes, except .. and . | ||
// not (^ or / followed by one or two dots followed by $ or /), | ||
// followed by anything, any number of times. | ||
var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?' | ||
// not a ^ or / followed by a dot, | ||
// followed by anything, any number of times. | ||
, twoStarNoDot = "(?:(?!(?:\\\/|^)\\.).)*?" | ||
// not a ^ or / followed by a dot, | ||
// followed by anything, any number of times. | ||
var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?' | ||
// characters that need to be escaped in RegExp. | ||
, reSpecials = charSet("().*{}+?[]^$\\!") | ||
// characters that need to be escaped in RegExp. | ||
var reSpecials = charSet('().*{}+?[]^$\\!') | ||
// "abc" -> { a:true, b:true, c:true } | ||
function charSet (s) { | ||
return s.split("").reduce(function (set, c) { | ||
return s.split('').reduce(function (set, c) { | ||
set[c] = true | ||
@@ -83,6 +86,5 @@ return set | ||
function minimatch (p, pattern, options) { | ||
if (typeof pattern !== "string") { | ||
throw new TypeError("glob pattern string required") | ||
if (typeof pattern !== 'string') { | ||
throw new TypeError('glob pattern string required') | ||
} | ||
@@ -93,3 +95,3 @@ | ||
// shortcut: comments match nothing. | ||
if (!options.nocomment && pattern.charAt(0) === "#") { | ||
if (!options.nocomment && pattern.charAt(0) === '#') { | ||
return false | ||
@@ -99,3 +101,3 @@ } | ||
// "" only matches "" | ||
if (pattern.trim() === "") return p === "" | ||
if (pattern.trim() === '') return p === '' | ||
@@ -110,4 +112,4 @@ return new Minimatch(pattern, options).match(p) | ||
if (typeof pattern !== "string") { | ||
throw new TypeError("glob pattern string required") | ||
if (typeof pattern !== 'string') { | ||
throw new TypeError('glob pattern string required') | ||
} | ||
@@ -119,4 +121,5 @@ | ||
// windows support: need to use /, not \ | ||
if (path.sep === '\\') | ||
pattern = pattern.split("\\").join("/") | ||
if (sep !== '/') { | ||
pattern = pattern.split(sep).join('/') | ||
} | ||
@@ -135,3 +138,3 @@ this.options = options | ||
Minimatch.prototype.debug = function() {} | ||
Minimatch.prototype.debug = function () {} | ||
@@ -147,3 +150,3 @@ Minimatch.prototype.make = make | ||
// empty patterns and comments match nothing. | ||
if (!options.nocomment && pattern.charAt(0) === "#") { | ||
if (!options.nocomment && pattern.charAt(0) === '#') { | ||
this.comment = true | ||
@@ -187,3 +190,3 @@ return | ||
set = set.filter(function (s) { | ||
return -1 === s.indexOf(false) | ||
return s.indexOf(false) === -1 | ||
}) | ||
@@ -199,13 +202,13 @@ | ||
var pattern = this.pattern | ||
, negate = false | ||
, options = this.options | ||
, negateOffset = 0 | ||
var negate = false | ||
var options = this.options | ||
var negateOffset = 0 | ||
if (options.nonegate) return | ||
for ( var i = 0, l = pattern.length | ||
; i < l && pattern.charAt(i) === "!" | ||
; i ++) { | ||
for (var i = 0, l = pattern.length | ||
; i < l && pattern.charAt(i) === '!' | ||
; i++) { | ||
negate = !negate | ||
negateOffset ++ | ||
negateOffset++ | ||
} | ||
@@ -235,17 +238,18 @@ | ||
if (!options) { | ||
if (this instanceof Minimatch) | ||
if (this instanceof Minimatch) { | ||
options = this.options | ||
else | ||
} else { | ||
options = {} | ||
} | ||
} | ||
pattern = typeof pattern === "undefined" | ||
pattern = typeof pattern === 'undefined' | ||
? this.pattern : pattern | ||
if (typeof pattern === "undefined") { | ||
throw new Error("undefined pattern") | ||
if (typeof pattern === 'undefined') { | ||
throw new Error('undefined pattern') | ||
} | ||
if (options.nobrace || | ||
!pattern.match(/\{.*\}/)) { | ||
!pattern.match(/\{.*\}/)) { | ||
// shortcut. no need to expand. | ||
@@ -275,22 +279,22 @@ return [pattern] | ||
// shortcuts | ||
if (!options.noglobstar && pattern === "**") return GLOBSTAR | ||
if (pattern === "") return "" | ||
if (!options.noglobstar && pattern === '**') return GLOBSTAR | ||
if (pattern === '') return '' | ||
var re = "" | ||
, hasMagic = !!options.nocase | ||
, escaping = false | ||
// ? => one single character | ||
, patternListStack = [] | ||
, plType | ||
, stateChar | ||
, inClass = false | ||
, reClassStart = -1 | ||
, classStart = -1 | ||
// . and .. never match anything that doesn't start with ., | ||
// even when options.dot is set. | ||
, patternStart = pattern.charAt(0) === "." ? "" // anything | ||
// not (start or / followed by . or .. followed by / or end) | ||
: options.dot ? "(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))" | ||
: "(?!\\.)" | ||
, self = this | ||
var re = '' | ||
var hasMagic = !!options.nocase | ||
var escaping = false | ||
// ? => one single character | ||
var patternListStack = [] | ||
var plType | ||
var stateChar | ||
var inClass = false | ||
var reClassStart = -1 | ||
var classStart = -1 | ||
// . and .. never match anything that doesn't start with ., | ||
// even when options.dot is set. | ||
var patternStart = pattern.charAt(0) === '.' ? '' // anything | ||
// not (start or / followed by . or .. followed by / or end) | ||
: options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))' | ||
: '(?!\\.)' | ||
var self = this | ||
@@ -302,13 +306,13 @@ function clearStateChar () { | ||
switch (stateChar) { | ||
case "*": | ||
case '*': | ||
re += star | ||
hasMagic = true | ||
break | ||
case "?": | ||
break | ||
case '?': | ||
re += qmark | ||
hasMagic = true | ||
break | ||
break | ||
default: | ||
re += "\\"+stateChar | ||
break | ||
re += '\\' + stateChar | ||
break | ||
} | ||
@@ -320,11 +324,10 @@ self.debug('clearStateChar %j %j', stateChar, re) | ||
for ( var i = 0, len = pattern.length, c | ||
; (i < len) && (c = pattern.charAt(i)) | ||
; i ++ ) { | ||
for (var i = 0, len = pattern.length, c | ||
; (i < len) && (c = pattern.charAt(i)) | ||
; i++) { | ||
this.debug('%s\t%s %s %j', pattern, i, re, c) | ||
this.debug("%s\t%s %s %j", pattern, i, re, c) | ||
// skip over any that are escaped. | ||
if (escaping && reSpecials[c]) { | ||
re += "\\" + c | ||
re += '\\' + c | ||
escaping = false | ||
@@ -334,4 +337,4 @@ continue | ||
SWITCH: switch (c) { | ||
case "/": | ||
switch (c) { | ||
case '/': | ||
// completely not allowed, even escaped. | ||
@@ -341,15 +344,15 @@ // Should already be path-split by now. | ||
case "\\": | ||
case '\\': | ||
clearStateChar() | ||
escaping = true | ||
continue | ||
continue | ||
// the various stateChar values | ||
// for the "extglob" stuff. | ||
case "?": | ||
case "*": | ||
case "+": | ||
case "@": | ||
case "!": | ||
this.debug("%s\t%s %s %j <-- stateChar", pattern, i, re, c) | ||
case '?': | ||
case '*': | ||
case '+': | ||
case '@': | ||
case '!': | ||
this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c) | ||
@@ -360,3 +363,3 @@ // all of those are literals inside a class, except that | ||
this.debug(' in class') | ||
if (c === "!" && i === classStart + 1) c = "^" | ||
if (c === '!' && i === classStart + 1) c = '^' | ||
re += c | ||
@@ -376,7 +379,7 @@ continue | ||
if (options.noext) clearStateChar() | ||
continue | ||
continue | ||
case "(": | ||
case '(': | ||
if (inClass) { | ||
re += "(" | ||
re += '(' | ||
continue | ||
@@ -386,3 +389,3 @@ } | ||
if (!stateChar) { | ||
re += "\\(" | ||
re += '\\(' | ||
continue | ||
@@ -392,14 +395,12 @@ } | ||
plType = stateChar | ||
patternListStack.push({ type: plType | ||
, start: i - 1 | ||
, reStart: re.length }) | ||
patternListStack.push({ type: plType, start: i - 1, reStart: re.length }) | ||
// negation is (?:(?!js)[^/]*) | ||
re += stateChar === "!" ? "(?:(?!" : "(?:" | ||
re += stateChar === '!' ? '(?:(?!' : '(?:' | ||
this.debug('plType %j %j', stateChar, re) | ||
stateChar = false | ||
continue | ||
continue | ||
case ")": | ||
case ')': | ||
if (inClass || !patternListStack.length) { | ||
re += "\\)" | ||
re += '\\)' | ||
continue | ||
@@ -410,3 +411,3 @@ } | ||
hasMagic = true | ||
re += ")" | ||
re += ')' | ||
plType = patternListStack.pop().type | ||
@@ -416,15 +417,17 @@ // negation is (?:(?!js)[^/]*) | ||
switch (plType) { | ||
case "!": | ||
re += "[^/]*?)" | ||
case '!': | ||
re += '[^/]*?)' | ||
break | ||
case "?": | ||
case "+": | ||
case "*": re += plType | ||
case "@": break // the default anyway | ||
case '?': | ||
case '+': | ||
case '*': | ||
re += plType | ||
break | ||
case '@': break // the default anyway | ||
} | ||
continue | ||
continue | ||
case "|": | ||
case '|': | ||
if (inClass || !patternListStack.length || escaping) { | ||
re += "\\|" | ||
re += '\\|' | ||
escaping = false | ||
@@ -435,7 +438,7 @@ continue | ||
clearStateChar() | ||
re += "|" | ||
continue | ||
re += '|' | ||
continue | ||
// these are mostly the same in regexp and glob | ||
case "[": | ||
case '[': | ||
// swallow any state-tracking char before the [ | ||
@@ -445,3 +448,3 @@ clearStateChar() | ||
if (inClass) { | ||
re += "\\" + c | ||
re += '\\' + c | ||
continue | ||
@@ -454,5 +457,5 @@ } | ||
re += c | ||
continue | ||
continue | ||
case "]": | ||
case ']': | ||
// a right bracket shall lose its special | ||
@@ -463,3 +466,3 @@ // meaning and represent itself in | ||
if (i === classStart + 1 || !inClass) { | ||
re += "\\" + c | ||
re += '\\' + c | ||
escaping = false | ||
@@ -481,7 +484,7 @@ continue | ||
try { | ||
new RegExp('[' + cs + ']') | ||
RegExp('[' + cs + ']') | ||
} catch (er) { | ||
// not a valid class! | ||
var sp = this.parse(cs, SUBPARSE) | ||
re = re.substr(0, reClassStart) + "\\[" + sp[0] + '\\]' | ||
re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]' | ||
hasMagic = hasMagic || sp[1] | ||
@@ -497,3 +500,3 @@ inClass = false | ||
re += c | ||
continue | ||
continue | ||
@@ -508,4 +511,4 @@ default: | ||
} else if (reSpecials[c] | ||
&& !(c === "^" && inClass)) { | ||
re += "\\" | ||
&& !(c === '^' && inClass)) { | ||
re += '\\' | ||
} | ||
@@ -518,3 +521,2 @@ | ||
// handle the case where we left a class open. | ||
@@ -527,5 +529,5 @@ // "[abc" is valid, equivalent to "\[abc" | ||
// any characters that were passed through as-is | ||
var cs = pattern.substr(classStart + 1) | ||
, sp = this.parse(cs, SUBPARSE) | ||
re = re.substr(0, reClassStart) + "\\[" + sp[0] | ||
cs = pattern.substr(classStart + 1) | ||
sp = this.parse(cs, SUBPARSE) | ||
re = re.substr(0, reClassStart) + '\\[' + sp[0] | ||
hasMagic = hasMagic || sp[1] | ||
@@ -540,4 +542,3 @@ } | ||
// | chars that were already escaped. | ||
var pl | ||
while (pl = patternListStack.pop()) { | ||
for (var pl = patternListStack.pop(); pl; pl = patternListStack.pop()) { | ||
var tail = re.slice(pl.reStart + 3) | ||
@@ -548,3 +549,3 @@ // maybe some even number of \, then maybe 1 \, followed by a | | ||
// the | isn't already escaped, so escape it. | ||
$2 = "\\" | ||
$2 = '\\' | ||
} | ||
@@ -558,14 +559,12 @@ | ||
// I am sorry that you have to see this. | ||
return $1 + $1 + $2 + "|" | ||
return $1 + $1 + $2 + '|' | ||
}) | ||
this.debug("tail=%j\n %s", tail, tail) | ||
var t = pl.type === "*" ? star | ||
: pl.type === "?" ? qmark | ||
: "\\" + pl.type | ||
this.debug('tail=%j\n %s', tail, tail) | ||
var t = pl.type === '*' ? star | ||
: pl.type === '?' ? qmark | ||
: '\\' + pl.type | ||
hasMagic = true | ||
re = re.slice(0, pl.reStart) | ||
+ t + "\\(" | ||
+ tail | ||
re = re.slice(0, pl.reStart) + t + '\\(' + tail | ||
} | ||
@@ -577,3 +576,3 @@ | ||
// trailing \\ | ||
re += "\\\\" | ||
re += '\\\\' | ||
} | ||
@@ -585,5 +584,5 @@ | ||
switch (re.charAt(0)) { | ||
case ".": | ||
case "[": | ||
case "(": addPatternStart = true | ||
case '.': | ||
case '[': | ||
case '(': addPatternStart = true | ||
} | ||
@@ -594,3 +593,3 @@ | ||
// Otherwise a/* will match a/, which it should not. | ||
if (re !== "" && hasMagic) re = "(?=.)" + re | ||
if (re !== '' && hasMagic) re = '(?=.)' + re | ||
@@ -601,3 +600,3 @@ if (addPatternStart) re = patternStart + re | ||
if (isSub === SUBPARSE) { | ||
return [ re, hasMagic ] | ||
return [re, hasMagic] | ||
} | ||
@@ -612,4 +611,4 @@ | ||
var flags = options.nocase ? "i" : "" | ||
, regExp = new RegExp("^" + re + "$", flags) | ||
var flags = options.nocase ? 'i' : '' | ||
var regExp = new RegExp('^' + re + '$', flags) | ||
@@ -638,9 +637,12 @@ regExp._glob = pattern | ||
if (!set.length) return this.regexp = false | ||
if (!set.length) { | ||
this.regexp = false | ||
return this.regexp | ||
} | ||
var options = this.options | ||
var twoStar = options.noglobstar ? star | ||
: options.dot ? twoStarDot | ||
: twoStarNoDot | ||
, flags = options.nocase ? "i" : "" | ||
: options.dot ? twoStarDot | ||
: twoStarNoDot | ||
var flags = options.nocase ? 'i' : '' | ||
@@ -650,19 +652,20 @@ var re = set.map(function (pattern) { | ||
return (p === GLOBSTAR) ? twoStar | ||
: (typeof p === "string") ? regExpEscape(p) | ||
: p._src | ||
}).join("\\\/") | ||
}).join("|") | ||
: (typeof p === 'string') ? regExpEscape(p) | ||
: p._src | ||
}).join('\\\/') | ||
}).join('|') | ||
// must match entire pattern | ||
// ending in a * or ** will make it less strict. | ||
re = "^(?:" + re + ")$" | ||
re = '^(?:' + re + ')$' | ||
// can match anything, as long as it's not this. | ||
if (this.negate) re = "^(?!" + re + ").*$" | ||
if (this.negate) re = '^(?!' + re + ').*$' | ||
try { | ||
return this.regexp = new RegExp(re, flags) | ||
this.regexp = new RegExp(re, flags) | ||
} catch (ex) { | ||
return this.regexp = false | ||
this.regexp = false | ||
} | ||
return this.regexp | ||
} | ||
@@ -684,9 +687,9 @@ | ||
function match (f, partial) { | ||
this.debug("match", f, this.pattern) | ||
this.debug('match', f, this.pattern) | ||
// short-circuit in the case of busted things. | ||
// comments, etc. | ||
if (this.comment) return false | ||
if (this.empty) return f === "" | ||
if (this.empty) return f === '' | ||
if (f === "/" && partial) return true | ||
if (f === '/' && partial) return true | ||
@@ -696,8 +699,9 @@ var options = this.options | ||
// windows: need to use /, not \ | ||
if (path.sep == '\\') | ||
f = f.split("\\").join("/") | ||
if (sep !== '/') { | ||
f = f.split(sep).join('/') | ||
} | ||
// treat the test path as a set of pathparts. | ||
f = f.split(slashSplit) | ||
this.debug(this.pattern, "split", f) | ||
this.debug(this.pattern, 'split', f) | ||
@@ -710,7 +714,8 @@ // just ONE of the pattern sets in this.set needs to match | ||
var set = this.set | ||
this.debug(this.pattern, "set", set) | ||
this.debug(this.pattern, 'set', set) | ||
// Find the basename of the path by looking for the last non-empty segment | ||
var filename; | ||
for (var i = f.length - 1; i >= 0; i--) { | ||
var filename | ||
var i | ||
for (i = f.length - 1; i >= 0; i--) { | ||
filename = f[i] | ||
@@ -720,4 +725,5 @@ if (filename) break | ||
for (var i = 0, l = set.length; i < l; i ++) { | ||
var pattern = set[i], file = f | ||
for (i = 0; i < set.length; i++) { | ||
var pattern = set[i] | ||
var file = f | ||
if (options.matchBase && pattern.length === 1) { | ||
@@ -747,19 +753,16 @@ file = [filename] | ||
this.debug("matchOne", | ||
{ "this": this | ||
, file: file | ||
, pattern: pattern }) | ||
this.debug('matchOne', | ||
{ 'this': this, file: file, pattern: pattern }) | ||
this.debug("matchOne", file.length, pattern.length) | ||
this.debug('matchOne', file.length, pattern.length) | ||
for ( var fi = 0 | ||
, pi = 0 | ||
, fl = file.length | ||
, pl = pattern.length | ||
for (var fi = 0, | ||
pi = 0, | ||
fl = file.length, | ||
pl = pattern.length | ||
; (fi < fl) && (pi < pl) | ||
; fi ++, pi ++ ) { | ||
this.debug("matchOne loop") | ||
; fi++, pi++) { | ||
this.debug('matchOne loop') | ||
var p = pattern[pi] | ||
, f = file[fi] | ||
var f = file[fi] | ||
@@ -798,3 +801,3 @@ this.debug(pattern, p, f) | ||
var fr = fi | ||
, pr = pi + 1 | ||
var pr = pi + 1 | ||
if (pr === pl) { | ||
@@ -808,5 +811,5 @@ this.debug('** at the end') | ||
// exponential reasons. | ||
for ( ; fi < fl; fi ++) { | ||
if (file[fi] === "." || file[fi] === ".." || | ||
(!options.dot && file[fi].charAt(0) === ".")) return false | ||
for (; fi < fl; fi++) { | ||
if (file[fi] === '.' || file[fi] === '..' || | ||
(!options.dot && file[fi].charAt(0) === '.')) return false | ||
} | ||
@@ -817,7 +820,6 @@ return true | ||
// ok, let's see if we can swallow whatever we can. | ||
WHILE: while (fr < fl) { | ||
while (fr < fl) { | ||
var swallowee = file[fr] | ||
this.debug('\nglobstar while', | ||
file, fr, pattern, pr, swallowee) | ||
this.debug('\nglobstar while', file, fr, pattern, pr, swallowee) | ||
@@ -832,6 +834,6 @@ // XXX remove this slice. Just pass the start index. | ||
// can only swallow ".foo" when explicitly asked. | ||
if (swallowee === "." || swallowee === ".." || | ||
(!options.dot && swallowee.charAt(0) === ".")) { | ||
this.debug("dot detected!", file, fr, pattern, pr) | ||
break WHILE | ||
if (swallowee === '.' || swallowee === '..' || | ||
(!options.dot && swallowee.charAt(0) === '.')) { | ||
this.debug('dot detected!', file, fr, pattern, pr) | ||
break | ||
} | ||
@@ -841,5 +843,6 @@ | ||
this.debug('globstar swallow a segment, and continue') | ||
fr ++ | ||
fr++ | ||
} | ||
} | ||
// no match was found. | ||
@@ -850,3 +853,3 @@ // However, in partial mode, we can't say this is necessarily over. | ||
// ran out of file | ||
this.debug("\n>>> no match, partial?", file, fr, pattern, pr) | ||
this.debug('\n>>> no match, partial?', file, fr, pattern, pr) | ||
if (fr === fl) return true | ||
@@ -861,3 +864,3 @@ } | ||
var hit | ||
if (typeof p === "string") { | ||
if (typeof p === 'string') { | ||
if (options.nocase) { | ||
@@ -868,6 +871,6 @@ hit = f.toLowerCase() === p.toLowerCase() | ||
} | ||
this.debug("string match", p, f, hit) | ||
this.debug('string match', p, f, hit) | ||
} else { | ||
hit = f.match(p) | ||
this.debug("pattern match", p, f, hit) | ||
this.debug('pattern match', p, f, hit) | ||
} | ||
@@ -904,3 +907,3 @@ | ||
// a/* should match a/b/ | ||
var emptyFileEnd = (fi === fl - 1) && (file[fi] === "") | ||
var emptyFileEnd = (fi === fl - 1) && (file[fi] === '') | ||
return emptyFileEnd | ||
@@ -910,14 +913,12 @@ } | ||
// should be unreachable. | ||
throw new Error("wtf?") | ||
throw new Error('wtf?') | ||
} | ||
// replace stuff like \* with * | ||
function globUnescape (s) { | ||
return s.replace(/\\(.)/g, "$1") | ||
return s.replace(/\\(.)/g, '$1') | ||
} | ||
function regExpEscape (s) { | ||
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") | ||
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') | ||
} | ||
@@ -924,0 +925,0 @@ |
397
minimatch.js
module.exports = minimatch | ||
minimatch.Minimatch = Minimatch | ||
var path = require('path'); | ||
var sep = '/' | ||
try { | ||
sep = require('path').sep | ||
} catch (er) {} | ||
var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {} | ||
, expand = require("brace-expansion") | ||
var expand = require('brace-expansion') | ||
// any single thing other than / | ||
// don't need to escape / when using new RegExp() | ||
, qmark = "[^/]" | ||
// any single thing other than / | ||
// don't need to escape / when using new RegExp() | ||
var qmark = '[^/]' | ||
// * => any number of characters | ||
, star = qmark + "*?" | ||
// * => any number of characters | ||
var star = qmark + '*?' | ||
// ** when dots are allowed. Anything goes, except .. and . | ||
// not (^ or / followed by one or two dots followed by $ or /), | ||
// followed by anything, any number of times. | ||
, twoStarDot = "(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?" | ||
// ** when dots are allowed. Anything goes, except .. and . | ||
// not (^ or / followed by one or two dots followed by $ or /), | ||
// followed by anything, any number of times. | ||
var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?' | ||
// not a ^ or / followed by a dot, | ||
// followed by anything, any number of times. | ||
, twoStarNoDot = "(?:(?!(?:\\\/|^)\\.).)*?" | ||
// not a ^ or / followed by a dot, | ||
// followed by anything, any number of times. | ||
var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?' | ||
// characters that need to be escaped in RegExp. | ||
, reSpecials = charSet("().*{}+?[]^$\\!") | ||
// characters that need to be escaped in RegExp. | ||
var reSpecials = charSet('().*{}+?[]^$\\!') | ||
// "abc" -> { a:true, b:true, c:true } | ||
function charSet (s) { | ||
return s.split("").reduce(function (set, c) { | ||
return s.split('').reduce(function (set, c) { | ||
set[c] = true | ||
@@ -81,6 +84,5 @@ return set | ||
function minimatch (p, pattern, options) { | ||
if (typeof pattern !== "string") { | ||
throw new TypeError("glob pattern string required") | ||
if (typeof pattern !== 'string') { | ||
throw new TypeError('glob pattern string required') | ||
} | ||
@@ -91,3 +93,3 @@ | ||
// shortcut: comments match nothing. | ||
if (!options.nocomment && pattern.charAt(0) === "#") { | ||
if (!options.nocomment && pattern.charAt(0) === '#') { | ||
return false | ||
@@ -97,3 +99,3 @@ } | ||
// "" only matches "" | ||
if (pattern.trim() === "") return p === "" | ||
if (pattern.trim() === '') return p === '' | ||
@@ -108,4 +110,4 @@ return new Minimatch(pattern, options).match(p) | ||
if (typeof pattern !== "string") { | ||
throw new TypeError("glob pattern string required") | ||
if (typeof pattern !== 'string') { | ||
throw new TypeError('glob pattern string required') | ||
} | ||
@@ -117,4 +119,5 @@ | ||
// windows support: need to use /, not \ | ||
if (path.sep === '\\') | ||
pattern = pattern.split("\\").join("/") | ||
if (sep !== '/') { | ||
pattern = pattern.split(sep).join('/') | ||
} | ||
@@ -133,3 +136,3 @@ this.options = options | ||
Minimatch.prototype.debug = function() {} | ||
Minimatch.prototype.debug = function () {} | ||
@@ -145,3 +148,3 @@ Minimatch.prototype.make = make | ||
// empty patterns and comments match nothing. | ||
if (!options.nocomment && pattern.charAt(0) === "#") { | ||
if (!options.nocomment && pattern.charAt(0) === '#') { | ||
this.comment = true | ||
@@ -185,3 +188,3 @@ return | ||
set = set.filter(function (s) { | ||
return -1 === s.indexOf(false) | ||
return s.indexOf(false) === -1 | ||
}) | ||
@@ -197,13 +200,13 @@ | ||
var pattern = this.pattern | ||
, negate = false | ||
, options = this.options | ||
, negateOffset = 0 | ||
var negate = false | ||
var options = this.options | ||
var negateOffset = 0 | ||
if (options.nonegate) return | ||
for ( var i = 0, l = pattern.length | ||
; i < l && pattern.charAt(i) === "!" | ||
; i ++) { | ||
for (var i = 0, l = pattern.length | ||
; i < l && pattern.charAt(i) === '!' | ||
; i++) { | ||
negate = !negate | ||
negateOffset ++ | ||
negateOffset++ | ||
} | ||
@@ -233,17 +236,18 @@ | ||
if (!options) { | ||
if (this instanceof Minimatch) | ||
if (this instanceof Minimatch) { | ||
options = this.options | ||
else | ||
} else { | ||
options = {} | ||
} | ||
} | ||
pattern = typeof pattern === "undefined" | ||
pattern = typeof pattern === 'undefined' | ||
? this.pattern : pattern | ||
if (typeof pattern === "undefined") { | ||
throw new Error("undefined pattern") | ||
if (typeof pattern === 'undefined') { | ||
throw new Error('undefined pattern') | ||
} | ||
if (options.nobrace || | ||
!pattern.match(/\{.*\}/)) { | ||
!pattern.match(/\{.*\}/)) { | ||
// shortcut. no need to expand. | ||
@@ -273,22 +277,22 @@ return [pattern] | ||
// shortcuts | ||
if (!options.noglobstar && pattern === "**") return GLOBSTAR | ||
if (pattern === "") return "" | ||
if (!options.noglobstar && pattern === '**') return GLOBSTAR | ||
if (pattern === '') return '' | ||
var re = "" | ||
, hasMagic = !!options.nocase | ||
, escaping = false | ||
// ? => one single character | ||
, patternListStack = [] | ||
, plType | ||
, stateChar | ||
, inClass = false | ||
, reClassStart = -1 | ||
, classStart = -1 | ||
// . and .. never match anything that doesn't start with ., | ||
// even when options.dot is set. | ||
, patternStart = pattern.charAt(0) === "." ? "" // anything | ||
// not (start or / followed by . or .. followed by / or end) | ||
: options.dot ? "(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))" | ||
: "(?!\\.)" | ||
, self = this | ||
var re = '' | ||
var hasMagic = !!options.nocase | ||
var escaping = false | ||
// ? => one single character | ||
var patternListStack = [] | ||
var plType | ||
var stateChar | ||
var inClass = false | ||
var reClassStart = -1 | ||
var classStart = -1 | ||
// . and .. never match anything that doesn't start with ., | ||
// even when options.dot is set. | ||
var patternStart = pattern.charAt(0) === '.' ? '' // anything | ||
// not (start or / followed by . or .. followed by / or end) | ||
: options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))' | ||
: '(?!\\.)' | ||
var self = this | ||
@@ -300,13 +304,13 @@ function clearStateChar () { | ||
switch (stateChar) { | ||
case "*": | ||
case '*': | ||
re += star | ||
hasMagic = true | ||
break | ||
case "?": | ||
break | ||
case '?': | ||
re += qmark | ||
hasMagic = true | ||
break | ||
break | ||
default: | ||
re += "\\"+stateChar | ||
break | ||
re += '\\' + stateChar | ||
break | ||
} | ||
@@ -318,11 +322,10 @@ self.debug('clearStateChar %j %j', stateChar, re) | ||
for ( var i = 0, len = pattern.length, c | ||
; (i < len) && (c = pattern.charAt(i)) | ||
; i ++ ) { | ||
for (var i = 0, len = pattern.length, c | ||
; (i < len) && (c = pattern.charAt(i)) | ||
; i++) { | ||
this.debug('%s\t%s %s %j', pattern, i, re, c) | ||
this.debug("%s\t%s %s %j", pattern, i, re, c) | ||
// skip over any that are escaped. | ||
if (escaping && reSpecials[c]) { | ||
re += "\\" + c | ||
re += '\\' + c | ||
escaping = false | ||
@@ -332,4 +335,4 @@ continue | ||
SWITCH: switch (c) { | ||
case "/": | ||
switch (c) { | ||
case '/': | ||
// completely not allowed, even escaped. | ||
@@ -339,15 +342,15 @@ // Should already be path-split by now. | ||
case "\\": | ||
case '\\': | ||
clearStateChar() | ||
escaping = true | ||
continue | ||
continue | ||
// the various stateChar values | ||
// for the "extglob" stuff. | ||
case "?": | ||
case "*": | ||
case "+": | ||
case "@": | ||
case "!": | ||
this.debug("%s\t%s %s %j <-- stateChar", pattern, i, re, c) | ||
case '?': | ||
case '*': | ||
case '+': | ||
case '@': | ||
case '!': | ||
this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c) | ||
@@ -358,3 +361,3 @@ // all of those are literals inside a class, except that | ||
this.debug(' in class') | ||
if (c === "!" && i === classStart + 1) c = "^" | ||
if (c === '!' && i === classStart + 1) c = '^' | ||
re += c | ||
@@ -374,7 +377,7 @@ continue | ||
if (options.noext) clearStateChar() | ||
continue | ||
continue | ||
case "(": | ||
case '(': | ||
if (inClass) { | ||
re += "(" | ||
re += '(' | ||
continue | ||
@@ -384,3 +387,3 @@ } | ||
if (!stateChar) { | ||
re += "\\(" | ||
re += '\\(' | ||
continue | ||
@@ -390,14 +393,12 @@ } | ||
plType = stateChar | ||
patternListStack.push({ type: plType | ||
, start: i - 1 | ||
, reStart: re.length }) | ||
patternListStack.push({ type: plType, start: i - 1, reStart: re.length }) | ||
// negation is (?:(?!js)[^/]*) | ||
re += stateChar === "!" ? "(?:(?!" : "(?:" | ||
re += stateChar === '!' ? '(?:(?!' : '(?:' | ||
this.debug('plType %j %j', stateChar, re) | ||
stateChar = false | ||
continue | ||
continue | ||
case ")": | ||
case ')': | ||
if (inClass || !patternListStack.length) { | ||
re += "\\)" | ||
re += '\\)' | ||
continue | ||
@@ -408,3 +409,3 @@ } | ||
hasMagic = true | ||
re += ")" | ||
re += ')' | ||
plType = patternListStack.pop().type | ||
@@ -414,15 +415,17 @@ // negation is (?:(?!js)[^/]*) | ||
switch (plType) { | ||
case "!": | ||
re += "[^/]*?)" | ||
case '!': | ||
re += '[^/]*?)' | ||
break | ||
case "?": | ||
case "+": | ||
case "*": re += plType | ||
case "@": break // the default anyway | ||
case '?': | ||
case '+': | ||
case '*': | ||
re += plType | ||
break | ||
case '@': break // the default anyway | ||
} | ||
continue | ||
continue | ||
case "|": | ||
case '|': | ||
if (inClass || !patternListStack.length || escaping) { | ||
re += "\\|" | ||
re += '\\|' | ||
escaping = false | ||
@@ -433,7 +436,7 @@ continue | ||
clearStateChar() | ||
re += "|" | ||
continue | ||
re += '|' | ||
continue | ||
// these are mostly the same in regexp and glob | ||
case "[": | ||
case '[': | ||
// swallow any state-tracking char before the [ | ||
@@ -443,3 +446,3 @@ clearStateChar() | ||
if (inClass) { | ||
re += "\\" + c | ||
re += '\\' + c | ||
continue | ||
@@ -452,5 +455,5 @@ } | ||
re += c | ||
continue | ||
continue | ||
case "]": | ||
case ']': | ||
// a right bracket shall lose its special | ||
@@ -461,3 +464,3 @@ // meaning and represent itself in | ||
if (i === classStart + 1 || !inClass) { | ||
re += "\\" + c | ||
re += '\\' + c | ||
escaping = false | ||
@@ -479,7 +482,7 @@ continue | ||
try { | ||
new RegExp('[' + cs + ']') | ||
RegExp('[' + cs + ']') | ||
} catch (er) { | ||
// not a valid class! | ||
var sp = this.parse(cs, SUBPARSE) | ||
re = re.substr(0, reClassStart) + "\\[" + sp[0] + '\\]' | ||
re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]' | ||
hasMagic = hasMagic || sp[1] | ||
@@ -495,3 +498,3 @@ inClass = false | ||
re += c | ||
continue | ||
continue | ||
@@ -506,4 +509,4 @@ default: | ||
} else if (reSpecials[c] | ||
&& !(c === "^" && inClass)) { | ||
re += "\\" | ||
&& !(c === '^' && inClass)) { | ||
re += '\\' | ||
} | ||
@@ -516,3 +519,2 @@ | ||
// handle the case where we left a class open. | ||
@@ -525,5 +527,5 @@ // "[abc" is valid, equivalent to "\[abc" | ||
// any characters that were passed through as-is | ||
var cs = pattern.substr(classStart + 1) | ||
, sp = this.parse(cs, SUBPARSE) | ||
re = re.substr(0, reClassStart) + "\\[" + sp[0] | ||
cs = pattern.substr(classStart + 1) | ||
sp = this.parse(cs, SUBPARSE) | ||
re = re.substr(0, reClassStart) + '\\[' + sp[0] | ||
hasMagic = hasMagic || sp[1] | ||
@@ -538,4 +540,3 @@ } | ||
// | chars that were already escaped. | ||
var pl | ||
while (pl = patternListStack.pop()) { | ||
for (var pl = patternListStack.pop(); pl; pl = patternListStack.pop()) { | ||
var tail = re.slice(pl.reStart + 3) | ||
@@ -546,3 +547,3 @@ // maybe some even number of \, then maybe 1 \, followed by a | | ||
// the | isn't already escaped, so escape it. | ||
$2 = "\\" | ||
$2 = '\\' | ||
} | ||
@@ -556,14 +557,12 @@ | ||
// I am sorry that you have to see this. | ||
return $1 + $1 + $2 + "|" | ||
return $1 + $1 + $2 + '|' | ||
}) | ||
this.debug("tail=%j\n %s", tail, tail) | ||
var t = pl.type === "*" ? star | ||
: pl.type === "?" ? qmark | ||
: "\\" + pl.type | ||
this.debug('tail=%j\n %s', tail, tail) | ||
var t = pl.type === '*' ? star | ||
: pl.type === '?' ? qmark | ||
: '\\' + pl.type | ||
hasMagic = true | ||
re = re.slice(0, pl.reStart) | ||
+ t + "\\(" | ||
+ tail | ||
re = re.slice(0, pl.reStart) + t + '\\(' + tail | ||
} | ||
@@ -575,3 +574,3 @@ | ||
// trailing \\ | ||
re += "\\\\" | ||
re += '\\\\' | ||
} | ||
@@ -583,5 +582,5 @@ | ||
switch (re.charAt(0)) { | ||
case ".": | ||
case "[": | ||
case "(": addPatternStart = true | ||
case '.': | ||
case '[': | ||
case '(': addPatternStart = true | ||
} | ||
@@ -592,3 +591,3 @@ | ||
// Otherwise a/* will match a/, which it should not. | ||
if (re !== "" && hasMagic) re = "(?=.)" + re | ||
if (re !== '' && hasMagic) re = '(?=.)' + re | ||
@@ -599,3 +598,3 @@ if (addPatternStart) re = patternStart + re | ||
if (isSub === SUBPARSE) { | ||
return [ re, hasMagic ] | ||
return [re, hasMagic] | ||
} | ||
@@ -610,4 +609,4 @@ | ||
var flags = options.nocase ? "i" : "" | ||
, regExp = new RegExp("^" + re + "$", flags) | ||
var flags = options.nocase ? 'i' : '' | ||
var regExp = new RegExp('^' + re + '$', flags) | ||
@@ -636,9 +635,12 @@ regExp._glob = pattern | ||
if (!set.length) return this.regexp = false | ||
if (!set.length) { | ||
this.regexp = false | ||
return this.regexp | ||
} | ||
var options = this.options | ||
var twoStar = options.noglobstar ? star | ||
: options.dot ? twoStarDot | ||
: twoStarNoDot | ||
, flags = options.nocase ? "i" : "" | ||
: options.dot ? twoStarDot | ||
: twoStarNoDot | ||
var flags = options.nocase ? 'i' : '' | ||
@@ -648,19 +650,20 @@ var re = set.map(function (pattern) { | ||
return (p === GLOBSTAR) ? twoStar | ||
: (typeof p === "string") ? regExpEscape(p) | ||
: p._src | ||
}).join("\\\/") | ||
}).join("|") | ||
: (typeof p === 'string') ? regExpEscape(p) | ||
: p._src | ||
}).join('\\\/') | ||
}).join('|') | ||
// must match entire pattern | ||
// ending in a * or ** will make it less strict. | ||
re = "^(?:" + re + ")$" | ||
re = '^(?:' + re + ')$' | ||
// can match anything, as long as it's not this. | ||
if (this.negate) re = "^(?!" + re + ").*$" | ||
if (this.negate) re = '^(?!' + re + ').*$' | ||
try { | ||
return this.regexp = new RegExp(re, flags) | ||
this.regexp = new RegExp(re, flags) | ||
} catch (ex) { | ||
return this.regexp = false | ||
this.regexp = false | ||
} | ||
return this.regexp | ||
} | ||
@@ -682,9 +685,9 @@ | ||
function match (f, partial) { | ||
this.debug("match", f, this.pattern) | ||
this.debug('match', f, this.pattern) | ||
// short-circuit in the case of busted things. | ||
// comments, etc. | ||
if (this.comment) return false | ||
if (this.empty) return f === "" | ||
if (this.empty) return f === '' | ||
if (f === "/" && partial) return true | ||
if (f === '/' && partial) return true | ||
@@ -694,8 +697,9 @@ var options = this.options | ||
// windows: need to use /, not \ | ||
if (path.sep == '\\') | ||
f = f.split("\\").join("/") | ||
if (sep !== '/') { | ||
f = f.split(sep).join('/') | ||
} | ||
// treat the test path as a set of pathparts. | ||
f = f.split(slashSplit) | ||
this.debug(this.pattern, "split", f) | ||
this.debug(this.pattern, 'split', f) | ||
@@ -708,7 +712,8 @@ // just ONE of the pattern sets in this.set needs to match | ||
var set = this.set | ||
this.debug(this.pattern, "set", set) | ||
this.debug(this.pattern, 'set', set) | ||
// Find the basename of the path by looking for the last non-empty segment | ||
var filename; | ||
for (var i = f.length - 1; i >= 0; i--) { | ||
var filename | ||
var i | ||
for (i = f.length - 1; i >= 0; i--) { | ||
filename = f[i] | ||
@@ -718,4 +723,5 @@ if (filename) break | ||
for (var i = 0, l = set.length; i < l; i ++) { | ||
var pattern = set[i], file = f | ||
for (i = 0; i < set.length; i++) { | ||
var pattern = set[i] | ||
var file = f | ||
if (options.matchBase && pattern.length === 1) { | ||
@@ -745,19 +751,16 @@ file = [filename] | ||
this.debug("matchOne", | ||
{ "this": this | ||
, file: file | ||
, pattern: pattern }) | ||
this.debug('matchOne', | ||
{ 'this': this, file: file, pattern: pattern }) | ||
this.debug("matchOne", file.length, pattern.length) | ||
this.debug('matchOne', file.length, pattern.length) | ||
for ( var fi = 0 | ||
, pi = 0 | ||
, fl = file.length | ||
, pl = pattern.length | ||
for (var fi = 0, | ||
pi = 0, | ||
fl = file.length, | ||
pl = pattern.length | ||
; (fi < fl) && (pi < pl) | ||
; fi ++, pi ++ ) { | ||
this.debug("matchOne loop") | ||
; fi++, pi++) { | ||
this.debug('matchOne loop') | ||
var p = pattern[pi] | ||
, f = file[fi] | ||
var f = file[fi] | ||
@@ -796,3 +799,3 @@ this.debug(pattern, p, f) | ||
var fr = fi | ||
, pr = pi + 1 | ||
var pr = pi + 1 | ||
if (pr === pl) { | ||
@@ -806,5 +809,5 @@ this.debug('** at the end') | ||
// exponential reasons. | ||
for ( ; fi < fl; fi ++) { | ||
if (file[fi] === "." || file[fi] === ".." || | ||
(!options.dot && file[fi].charAt(0) === ".")) return false | ||
for (; fi < fl; fi++) { | ||
if (file[fi] === '.' || file[fi] === '..' || | ||
(!options.dot && file[fi].charAt(0) === '.')) return false | ||
} | ||
@@ -815,7 +818,6 @@ return true | ||
// ok, let's see if we can swallow whatever we can. | ||
WHILE: while (fr < fl) { | ||
while (fr < fl) { | ||
var swallowee = file[fr] | ||
this.debug('\nglobstar while', | ||
file, fr, pattern, pr, swallowee) | ||
this.debug('\nglobstar while', file, fr, pattern, pr, swallowee) | ||
@@ -830,6 +832,6 @@ // XXX remove this slice. Just pass the start index. | ||
// can only swallow ".foo" when explicitly asked. | ||
if (swallowee === "." || swallowee === ".." || | ||
(!options.dot && swallowee.charAt(0) === ".")) { | ||
this.debug("dot detected!", file, fr, pattern, pr) | ||
break WHILE | ||
if (swallowee === '.' || swallowee === '..' || | ||
(!options.dot && swallowee.charAt(0) === '.')) { | ||
this.debug('dot detected!', file, fr, pattern, pr) | ||
break | ||
} | ||
@@ -839,5 +841,6 @@ | ||
this.debug('globstar swallow a segment, and continue') | ||
fr ++ | ||
fr++ | ||
} | ||
} | ||
// no match was found. | ||
@@ -848,3 +851,3 @@ // However, in partial mode, we can't say this is necessarily over. | ||
// ran out of file | ||
this.debug("\n>>> no match, partial?", file, fr, pattern, pr) | ||
this.debug('\n>>> no match, partial?', file, fr, pattern, pr) | ||
if (fr === fl) return true | ||
@@ -859,3 +862,3 @@ } | ||
var hit | ||
if (typeof p === "string") { | ||
if (typeof p === 'string') { | ||
if (options.nocase) { | ||
@@ -866,6 +869,6 @@ hit = f.toLowerCase() === p.toLowerCase() | ||
} | ||
this.debug("string match", p, f, hit) | ||
this.debug('string match', p, f, hit) | ||
} else { | ||
hit = f.match(p) | ||
this.debug("pattern match", p, f, hit) | ||
this.debug('pattern match', p, f, hit) | ||
} | ||
@@ -902,3 +905,3 @@ | ||
// a/* should match a/b/ | ||
var emptyFileEnd = (fi === fl - 1) && (file[fi] === "") | ||
var emptyFileEnd = (fi === fl - 1) && (file[fi] === '') | ||
return emptyFileEnd | ||
@@ -908,14 +911,12 @@ } | ||
// should be unreachable. | ||
throw new Error("wtf?") | ||
throw new Error('wtf?') | ||
} | ||
// replace stuff like \* with * | ||
function globUnescape (s) { | ||
return s.replace(/\\(.)/g, "$1") | ||
return s.replace(/\\(.)/g, '$1') | ||
} | ||
function regExpEscape (s) { | ||
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") | ||
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') | ||
} |
@@ -5,3 +5,3 @@ { | ||
"description": "a glob matcher in javascript", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"repository": { | ||
@@ -13,2 +13,3 @@ "type": "git", | ||
"scripts": { | ||
"pretest": "standard minimatch.js test/*.js", | ||
"test": "tap test/*.js", | ||
@@ -25,2 +26,3 @@ "prepublish": "browserify -o browser.js -e minimatch.js --bare" | ||
"browserify": "^9.0.3", | ||
"standard": "^3.7.2", | ||
"tap": "" | ||
@@ -27,0 +29,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1672
55064
3
4
1
0