Comparing version 0.2.2 to 0.3.0
39
index.js
const dotRE = /\./g | ||
const globAnyRE = /\*\*/g | ||
const globEndRE = /\*\*$/g | ||
const globDirsRE = /\*\*\//g | ||
const globNamesRE = /\*/g | ||
var dotRE = /\./g | ||
var dotPattern = '\\.' | ||
function globRegex(glob) { | ||
const source = Array.isArray(glob) ? join(glob) : convert(glob) | ||
return new RegExp('^' + source + '$') | ||
var restRE = /\*\*$/g | ||
var restPattern = '(.+)' | ||
var globRE = /(?:\*\*\/|\*\*|\*)/g | ||
var globPatterns = { | ||
'*': '([^/]+)', // no backslashes | ||
'**': '(.+/)?([^/]+)', // short for "**/*" | ||
'**/': '(.+/)?', // one or more directories | ||
} | ||
function convert(glob) { | ||
function mapToPattern(str) { | ||
return globPatterns[str] | ||
} | ||
function replace(glob) { | ||
return glob | ||
.replace(dotRE, '\\.') | ||
.replace(globDirsRE, '(.+/)?') | ||
.replace(globEndRE, '(.+)') | ||
.replace(globAnyRE, '(.+/)?([^/]+)') | ||
.replace(globNamesRE, '([^/]+)') | ||
.replace(dotRE, dotPattern) | ||
.replace(restRE, restPattern) | ||
.replace(globRE, mapToPattern) | ||
} | ||
function join(globs) { | ||
return '((' + globs.map(convert).join(')|(') + '))' | ||
return '((' + globs.map(replace).join(')|(') + '))' | ||
} | ||
function globRegex(glob) { | ||
return new RegExp('^' + (Array.isArray(glob) ? join : replace)(glob) + '$') | ||
} | ||
globRegex.replace = replace | ||
module.exports = globRegex |
{ | ||
"name": "glob-regex", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
# glob-regex v0.2.2 | ||
# glob-regex v0.3.0 | ||
@@ -41,2 +41,4 @@ Convert a glob to a `RegExp` object. | ||
Use `globRegex.replace()` to transform a glob into a RegExp-compatible string. | ||
**NOTE:** It's not recommended to use `globRegex(array)` if you need | ||
@@ -43,0 +45,0 @@ the `exec` method, since the result will be difficult to make use of. |
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
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
47
3273
6
27