Comparing version 0.1.4 to 0.2.0
@@ -1,3 +0,3 @@ | ||
/* Copyright (c) 2011-2013 Richard Rodger, MIT License, https://github.com/rjrodger/patrun */ | ||
(function(){"use strict";function e(e){function r(e){return u.isNull(e)||u.isNaN(e)||u.isUndefined(e)}function i(e){var r=""+e;return(u.isNull(e)||u.isNaN(e)||u.isUndefined(e))&&(r=""),r}function s(e){e=""+e;for(var r=!1,n=u.keys(c),t=0;t<n.length&&!r;t++)r=!!c[n[t]].exec(e);return r}var o=this;o.noConflict=function(){return n.gex=t,o},o.on=function(e){if(u.isString(e)||u.isNumber(e)||u.isBoolean(e)||u.isDate(e)||u.isRegExp(e))return s(e)?e:null;if(u.isArray(e)||u.isArguments(e)){for(var n=[],t=0;t<e.length;t++)!r(e[t])&&s(e[t])&&n.push(e[t]);return n}if(r(e))return null;if(u.isObject(e)){var n={};for(var i in e)e.hasOwnProperty(i)&&s(i)&&(n[i]=e[i]);return n}return null},o.esc=function(e){var r=i(e);return r=r.replace(/\*/g,"**"),r=r.replace(/\?/g,"*?")},o.re=function(e){if(""==e||e){var e=o.escregexp(e);return e=e.replace(/\\\*/g,"[\\s\\S]*"),e=e.replace(/\\\?/g,"[\\s\\S]"),e=e.replace(/\[\\s\\S\]\*\[\\s\\S\]\*/g,"\\*"),e=e.replace(/\[\\s\\S\]\*\[\\s\\S\]/g,"\\?"),e="^"+e+"$",new RegExp(e)}var r=u.keys(c);return 1==r.length?c[r[0]]:u.clone(c)},o.escregexp=function(e){return e?(""+e).replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"):""},o.toString=function(){return""+u.keys(c)};var f=null==e||u.isNaN(e)?[]:u.isArray(e)?e:[e],c={};u.each(f,function(e){var r=o.re(e);c[e]=r})}function r(r){var n=new e(r);return n}var n=this,t=n.gex,i="undefined"!=typeof require,u=n._;if("undefined"==typeof u){if(!i)throw new Error("gex requires underscore, see http://underscorejs.org");u=require("underscore")}r.Gex=e,"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=r),exports.gex=r):n.gex=r}).call(this); | ||
/* Copyright (c) 2011-2015 Richard Rodger, MIT License */ | ||
(function(){"use strict";function e(e){function r(e){return u.isNull(e)||u.isNaN(e)||u.isUndefined(e)}function i(e){var r=""+e;return(u.isNull(e)||u.isNaN(e)||u.isUndefined(e))&&(r=""),r}function s(e){e=""+e;for(var r=!1,n=u.keys(c),t=0;t<n.length&&!r;t++)r=!!c[n[t]].exec(e);return r}var o=this;o.noConflict=function(){return n.gex=t,o},o.on=function(e){if(u.isString(e)||u.isNumber(e)||u.isBoolean(e)||u.isDate(e)||u.isRegExp(e))return s(e)?e:null;if(u.isArray(e)||u.isArguments(e)){for(var n=[],t=0;t<e.length;t++)!r(e[t])&&s(e[t])&&n.push(e[t]);return n}if(r(e))return null;if(u.isObject(e)){var i={};for(var o in e)e.hasOwnProperty(o)&&s(o)&&(i[o]=e[o]);return i}return null},o.esc=function(e){var r=i(e);return r=r.replace(/\*/g,"**"),r=r.replace(/\?/g,"*?")},o.re=function(e){if(""===e||e)return e=o.escregexp(e),e=e.replace(/\\\*/g,"[\\s\\S]*"),e=e.replace(/\\\?/g,"[\\s\\S]"),e=e.replace(/\[\\s\\S\]\*\[\\s\\S\]\*/g,"\\*"),e=e.replace(/\[\\s\\S\]\*\[\\s\\S\]/g,"\\?"),e="^"+e+"$",new RegExp(e);var r=u.keys(c);return 1==r.length?c[r[0]]:u.clone(c)},o.escregexp=function(e){return e?(""+e).replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"):""},o.toString=function(){return""+u.keys(c)};var f=null==e||u.isNaN(e)?[]:u.isArray(e)?e:[e],c={};u.each(f,function(e){var r=o.re(e);c[e]=r})}function r(r){var n=new e(r);return n}var n=this,t=n.gex,i="undefined"!=typeof require,u=n._;if("undefined"==typeof u){if(!i)throw new Error("gex requires underscore, see http://underscorejs.org");u=require("lodash")}r.Gex=e,"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=r),exports.gex=r):n.gex=r}).call(this); | ||
//# sourceMappingURL=gex-min.map |
81
gex.js
@@ -1,5 +0,5 @@ | ||
/* Copyright (c) 2011-2013 Richard Rodger, MIT License, https://github.com/rjrodger/patrun */ | ||
/* Copyright (c) 2011-2015 Richard Rodger, MIT License */ | ||
/* jshint node:true, asi:true, eqnull:true */ | ||
(function() { | ||
;(function() { | ||
"use strict"; | ||
@@ -16,3 +16,3 @@ | ||
if( has_require ) { | ||
_ = require('underscore') | ||
_ = require('lodash') | ||
} | ||
@@ -27,5 +27,3 @@ else throw new Error('gex requires underscore, see http://underscorejs.org'); | ||
function dodgy(obj) { | ||
return ( _.isNull(obj) | ||
|| _.isNaN(obj) | ||
|| _.isUndefined(obj) ) | ||
return ( _.isNull(obj) || _.isNaN(obj) || _.isUndefined(obj) ); | ||
} | ||
@@ -35,8 +33,6 @@ | ||
var gexstr = ''+gexexp | ||
if( _.isNull(gexexp) | ||
|| _.isNaN(gexexp) | ||
|| _.isUndefined(gexexp) ) { | ||
if( _.isNull(gexexp) || _.isNaN(gexexp) || _.isUndefined(gexexp) ) { | ||
gexstr = '' | ||
} | ||
return gexstr | ||
return gexstr; | ||
} | ||
@@ -48,8 +44,7 @@ | ||
var gexstrs = _.keys(gexmap) | ||
//console.log(gexstrs) | ||
for(var i = 0; i < gexstrs.length && !hasmatch; i++ ) { | ||
hasmatch = !!gexmap[gexstrs[i]].exec(str) | ||
//console.log(hasmatch+' '+gexstrs[i]+' '+str) | ||
} | ||
return hasmatch | ||
return hasmatch; | ||
} | ||
@@ -65,19 +60,16 @@ | ||
self.on = function(obj) { | ||
if( _.isString(obj) | ||
|| _.isNumber(obj) | ||
|| _.isBoolean(obj) | ||
|| _.isDate(obj) | ||
|| _.isRegExp(obj) | ||
if( _.isString(obj) || | ||
_.isNumber(obj) || | ||
_.isBoolean(obj) || | ||
_.isDate(obj) || | ||
_.isRegExp(obj) | ||
) | ||
{ | ||
//return (!!re.exec(''+obj)) ? obj : null | ||
return match(obj) ? obj : null | ||
return match(obj) ? obj : null; | ||
} | ||
else if( _.isArray(obj) | ||
|| _.isArguments(obj) | ||
else if( _.isArray(obj) || _.isArguments(obj) | ||
) { | ||
var out = [] | ||
for( var i = 0; i < obj.length; i++ ) { | ||
//if( !dodgy(obj[i]) && !!re.exec(''+obj[i]) ) { | ||
if( !dodgy(obj[i]) && match(obj[i]) ) { | ||
@@ -87,24 +79,23 @@ out.push(obj[i]) | ||
} | ||
return out | ||
return out; | ||
} | ||
else if( dodgy(obj) ) { | ||
return null | ||
return null; | ||
} | ||
else if( _.isObject(obj) ) { | ||
var out = {} | ||
var outobj = {} | ||
for( var p in obj ) { | ||
if( obj.hasOwnProperty(p) ) { | ||
//if( !!re.exec(p) ) { | ||
if( match(p) ) { | ||
out[p] = obj[p] | ||
outobj[p] = obj[p] | ||
} | ||
} | ||
} | ||
return out | ||
return outobj; | ||
} | ||
else { | ||
return null | ||
return null; | ||
} | ||
@@ -117,3 +108,3 @@ } | ||
gexstr = gexstr.replace(/\?/g,'*?') | ||
return gexstr | ||
return gexstr; | ||
} | ||
@@ -123,4 +114,4 @@ | ||
self.re = function(gs) { | ||
if( '' == gs || gs ) { | ||
var gs = self.escregexp(gs) | ||
if( '' === gs || gs ) { | ||
gs = self.escregexp(gs) | ||
@@ -130,4 +121,2 @@ // use [\s\S] instead of . to match newlines | ||
gs = gs.replace(/\\\?/g,'[\\s\\S]') | ||
//gs = gs.replace(/\\\*/g,'.*') | ||
//gs = gs.replace(/\\\?/g,'.') | ||
@@ -140,7 +129,7 @@ // escapes ** and *? | ||
return new RegExp(gs) | ||
return new RegExp(gs); | ||
} | ||
else { | ||
var gexstrs = _.keys(gexmap) | ||
return 1 == gexstrs.length ? gexmap[gexstrs[0]] : _.clone(gexmap) | ||
return 1 == gexstrs.length ? gexmap[gexstrs[0]] : _.clone(gexmap); | ||
} | ||
@@ -150,13 +139,12 @@ } | ||
self.escregexp = function(restr) { | ||
return restr ? (''+restr).replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") : '' | ||
return restr ? (''+restr).replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") : ''; | ||
} | ||
self.toString = function() { | ||
return ''+_.keys(gexmap) | ||
return ''+_.keys(gexmap); | ||
} | ||
var gexstrs = (null==gexspec||_.isNaN(gexspec)) ? | ||
[] : _.isArray(gexspec) ? gexspec : [gexspec] | ||
var gexstrs = (null==gexspec||_.isNaN(gexspec)) ? [] : _.isArray(gexspec) ? gexspec : [gexspec] | ||
//console.log(gexstrs) | ||
var gexmap = {} | ||
@@ -168,4 +156,2 @@ | ||
}) | ||
//console.dir(gexmap) | ||
} | ||
@@ -175,4 +161,4 @@ | ||
function gex(gexspec) { | ||
var gex = new Gex(gexspec) | ||
return gex | ||
var gexobj = new Gex(gexspec) | ||
return gexobj; | ||
} | ||
@@ -182,3 +168,2 @@ gex.Gex = Gex | ||
if( typeof exports !== 'undefined' ) { | ||
@@ -185,0 +170,0 @@ if( typeof module !== 'undefined' && module.exports ) { |
@@ -12,3 +12,3 @@ { | ||
], | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/rjrodger/gex", | ||
@@ -21,3 +21,3 @@ "author": "Richard Rodger (http://richardrodger.com/)", | ||
"dependencies": { | ||
"underscore": "~1.6.0" | ||
"lodash": "~2.4.1" | ||
}, | ||
@@ -37,11 +37,5 @@ "main": "gex.js", | ||
"scripts": { | ||
"test": "./node_modules/.bin/jasmine-node ./test", | ||
"browser": "./node_modules/.bin/phantomjs test/run-jasmine.js test/jasmine.html", | ||
"build": "./node_modules/.bin/uglifyjs gex.js -c \"evaluate=false\" --comments \"/ Copyright .*/\" -m --source-map gex-min.map -o gex-min.js" | ||
}, | ||
"devDependencies": { | ||
"jasmine-node": "~1.14.3", | ||
"phantomjs": "~1.9.7-5", | ||
"uglify-js": "~2.4.13" | ||
"test": "./test.sh", | ||
"build": "./build.sh" | ||
} | ||
} |
@@ -7,9 +7,11 @@ # gex | ||
[![Gitter chat](https://badges.gitter.im/rjrodger/gex.png)](https://gitter.im/rjrodger/gex) | ||
Current Version: 0.1.4 | ||
Current Version: 0.2.0 | ||
Tested on: Node.js 0.10.26, Chrome 34, Firefox 28, Safari 5.1, Opera 12.16 | ||
Tested on: Node.js 0.10.35, Chrome 40, Firefox 34, Safari 7, Opera 26 | ||
[![Build Status](https://travis-ci.org/rjrodger/gex.png?branch=master)](https://travis-ci.org/rjrodger/gex) | ||
[Annotated Source](http://rjrodger.github.io/gex/doc/gex.html) | ||
@@ -86,12 +88,1 @@ | ||
## Testing | ||
The unit tests use [mocha](https://github.com/visionmedia/mocha) | ||
npm install mocha | ||
Run with: | ||
mocha test/gex.test.js | ||
Sorry, the diff of this file is not supported yet
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
0
12766
137
87
+ Addedlodash@~2.4.1
+ Addedlodash@2.4.2(transitive)
- Removedunderscore@~1.6.0
- Removedunderscore@1.6.0(transitive)