Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "globrex", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Glob to regex", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -8,9 +8,10 @@ 'use strict'; | ||
* @param {String} glob Glob pattern to convert | ||
* @param {Object} options Configuration object | ||
* @returns {RegExp} converted RegExp object | ||
* @param {Object} opts Configuration object | ||
* @param {Boolean} [opts.extended=false] Support advanced ext globbing | ||
* @param {Boolean} [opts.globstar=false] Support globstar | ||
* @param {Boolean} [opts.strict=true] be laissez faire about mutiple slashes | ||
* @param {String} [opts.flags=''] RegExp globs | ||
* @returns {Object} converted object with string, segments and RegExp object | ||
*/ | ||
function globrex(glob, { extended = false, globstar = false, strict = false, flags = ''} = {}) { | ||
let str = String(glob); | ||
// The regexp we are building, as a string. | ||
let reStr = ''; | ||
@@ -47,5 +48,5 @@ | ||
let n; // next char | ||
for (var i = 0, len = str.length; i < len; i++) { | ||
c = str[i]; | ||
n = str[i + 1] || null; | ||
for (var i = 0, len = glob.length; i < len; i++) { | ||
c = glob[i]; | ||
n = glob[i + 1] || null; | ||
@@ -142,3 +143,3 @@ switch (c) { | ||
let value = ''; | ||
while(str[++i] !== ':') value += str[i]; | ||
while(glob[++i] !== ':') value += glob[i]; | ||
if (value === 'alnum') add('(\\w|\\d)'); | ||
@@ -193,9 +194,9 @@ else if (value === 'space') add('\\s'); | ||
// Also store the previous and next characters | ||
let prevChar = str[i - 1]; | ||
let prevChar = glob[i - 1]; | ||
let starCount = 1; | ||
while (str[i + 1] === '*') { | ||
while (glob[i + 1] === '*') { | ||
starCount++; | ||
i++; | ||
} | ||
let nextChar = str[i + 1]; | ||
let nextChar = glob[i + 1]; | ||
@@ -235,11 +236,6 @@ if (!globstar) { | ||
// Push the last segment / the rest | ||
// Push the last segment | ||
segments.push(new RegExp(segment, flags)); | ||
/* | ||
if (pathsegments) { | ||
return { segments, full: new RegExp(reStr, flags) } | ||
} | ||
*/ | ||
return { regex: new RegExp(reStr, flags), string: reStr, segments }; | ||
} |
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
18511
207