Comparing version 0.0.1 to 0.0.3
@@ -8,17 +8,2 @@ | ||
var gexstr = ''+gexexp | ||
if( _.isNull(gexexp) | ||
|| _.isNaN(gexexp) | ||
|| _.isUndefined(gexexp) ) { | ||
gexstr = '' | ||
} | ||
gexstr = gexstr.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); | ||
gexstr = gexstr.replace(/\\\*/g,'.*') | ||
gexstr = gexstr.replace(/\\\?/g,'.') | ||
gexstr = '^'+gexstr+'$' | ||
var re = new RegExp(gexstr) | ||
function dodgy(obj) { | ||
@@ -30,2 +15,31 @@ return ( _.isNull(obj) | ||
function clean(gexexp) { | ||
var gexstr = ''+gexexp | ||
if( _.isNull(gexexp) | ||
|| _.isNaN(gexexp) | ||
|| _.isUndefined(gexexp) ) { | ||
gexstr = '' | ||
} | ||
return gexstr | ||
} | ||
function gexstr(gexexp) { | ||
var gs = [] | ||
if( _.isArray(gexexp) || _.isArguments(gexexp) ) { | ||
for( var i = 0; i < gexexp.length; i++ ){ | ||
var s = clean(gexexp[i]) | ||
gexexp.push( | ||
( '*' == s || '?' == s ) ? s | ||
: self.esc(s) | ||
) | ||
} | ||
gs = gs.join('') | ||
} | ||
else { | ||
gs = clean(gexexp) | ||
} | ||
return gs | ||
} | ||
self.on = function(obj) { | ||
@@ -74,2 +88,44 @@ if( _.isString(obj) | ||
} | ||
self.esc = function(gexexp) { | ||
var gexstr = clean(gexexp) | ||
gexstr = gexstr.replace(/\*/g,'**') | ||
gexstr = gexstr.replace(/\?/g,'*?') | ||
return gexstr | ||
} | ||
self.re = function(gs) { | ||
if( '' == gs || gs ) { | ||
var gs = self.escregexp(gs) | ||
// use [\s\S] instead of . to match newlines | ||
gs = gs.replace(/\\\*/g,'[\\s\\S]*') | ||
gs = gs.replace(/\\\?/g,'[\\s\\S]') | ||
//gs = gs.replace(/\\\*/g,'.*') | ||
//gs = gs.replace(/\\\?/g,'.') | ||
// escapes ** and *? | ||
gs = gs.replace(/\[\\s\\S\]\*\[\\s\\S\]\*/g,'\\\*') | ||
gs = gs.replace(/\[\\s\\S\]\*\[\\s\\S\]/g,'\\\?') | ||
gs = '^'+gs+'$' | ||
return new RegExp(gs) | ||
} | ||
else { | ||
return re | ||
} | ||
} | ||
self.escregexp = function(restr) { | ||
return restr ? (''+restr).replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") : '' | ||
} | ||
self.toString = function() { | ||
return str | ||
} | ||
var str = gexstr(gexexp) | ||
var re = self.re(str) | ||
} | ||
@@ -76,0 +132,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"keywords": ["glob","star","question","mark","expression","regular"], | ||
"version": "0.0.1", | ||
"version": "0.0.3", | ||
"homepage": "https://github.com/rjrodger/gex", | ||
@@ -8,0 +8,0 @@ "author": "Richard Rodger <richard@ricebridge.com> (http://richardrodger.com/)", |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
6060
111
0
1