Comparing version 0.2.2 to 0.3.0
@@ -1,3 +0,3 @@ | ||
/* Copyright (c) 2011-2015 Richard Rodger, MIT License */ | ||
(function(){"use strict";function e(e){function r(e){return s.isNull(e)||s.isNaN(e)||s.isUndefined(e)}function i(e){var r=""+e;return(s.isNull(e)||s.isNaN(e)||s.isUndefined(e))&&(r=""),r}function u(e){e=""+e;for(var r=!1,n=s.keys(a),t=0;t<n.length&&!r;t++)r=!!a[n[t]].exec(e);return r}var o=this;o.noConflict=function(){return n.gex=t,o},o.on=function(e){if(s.isString(e)||s.isNumber(e)||s.isBoolean(e)||s.isDate(e)||s.isRegExp(e))return u(e)?e:null;if(s.isArray(e)||s.isArguments(e)){for(var n=[],t=0;t<e.length;t++)!r(e[t])&&u(e[t])&&n.push(e[t]);return n}if(s.isObject(e)){var i={};for(var o in e)e.hasOwnProperty(o)&&u(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=s.keys(a);return 1==r.length?a[r[0]]:s.clone(a)},o.escregexp=function(e){return e?(""+e).replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"):""},o.toString=function(){return c?c:c="gex["+s.keys(a)+"]"},o.inspect=function(){return o.toString()};var c,f=s.isArray(e)?e:[e],a={};s.each(f,function(e){e=i(e);var r=o.re(e);a[e]=r})}function r(r){var n=new e(r);return n}var n=this,t=n.gex,i="undefined"!=typeof require,s=n._||i&&require("lodash");if(!s)throw new Error("gex requires underscore, see http://underscorejs.org");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-2018 Richard Rodger, MIT License */ | ||
(function(){"use strict";function e(e){function r(e){return s.isNull(e)||s.isNaN(e)||s.isUndefined(e)}function i(e){var r=""+e;return(s.isNull(e)||s.isNaN(e)||s.isUndefined(e))&&(r=""),r}function u(e){e=""+e;for(var r=!1,n=s.keys(a),t=0;t<n.length&&!r;t++)r=!!a[n[t]].exec(e);return r}var o=this;o.noConflict=function(){return n.gex=t,o},o.on=function(e){if(s.isString(e)||s.isNumber(e)||s.isBoolean(e)||s.isDate(e)||s.isRegExp(e))return u(e)?e:null;if(s.isArray(e)||s.isArguments(e)){for(var n=[],t=0;t<e.length;t++)!r(e[t])&&u(e[t])&&n.push(e[t]);return n}if(s.isObject(e)){var i={};for(var o in e)e.hasOwnProperty(o)&&u(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=s.keys(a);return 1==r.length?a[r[0]]:s.clone(a)},o.escregexp=function(e){return e?(""+e).replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"):""},o.toString=function(){return c||(c="gex["+s.keys(a)+"]")},o.inspect=function(){return o.toString()};var c,f=s.isArray(e)?e:[e],a={};s.each(f,function(e){e=i(e);var r=o.re(e);a[e]=r})}function r(r){return new e(r)}var n=this,t=n.gex,i="undefined"!=typeof require,s=n._||i&&require("lodash");if(!s)throw new Error("gex requires underscore, see http://underscorejs.org");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 |
140
gex.js
@@ -1,8 +0,7 @@ | ||
/* Copyright (c) 2011-2015 Richard Rodger, MIT License */ | ||
/* Copyright (c) 2011-2018 Richard Rodger, MIT License */ | ||
/* jshint node:true, asi:true, eqnull:true */ | ||
;(function() { | ||
"use strict"; | ||
var root = this | ||
'use strict' | ||
var root = this | ||
var previous_gex = root.gex | ||
@@ -12,7 +11,6 @@ | ||
var _ = root._ || has_require && require('lodash') | ||
if( !_ ) | ||
var _ = root._ || (has_require && require('lodash')) | ||
if (!_) | ||
throw new Error('gex requires underscore, see http://underscorejs.org') | ||
function Gex(gexspec) { | ||
@@ -22,58 +20,51 @@ var self = this | ||
function dodgy(obj) { | ||
return ( _.isNull(obj) || _.isNaN(obj) || _.isUndefined(obj) ); | ||
return _.isNull(obj) || _.isNaN(obj) || _.isUndefined(obj) | ||
} | ||
function clean(gexexp) { | ||
var gexstr = ''+gexexp | ||
if( _.isNull(gexexp) || _.isNaN(gexexp) || _.isUndefined(gexexp) ) { | ||
var gexstr = '' + gexexp | ||
if (_.isNull(gexexp) || _.isNaN(gexexp) || _.isUndefined(gexexp)) { | ||
gexstr = '' | ||
} | ||
return gexstr; | ||
} | ||
return gexstr | ||
} | ||
function match(str) { | ||
str = ''+str | ||
str = '' + str | ||
var hasmatch = false | ||
var gexstrs = _.keys(gexmap) | ||
for(var i = 0; i < gexstrs.length && !hasmatch; i++ ) { | ||
for (var i = 0; i < gexstrs.length && !hasmatch; i++) { | ||
hasmatch = !!gexmap[gexstrs[i]].exec(str) | ||
} | ||
return hasmatch; | ||
return hasmatch | ||
} | ||
self.noConflict = function() { | ||
root.gex = previous_gex; | ||
return self; | ||
root.gex = previous_gex | ||
return self | ||
} | ||
self.on = function(obj) { | ||
if( _.isString(obj) || | ||
_.isNumber(obj) || | ||
_.isBoolean(obj) || | ||
_.isDate(obj) || | ||
_.isRegExp(obj) | ||
) | ||
{ | ||
return match(obj) ? obj : null; | ||
} | ||
else if( _.isArray(obj) || _.isArguments(obj) | ||
) { | ||
var out = [] | ||
for( var i = 0; i < obj.length; i++ ) { | ||
if( !dodgy(obj[i]) && match(obj[i]) ) { | ||
out.push(obj[i]) | ||
} | ||
} | ||
return out; | ||
} | ||
else if( _.isObject(obj) ) { | ||
if ( | ||
_.isString(obj) || | ||
_.isNumber(obj) || | ||
_.isBoolean(obj) || | ||
_.isDate(obj) || | ||
_.isRegExp(obj) | ||
) { | ||
return match(obj) ? obj : null | ||
} else if (_.isArray(obj) || _.isArguments(obj)) { | ||
var out = [] | ||
for (var i = 0; i < obj.length; i++) { | ||
if (!dodgy(obj[i]) && match(obj[i])) { | ||
out.push(obj[i]) | ||
} | ||
} | ||
return out | ||
} else if (_.isObject(obj)) { | ||
var outobj = {} | ||
for( var p in obj ) { | ||
if( obj.hasOwnProperty(p) ) { | ||
if( match(p) ) { | ||
for (var p in obj) { | ||
if (Object.prototype.hasOwnProperty.call(obj, p)) { | ||
if (match(p)) { | ||
outobj[p] = obj[p] | ||
@@ -83,8 +74,6 @@ } | ||
} | ||
return outobj; | ||
return outobj | ||
} else { | ||
return null | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
@@ -94,27 +83,25 @@ | ||
var gexstr = clean(gexexp) | ||
gexstr = gexstr.replace(/\*/g,'**') | ||
gexstr = gexstr.replace(/\?/g,'*?') | ||
return gexstr; | ||
gexstr = gexstr.replace(/\*/g, '**') | ||
gexstr = gexstr.replace(/\?/g, '*?') | ||
return gexstr | ||
} | ||
self.re = function(gs) { | ||
if( '' === gs || gs ) { | ||
if ('' === gs || gs) { | ||
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, '[\\s\\S]*') | ||
gs = gs.replace(/\\\?/g, '[\\s\\S]') | ||
// escapes ** and *? | ||
gs = gs.replace(/\[\\s\\S\]\*\[\\s\\S\]\*/g,'\\\*') | ||
gs = gs.replace(/\[\\s\\S\]\*\[\\s\\S\]/g,'\\\?') | ||
gs = gs.replace(/\[\\s\\S\]\*\[\\s\\S\]\*/g, '\\\*') | ||
gs = gs.replace(/\[\\s\\S\]\*\[\\s\\S\]/g, '\\\?') | ||
gs = '^'+gs+'$' | ||
gs = '^' + gs + '$' | ||
return new RegExp(gs); | ||
} | ||
else { | ||
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) | ||
} | ||
@@ -124,7 +111,9 @@ } | ||
self.escregexp = function(restr) { | ||
return restr ? (''+restr).replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") : ''; | ||
return restr | ||
? ('' + restr).replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') | ||
: '' | ||
} | ||
self.toString = function() { | ||
return desc ? desc : (desc = 'gex['+_.keys(gexmap)+']' ) | ||
return desc ? desc : (desc = 'gex[' + _.keys(gexmap) + ']') | ||
} | ||
@@ -137,31 +126,26 @@ | ||
var gexstrs = _.isArray(gexspec) ? gexspec : [gexspec] | ||
var gexmap = {} | ||
var gexmap = {} | ||
var desc | ||
_.each( gexstrs, function(str) { | ||
_.each(gexstrs, function(str) { | ||
str = clean(str) | ||
var re = self.re(str) | ||
gexmap[str]=re | ||
gexmap[str] = re | ||
}) | ||
} | ||
function gex(gexspec) { | ||
var gexobj = new Gex(gexspec) | ||
return gexobj; | ||
return gexobj | ||
} | ||
gex.Gex = Gex | ||
if( typeof exports !== 'undefined' ) { | ||
if( typeof module !== 'undefined' && module.exports ) { | ||
if (typeof exports !== 'undefined') { | ||
if (typeof module !== 'undefined' && module.exports) { | ||
exports = module.exports = gex | ||
} | ||
exports.gex = gex | ||
} | ||
else { | ||
} else { | ||
root.gex = gex | ||
} | ||
}).call(this); | ||
}.call(this)) |
@@ -12,3 +12,3 @@ { | ||
], | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/rjrodger/gex", | ||
@@ -21,3 +21,3 @@ "author": "Richard Rodger (http://richardrodger.com/)", | ||
"dependencies": { | ||
"lodash": "3.10.0" | ||
"lodash": "4.17" | ||
}, | ||
@@ -37,8 +37,12 @@ "main": "gex.js", | ||
"scripts": { | ||
"test": "./test.sh", | ||
"build": "./build.sh" | ||
"test": "lab -v -P test -t 80 -I URL,URLSearchParams", | ||
"coveralls": "lab -s -P test -r lcov -I URL,URLSearchParams | coveralls", | ||
"prettier": "prettier --write --no-semi --single-quote gex.js lib/*.js test/*.js" | ||
}, | ||
"devDependencies": { | ||
"serve": "1.4.0" | ||
"serve": "6", | ||
"code": "4", | ||
"coveralls": "3", | ||
"lab": "14" | ||
} | ||
} |
# gex | ||
If you're using this library, feel free to contact me on twitter if you have any questions! :) [@rjrodger](http://twitter.com/rjrodger) | ||
[![npm version][npm-badge]][npm-url] | ||
[![Build Status][travis-badge]][travis-url] | ||
[![Coverage Status][coveralls-badge]][coveralls-url] | ||
[![Dependency Status][david-badge]][david-url] | ||
This module works on both Node.js and browsers. | ||
[![Gitter chat](https://badges.gitter.im/rjrodger/gex.png)](https://gitter.im/rjrodger/gex) | ||
Current Version: 0.2.2 | ||
Tested on: node 0.10, 0.11, 0.12, iojs, Chrome 43, Safari 7, Firefox 38 | ||
[![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) | ||
## Glob expressions for JavaScript | ||
@@ -87,1 +78,18 @@ | ||
## Support | ||
If you're using this library, feel free to contact me on twitter if you have any questions! :) [@rjrodger](http://twitter.com/rjrodger) | ||
This module works on both Node.js and browsers. | ||
[npm-badge]: https://badge.fury.io/js/gex.svg | ||
[npm-url]: https://badge.fury.io/js/gex | ||
[travis-badge]: https://api.travis-ci.org/rjrodger/gex.svg?branch=master | ||
[travis-url]: https://travis-ci.org/rjrodger/gex?branch=master | ||
[coveralls-badge]:https://coveralls.io/repos/rjrodger/gex/badge.svg?branch=master&service=github | ||
[coveralls-url]: https://coveralls.io/github/rjrodger/gex?branch=master | ||
[david-badge]: https://david-dm.org/rjrodger/gex.svg | ||
[david-url]: https://david-dm.org/rjrodger/gex | ||
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
13200
95
4
130
+ Addedlodash@4.17.21(transitive)
- Removedlodash@3.10.0(transitive)
Updatedlodash@4.17