diff options
Diffstat (limited to 'node_modules/glob-to-regexp')
-rw-r--r-- | node_modules/glob-to-regexp/.travis.yml | 4 | ||||
-rw-r--r-- | node_modules/glob-to-regexp/README.md | 75 | ||||
-rw-r--r-- | node_modules/glob-to-regexp/index.js | 131 | ||||
-rw-r--r-- | node_modules/glob-to-regexp/package.json | 59 | ||||
-rw-r--r-- | node_modules/glob-to-regexp/test.js | 227 |
5 files changed, 496 insertions, 0 deletions
diff --git a/node_modules/glob-to-regexp/.travis.yml b/node_modules/glob-to-regexp/.travis.yml new file mode 100644 index 0000000..ddc9c4f --- /dev/null +++ b/node_modules/glob-to-regexp/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - 0.8 + - "0.10"
\ No newline at end of file diff --git a/node_modules/glob-to-regexp/README.md b/node_modules/glob-to-regexp/README.md new file mode 100644 index 0000000..afb4114 --- /dev/null +++ b/node_modules/glob-to-regexp/README.md @@ -0,0 +1,75 @@ +# Glob To Regular Expression + +[![Build Status](https://travis-ci.org/fitzgen/glob-to-regexp.png?branch=master)](https://travis-ci.org/fitzgen/glob-to-regexp) + +Turn a \*-wildcard style glob (`"*.min.js"`) into a regular expression +(`/^.*\.min\.js$/`)! + +To match bash-like globs, eg. `?` for any single-character match, `[a-z]` for +character ranges, and `{*.html, *.js}` for multiple alternatives, call with +`{ extended: true }`. + +To obey [globstars `**`](https://github.com/isaacs/node-glob#glob-primer) rules set option `{globstar: true}`. +NOTE: This changes the behavior of `*` when `globstar` is `true` as shown below: +When `{globstar: true}`: `/foo/**` will match any string that starts with `/foo/` +like `/foo/index.htm`, `/foo/bar/baz.txt`, etc. Also, `/foo/**/*.txt` will match +any string that starts with `/foo/` and ends with `.txt` like `/foo/bar.txt`, +`/foo/bar/baz.txt`, etc. +Whereas `/foo/*` (single `*`, not a globstar) will match strings that start with +`/foo/` like `/foo/index.htm`, `/foo/baz.txt` but will not match strings that +contain a `/` to the right like `/foo/bar/baz.txt`, `/foo/bar/baz/qux.dat`, etc. + +Set flags on the resulting `RegExp` object by adding the `flags` property to the option object, eg `{ flags: "i" }` for ignoring case. + +## Install + + npm install glob-to-regexp + +## Usage +```js +var globToRegExp = require('glob-to-regexp'); +var re = globToRegExp("p*uck"); +re.test("pot luck"); // true +re.test("pluck"); // true +re.test("puck"); // true + +re = globToRegExp("*.min.js"); +re.test("http://example.com/jquery.min.js"); // true +re.test("http://example.com/jquery.min.js.map"); // false + +re = globToRegExp("*/www/*.js"); +re.test("http://example.com/www/app.js"); // true +re.test("http://example.com/www/lib/factory-proxy-model-observer.js"); // true + +// Extended globs +re = globToRegExp("*/www/{*.js,*.html}", { extended: true }); +re.test("http://example.com/www/app.js"); // true +re.test("http://example.com/www/index.html"); // true +``` + +## License + +Copyright (c) 2013, Nick Fitzgerald + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/node_modules/glob-to-regexp/index.js b/node_modules/glob-to-regexp/index.js new file mode 100644 index 0000000..03bd090 --- /dev/null +++ b/node_modules/glob-to-regexp/index.js @@ -0,0 +1,131 @@ +module.exports = function (glob, opts) { + if (typeof glob !== 'string') { + throw new TypeError('Expected a string'); + } + + var str = String(glob); + + // The regexp we are building, as a string. + var reStr = ""; + + // Whether we are matching so called "extended" globs (like bash) and should + // support single character matching, matching ranges of characters, group + // matching, etc. + var extended = opts ? !!opts.extended : false; + + // When globstar is _false_ (default), '/foo/*' is translated a regexp like + // '^\/foo\/.*$' which will match any string beginning with '/foo/' + // When globstar is _true_, '/foo/*' is translated to regexp like + // '^\/foo\/[^/]*$' which will match any string beginning with '/foo/' BUT + // which does not have a '/' to the right of it. + // E.g. with '/foo/*' these will match: '/foo/bar', '/foo/bar.txt' but + // these will not '/foo/bar/baz', '/foo/bar/baz.txt' + // Lastely, when globstar is _true_, '/foo/**' is equivelant to '/foo/*' when + // globstar is _false_ + var globstar = opts ? !!opts.globstar : false; + + // If we are doing extended matching, this boolean is true when we are inside + // a group (eg {*.html,*.js}), and false otherwise. + var inGroup = false; + + // RegExp flags (eg "i" ) to pass in to RegExp constructor. + var flags = opts && typeof( opts.flags ) === "string" ? opts.flags : ""; + + var c; + for (var i = 0, len = str.length; i < len; i++) { + c = str[i]; + + switch (c) { + case "\\": + case "/": + case "$": + case "^": + case "+": + case ".": + case "(": + case ")": + case "=": + case "!": + case "|": + reStr += "\\" + c; + break; + + case "?": + if (extended) { + reStr += "."; + break; + } + + case "[": + case "]": + if (extended) { + reStr += c; + break; + } + + case "{": + if (extended) { + inGroup = true; + reStr += "("; + break; + } + + case "}": + if (extended) { + inGroup = false; + reStr += ")"; + break; + } + + case ",": + if (inGroup) { + reStr += "|"; + break; + } + reStr += "\\" + c; + break; + + case "*": + // Move over all consecutive "*"'s. + // Also store the previous and next characters + var prevChar = str[i - 1]; + var starCount = 1; + while(str[i + 1] === "*") { + starCount++; + i++; + } + var nextChar = str[i + 1]; + + if (!globstar) { + // globstar is disabled, so treat any number of "*" as one + reStr += ".*"; + } else { + // globstar is enabled, so determine if this is a globstar segment + var isGlobstar = starCount > 1 // multiple "*"'s + && (prevChar === "/" || prevChar === undefined) // from the start of the segment + && (nextChar === "/" || nextChar === undefined) // to the end of the segment + + if (isGlobstar) { + // it's a globstar, so match zero or more path segments + reStr += "(?:[^/]*(?:\/|$))*"; + i++; // move over the "/" + } else { + // it's not a globstar, so only match one path segment + reStr += "[^/]*"; + } + } + break; + + default: + reStr += c; + } + } + + // When regexp 'g' flag is specified don't + // constrain the regular expression with ^ & $ + if (!flags || !~flags.indexOf('g')) { + reStr = "^" + reStr + "$"; + } + + return new RegExp(reStr, flags); +}; diff --git a/node_modules/glob-to-regexp/package.json b/node_modules/glob-to-regexp/package.json new file mode 100644 index 0000000..c7b049f --- /dev/null +++ b/node_modules/glob-to-regexp/package.json @@ -0,0 +1,59 @@ +{ + "_args": [ + [ + "[email protected]", + "/home/dstaesse/git/website" + ] + ], + "_development": true, + "_from": "[email protected]", + "_id": "[email protected]", + "_inBundle": false, + "_integrity": "sha1-jFoUlNIGbFcMw7/kSWF1rMTVAqs=", + "_location": "/glob-to-regexp", + "_phantomChildren": {}, + "_requested": { + "type": "version", + "registry": true, + "raw": "[email protected]", + "name": "glob-to-regexp", + "escapedName": "glob-to-regexp", + "rawSpec": "0.3.0", + "saveSpec": null, + "fetchSpec": "0.3.0" + }, + "_requiredBy": [ + "/@mrmlnc/readdir-enhanced" + ], + "_resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz", + "_spec": "0.3.0", + "_where": "/home/dstaesse/git/website", + "author": { + "name": "Nick Fitzgerald", + "email": "[email protected]" + }, + "bugs": { + "url": "https://github.com/fitzgen/glob-to-regexp/issues" + }, + "description": "Convert globs to regular expressions", + "homepage": "https://github.com/fitzgen/glob-to-regexp#readme", + "keywords": [ + "regexp", + "glob", + "regexps", + "regular expressions", + "regular expression", + "wildcard" + ], + "license": "BSD", + "main": "index.js", + "name": "glob-to-regexp", + "repository": { + "type": "git", + "url": "git+https://github.com/fitzgen/glob-to-regexp.git" + }, + "scripts": { + "test": "node test.js" + }, + "version": "0.3.0" +} diff --git a/node_modules/glob-to-regexp/test.js b/node_modules/glob-to-regexp/test.js new file mode 100644 index 0000000..58f1080 --- /dev/null +++ b/node_modules/glob-to-regexp/test.js @@ -0,0 +1,227 @@ +var globToRegexp = require("./index.js"); +var assert = require("assert"); + +function assertMatch(glob, str, opts) { + //console.log(glob, globToRegexp(glob, opts)); + assert.ok(globToRegexp(glob, opts).test(str)); +} + +function assertNotMatch(glob, str, opts) { + //console.log(glob, globToRegexp(glob, opts)); + assert.equal(false, globToRegexp(glob, opts).test(str)); +} + +function test(globstar) { + // Match everything + assertMatch("*", "foo"); + assertMatch("*", "foo", { flags: 'g' }); + + // Match the end + assertMatch("f*", "foo"); + assertMatch("f*", "foo", { flags: 'g' }); + + // Match the start + assertMatch("*o", "foo"); + assertMatch("*o", "foo", { flags: 'g' }); + + // Match the middle + assertMatch("f*uck", "firetruck"); + assertMatch("f*uck", "firetruck", { flags: 'g' }); + + // Don't match without Regexp 'g' + assertNotMatch("uc", "firetruck"); + // Match anywhere with RegExp 'g' + assertMatch("uc", "firetruck", { flags: 'g' }); + + // Match zero characters + assertMatch("f*uck", "fuck"); + assertMatch("f*uck", "fuck", { flags: 'g' }); + + // More complex matches + assertMatch("*.min.js", "http://example.com/jquery.min.js", {globstar: false}); + assertMatch("*.min.*", "http://example.com/jquery.min.js", {globstar: false}); + assertMatch("*/js/*.js", "http://example.com/js/jquery.min.js", {globstar: false}); + + // More complex matches with RegExp 'g' flag (complex regression) + assertMatch("*.min.*", "http://example.com/jquery.min.js", { flags: 'g' }); + assertMatch("*.min.js", "http://example.com/jquery.min.js", { flags: 'g' }); + assertMatch("*/js/*.js", "http://example.com/js/jquery.min.js", { flags: 'g' }); + + var testStr = "\\/$^+?.()=!|{},[].*" + assertMatch(testStr, testStr); + assertMatch(testStr, testStr, { flags: 'g' }); + + // Equivalent matches without/with using RegExp 'g' + assertNotMatch(".min.", "http://example.com/jquery.min.js"); + assertMatch("*.min.*", "http://example.com/jquery.min.js"); + assertMatch(".min.", "http://example.com/jquery.min.js", { flags: 'g' }); + + assertNotMatch("http:", "http://example.com/jquery.min.js"); + assertMatch("http:*", "http://example.com/jquery.min.js"); + assertMatch("http:", "http://example.com/jquery.min.js", { flags: 'g' }); + + assertNotMatch("min.js", "http://example.com/jquery.min.js"); + assertMatch("*.min.js", "http://example.com/jquery.min.js"); + assertMatch("min.js", "http://example.com/jquery.min.js", { flags: 'g' }); + + // Match anywhere (globally) using RegExp 'g' + assertMatch("min", "http://example.com/jquery.min.js", { flags: 'g' }); + assertMatch("/js/", "http://example.com/js/jquery.min.js", { flags: 'g' }); + + assertNotMatch("/js*jq*.js", "http://example.com/js/jquery.min.js"); + assertMatch("/js*jq*.js", "http://example.com/js/jquery.min.js", { flags: 'g' }); + + // Extended mode + + // ?: Match one character, no more and no less + assertMatch("f?o", "foo", { extended: true }); + assertNotMatch("f?o", "fooo", { extended: true }); + assertNotMatch("f?oo", "foo", { extended: true }); + + // ?: Match one character with RegExp 'g' + assertMatch("f?o", "foo", { extended: true, globstar: globstar, flags: 'g' }); + assertMatch("f?o", "fooo", { extended: true, globstar: globstar, flags: 'g' }); + assertMatch("f?o?", "fooo", { extended: true, globstar: globstar, flags: 'g' }); + assertNotMatch("?fo", "fooo", { extended: true, globstar: globstar, flags: 'g' }); + assertNotMatch("f?oo", "foo", { extended: true, globstar: globstar, flags: 'g' }); + assertNotMatch("foo?", "foo", { extended: true, globstar: globstar, flags: 'g' }); + + // []: Match a character range + assertMatch("fo[oz]", "foo", { extended: true }); + assertMatch("fo[oz]", "foz", { extended: true }); + assertNotMatch("fo[oz]", "fog", { extended: true }); + + // []: Match a character range and RegExp 'g' (regresion) + assertMatch("fo[oz]", "foo", { extended: true, globstar: globstar, flags: 'g' }); + assertMatch("fo[oz]", "foz", { extended: true, globstar: globstar, flags: 'g' }); + assertNotMatch("fo[oz]", "fog", { extended: true, globstar: globstar, flags: 'g' }); + + // {}: Match a choice of different substrings + assertMatch("foo{bar,baaz}", "foobaaz", { extended: true }); + assertMatch("foo{bar,baaz}", "foobar", { extended: true }); + assertNotMatch("foo{bar,baaz}", "foobuzz", { extended: true }); + assertMatch("foo{bar,b*z}", "foobuzz", { extended: true }); + + // {}: Match a choice of different substrings and RegExp 'g' (regression) + assertMatch("foo{bar,baaz}", "foobaaz", { extended: true, globstar: globstar, flags: 'g' }); + assertMatch("foo{bar,baaz}", "foobar", { extended: true, globstar: globstar, flags: 'g' }); + assertNotMatch("foo{bar,baaz}", "foobuzz", { extended: true, globstar: globstar, flags: 'g' }); + assertMatch("foo{bar,b*z}", "foobuzz", { extended: true, globstar: globstar, flags: 'g' }); + + // More complex extended matches + assertMatch("http://?o[oz].b*z.com/{*.js,*.html}", + "http://foo.baaz.com/jquery.min.js", + { extended: true }); + assertMatch("http://?o[oz].b*z.com/{*.js,*.html}", + "http://moz.buzz.com/index.html", + { extended: true }); + assertNotMatch("http://?o[oz].b*z.com/{*.js,*.html}", + "http://moz.buzz.com/index.htm", + { extended: true }); + assertNotMatch("http://?o[oz].b*z.com/{*.js,*.html}", + "http://moz.bar.com/index.html", + { extended: true }); + assertNotMatch("http://?o[oz].b*z.com/{*.js,*.html}", + "http://flozz.buzz.com/index.html", + { extended: true }); + + // More complex extended matches and RegExp 'g' (regresion) + assertMatch("http://?o[oz].b*z.com/{*.js,*.html}", + "http://foo.baaz.com/jquery.min.js", + { extended: true, globstar: globstar, flags: 'g' }); + assertMatch("http://?o[oz].b*z.com/{*.js,*.html}", + "http://moz.buzz.com/index.html", + { extended: true, globstar: globstar, flags: 'g' }); + assertNotMatch("http://?o[oz].b*z.com/{*.js,*.html}", + "http://moz.buzz.com/index.htm", + { extended: true, globstar: globstar, flags: 'g' }); + assertNotMatch("http://?o[oz].b*z.com/{*.js,*.html}", + "http://moz.bar.com/index.html", + { extended: true, globstar: globstar, flags: 'g' }); + assertNotMatch("http://?o[oz].b*z.com/{*.js,*.html}", + "http://flozz.buzz.com/index.html", + { extended: true, globstar: globstar, flags: 'g' }); + + // globstar + assertMatch("http://foo.com/**/{*.js,*.html}", + "http://foo.com/bar/jquery.min.js", + { extended: true, globstar: globstar, flags: 'g' }); + assertMatch("http://foo.com/**/{*.js,*.html}", + "http://foo.com/bar/baz/jquery.min.js", + { extended: true, globstar: globstar, flags: 'g' }); + assertMatch("http://foo.com/**", + "http://foo.com/bar/baz/jquery.min.js", + { extended: true, globstar: globstar, flags: 'g' }); + + // Remaining special chars should still match themselves + var testExtStr = "\\/$^+.()=!|,.*" + assertMatch(testExtStr, testExtStr, { extended: true }); + assertMatch(testExtStr, testExtStr, { extended: true, globstar: globstar, flags: 'g' }); +} + +// regression +// globstar false +test(false) +// globstar true +test(true); + +// globstar specific tests +assertMatch("/foo/*", "/foo/bar.txt", {globstar: true }); +assertMatch("/foo/**", "/foo/baz.txt", {globstar: true }); +assertMatch("/foo/**", "/foo/bar/baz.txt", {globstar: true }); +assertMatch("/foo/*/*.txt", "/foo/bar/baz.txt", {globstar: true }); +assertMatch("/foo/**/*.txt", "/foo/bar/baz.txt", {globstar: true }); +assertMatch("/foo/**/*.txt", "/foo/bar/baz/qux.txt", {globstar: true }); +assertMatch("/foo/**/bar.txt", "/foo/bar.txt", {globstar: true }); +assertMatch("/foo/**/**/bar.txt", "/foo/bar.txt", {globstar: true }); +assertMatch("/foo/**/*/baz.txt", "/foo/bar/baz.txt", {globstar: true }); +assertMatch("/foo/**/*.txt", "/foo/bar.txt", {globstar: true }); +assertMatch("/foo/**/**/*.txt", "/foo/bar.txt", {globstar: true }); +assertMatch("/foo/**/*/*.txt", "/foo/bar/baz.txt", {globstar: true }); +assertMatch("**/*.txt", "/foo/bar/baz/qux.txt", {globstar: true }); +assertMatch("**/foo.txt", "foo.txt", {globstar: true }); +assertMatch("**/*.txt", "foo.txt", {globstar: true }); + +assertNotMatch("/foo/*", "/foo/bar/baz.txt", {globstar: true }); +assertNotMatch("/foo/*.txt", "/foo/bar/baz.txt", {globstar: true }); +assertNotMatch("/foo/*/*.txt", "/foo/bar/baz/qux.txt", {globstar: true }); +assertNotMatch("/foo/*/bar.txt", "/foo/bar.txt", {globstar: true }); +assertNotMatch("/foo/*/*/baz.txt", "/foo/bar/baz.txt", {globstar: true }); +assertNotMatch("/foo/**.txt", "/foo/bar/baz/qux.txt", {globstar: true }); +assertNotMatch("/foo/bar**/*.txt", "/foo/bar/baz/qux.txt", {globstar: true }); +assertNotMatch("/foo/bar**", "/foo/bar/baz.txt", {globstar: true }); +assertNotMatch("**/.txt", "/foo/bar/baz/qux.txt", {globstar: true }); +assertNotMatch("*/*.txt", "/foo/bar/baz/qux.txt", {globstar: true }); +assertNotMatch("*/*.txt", "foo.txt", {globstar: true }); + +assertNotMatch("http://foo.com/*", + "http://foo.com/bar/baz/jquery.min.js", + { extended: true, globstar: true }); +assertNotMatch("http://foo.com/*", + "http://foo.com/bar/baz/jquery.min.js", + { globstar: true }); + +assertMatch("http://foo.com/*", + "http://foo.com/bar/baz/jquery.min.js", + { globstar: false }); +assertMatch("http://foo.com/**", + "http://foo.com/bar/baz/jquery.min.js", + { globstar: true }); + +assertMatch("http://foo.com/*/*/jquery.min.js", + "http://foo.com/bar/baz/jquery.min.js", + { globstar: true }); +assertMatch("http://foo.com/**/jquery.min.js", + "http://foo.com/bar/baz/jquery.min.js", + { globstar: true }); +assertMatch("http://foo.com/*/*/jquery.min.js", + "http://foo.com/bar/baz/jquery.min.js", + { globstar: false }); +assertMatch("http://foo.com/*/jquery.min.js", + "http://foo.com/bar/baz/jquery.min.js", + { globstar: false }); +assertNotMatch("http://foo.com/*/jquery.min.js", + "http://foo.com/bar/baz/jquery.min.js", + { globstar: true }); + +console.log("Ok!"); |