Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

minimatch

Package Overview
Dependencies
Maintainers
1
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minimatch - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

benchmark.js

266

minimatch.js

@@ -1,41 +0,7 @@

;(function (require, exports, module, platform) {
if (module) module.exports = minimatch
else exports.minimatch = minimatch
if (!require) {
require = function (id) {
switch (id) {
case "sigmund": return function sigmund (obj) {
return JSON.stringify(obj)
}
case "path": return { basename: function (f) {
f = f.split(/[\/\\]/)
var e = f.pop()
if (!e) e = f.pop()
return e
}}
case "lru-cache": return function LRUCache () {
// not quite an LRU, but still space-limited.
var cache = {}
var cnt = 0
this.set = function (k, v) {
cnt ++
if (cnt >= 100) cache = {}
cache[k] = v
}
this.get = function (k) { return cache[k] }
}
}
}
}
module.exports = minimatch
minimatch.Minimatch = Minimatch
var LRU = require("lru-cache")
, cache = minimatch.cache = new LRU({max: 100})
, GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
, sigmund = require("sigmund")
var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
, expand = require("brace-expansion")
var path = require("path")
// any single thing other than /

@@ -134,3 +100,3 @@ // don't need to escape / when using new RegExp()

if (!(this instanceof Minimatch)) {
return new Minimatch(pattern, options, cache)
return new Minimatch(pattern, options)
}

@@ -145,16 +111,2 @@

// windows: need to use /, not \
// On other platforms, \ is a valid (albeit bad) filename char.
if (platform === "win32") {
pattern = pattern.split("\\").join("/")
}
// lru storage.
// these things aren't particularly big, but walking down the string
// and turning it into a regexp can get pretty costly.
var cacheKey = pattern + "\n" + sigmund(options)
var cached = minimatch.cache.get(cacheKey)
if (cached) return cached
minimatch.cache.set(cacheKey, this)
this.options = options

@@ -261,3 +213,3 @@ this.set = []

minimatch.braceExpand = function (pattern, options) {
return new Minimatch(pattern, options).braceExpand()
return braceExpand(pattern, options)
}

@@ -267,10 +219,10 @@

function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
function braceExpand (pattern, options) {
if (!options) {
if (this instanceof Minimatch)
options = this.options
else
options = {}
}
function braceExpand (pattern, options) {
options = options || this.options
pattern = typeof pattern === "undefined"

@@ -289,183 +241,3 @@ ? this.pattern : pattern

var escaping = false
// examples and comments refer to this crazy pattern:
// a{b,c{d,e},{f,g}h}x{y,z}
// expected:
// abxy
// abxz
// acdxy
// acdxz
// acexy
// acexz
// afhxy
// afhxz
// aghxy
// aghxz
// everything before the first \{ is just a prefix.
// So, we pluck that off, and work with the rest,
// and then prepend it to everything we find.
if (pattern.charAt(0) !== "{") {
this.debug(pattern)
var prefix = null
for (var i = 0, l = pattern.length; i < l; i ++) {
var c = pattern.charAt(i)
this.debug(i, c)
if (c === "\\") {
escaping = !escaping
} else if (c === "{" && !escaping) {
prefix = pattern.substr(0, i)
break
}
}
// actually no sets, all { were escaped.
if (prefix === null) {
this.debug("no sets")
return [pattern]
}
var tail = braceExpand.call(this, pattern.substr(i), options)
return tail.map(function (t) {
return prefix + t
})
}
// now we have something like:
// {b,c{d,e},{f,g}h}x{y,z}
// walk through the set, expanding each part, until
// the set ends. then, we'll expand the suffix.
// If the set only has a single member, then'll put the {} back
// first, handle numeric sets, since they're easier
var numset = pattern.match(/^\{(-?[0-9]+)\.\.(-?[0-9]+)\}/)
if (numset) {
this.debug("numset", numset[1], numset[2])
var suf = braceExpand.call(this, pattern.substr(numset[0].length), options)
, start = +numset[1]
, needPadding = numset[1][0] === '0'
, startWidth = numset[1].length
, padded
, end = +numset[2]
, inc = start > end ? -1 : 1
, set = []
for (var i = start; i != (end + inc); i += inc) {
padded = needPadding ? pad(i, startWidth) : i + ''
// append all the suffixes
for (var ii = 0, ll = suf.length; ii < ll; ii ++) {
set.push(padded + suf[ii])
}
}
return set
}
// ok, walk through the set
// We hope, somewhat optimistically, that there
// will be a } at the end.
// If the closing brace isn't found, then the pattern is
// interpreted as braceExpand("\\" + pattern) so that
// the leading \{ will be interpreted literally.
var i = 1 // skip the \{
, depth = 1
, set = []
, member = ""
, sawEnd = false
, escaping = false
function addMember () {
set.push(member)
member = ""
}
this.debug("Entering for")
FOR: for (i = 1, l = pattern.length; i < l; i ++) {
var c = pattern.charAt(i)
this.debug("", i, c)
if (escaping) {
escaping = false
member += "\\" + c
} else {
switch (c) {
case "\\":
escaping = true
continue
case "{":
depth ++
member += "{"
continue
case "}":
depth --
// if this closes the actual set, then we're done
if (depth === 0) {
addMember()
// pluck off the close-brace
i ++
break FOR
} else {
member += c
continue
}
case ",":
if (depth === 1) {
addMember()
} else {
member += c
}
continue
default:
member += c
continue
} // switch
} // else
} // for
// now we've either finished the set, and the suffix is
// pattern.substr(i), or we have *not* closed the set,
// and need to escape the leading brace
if (depth !== 0) {
this.debug("didn't close", pattern)
return braceExpand.call(this, "\\" + pattern, options)
}
// x{y,z} -> ["xy", "xz"]
this.debug("set", set)
this.debug("suffix", pattern.substr(i))
var suf = braceExpand.call(this, pattern.substr(i), options)
// ["b", "c{d,e}","{f,g}h"] ->
// [["b"], ["cd", "ce"], ["fh", "gh"]]
var addBraces = set.length === 1
this.debug("set pre-expanded", set)
set = set.map(function (p) {
return braceExpand.call(this, p, options)
}, this)
this.debug("set expanded", set)
// [["b"], ["cd", "ce"], ["fh", "gh"]] ->
// ["b", "cd", "ce", "fh", "gh"]
set = set.reduce(function (l, r) {
return l.concat(r)
})
if (addBraces) {
set = set.map(function (s) {
return "{" + s + "}"
})
}
// now attach the suffixes.
var ret = []
for (var i = 0, l = set.length; i < l; i ++) {
for (var ii = 0, ll = suf.length; ii < ll; ii ++) {
ret.push(set[i] + suf[ii])
}
}
return ret
return expand(pattern)
}

@@ -856,8 +628,2 @@

// windows: need to use /, not \
// On other platforms, \ is a valid (albeit bad) filename char.
if (platform === "win32") {
f = f.split("\\").join("/")
}
// treat the test path as a set of pathparts.

@@ -1074,7 +840,1 @@ f = f.split(slashSplit)

}
})( typeof require === "function" ? require : null,
this,
typeof module === "object" ? module : null,
typeof process === "object" ? process.platform : "win32"
)

@@ -5,3 +5,3 @@ {

"description": "a glob matcher in javascript",
"version": "1.0.0",
"version": "2.0.0",
"repository": {

@@ -13,3 +13,4 @@ "type": "git",

"scripts": {
"test": "tap test/*.js"
"test": "tap test/*.js",
"prepublish": "browserify -o browser.js -e minimatch.js"
},

@@ -20,6 +21,6 @@ "engines": {

"dependencies": {
"lru-cache": "2",
"sigmund": "~1.0.0"
"brace-expansion": "^1.0.0"
},
"devDependencies": {
"browserify": "^6.3.3",
"tap": ""

@@ -26,0 +27,0 @@ },

@@ -10,4 +10,2 @@ # minimatch

Eventually, it will replace the C binding in node-glob.
It works by converting glob expressions into JavaScript `RegExp`

@@ -14,0 +12,0 @@ objects.

@@ -384,3 +384,3 @@ // http://www.bashcookbook.com/bashinfo/source/bash-1.14.7/tests/glob-test

t.equal(tapOpts.re, expectRe, tapOpts)
t.equal(tapOpts.re, expectRe, null, tapOpts)
})

@@ -387,0 +387,0 @@

@@ -25,8 +25,13 @@ var tap = require("tap")

, [ "a{00..05}b"
, ["a00b"
,"a01b"
,"a02b"
,"a03b"
,"a04b"
,"a05b" ] ]
, [ "a00b"
, "a01b"
, "a02b"
, "a03b"
, "a04b"
, "a05b" ] ]
, [ "z{a,b},c}d", ["za,c}d", "zb,c}d"] ]
, [ "z{a,b{,c}d", ["z{a,bd", "z{a,bcd"] ]
, [ "a{b{c{d,e}f}g}h", ["a{b{cdf}g}h", "a{b{cef}g}h"] ]
, [ "a{b{c{d,e}f{x,y}}g}h", ["a{b{cdfx}g}h", "a{b{cdfy}g}h", "a{b{cefx}g}h", "a{b{cefy}g}h"] ]
, [ "a{b{c{d,e}f{x,y{}g}h", ["a{b{cdfxh", "a{b{cdfy{}gh", "a{b{cefxh", "a{b{cefy{}gh"] ]
].forEach(function (tc) {

@@ -33,0 +38,0 @@ var p = tc[0]

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc