Comparing version 0.0.1 to 0.1.0
17
index.js
const dotRE = /\./g | ||
const globAllRE = /\*\*/g | ||
const globDirsRE = /\*\*\//g | ||
const globNamesRE = /\*/g | ||
function globRegex(glob) { | ||
if (Array.isArray(glob)) { | ||
glob = '((' + glob.join(')|(') + '))' | ||
} | ||
const pattern = glob | ||
.replace('.', '\\.') | ||
.replace('**/', '(.+\\/)?') | ||
.replace('**', '(.+\\/)?*') | ||
.replace('*', '[^\\/]+') | ||
.replace(dotRE, '\\.') | ||
.replace(globDirsRE, '(.+/)?') | ||
.replace(globAllRE, '(.+/)?*') | ||
.replace(globNamesRE, '[^/]+') | ||
@@ -9,0 +18,0 @@ return new RegExp('^' + pattern + '$') |
{ | ||
"name": "glob-regex", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
# glob-regex v0.0.1 | ||
# glob-regex v0.1.0 | ||
@@ -4,0 +4,0 @@ Convert a glob to a `RegExp` object. |
15
test.js
@@ -16,2 +16,10 @@ #!/usr/bin/env node | ||
}, | ||
'*/*.js': { | ||
'a.js': false, | ||
'a/b.js': true, | ||
'a/b/c.js': false, | ||
'a/b.css': false, | ||
'.js': false, | ||
'': false, | ||
}, | ||
'**.js': { | ||
@@ -74,1 +82,8 @@ 'a.js': true, | ||
}) | ||
test('an array can be passed', (t) => { | ||
const re = globRegex(['*.js', '*.css']) | ||
t.assert(!re.test('a.jsx')) | ||
t.assert(re.test('a.js')) | ||
t.assert(re.test('b.css')) | ||
}) |
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
4316
96