Permalink
Browse files

now using jasmine, runs in browser too

  • Loading branch information...
1 parent 0d46bb6 commit 5012cca10dfcafb2b4d1a64ccbd80fb2391f752e @rjrodger committed Sep 26, 2013
Showing with 3,899 additions and 326 deletions.
  1. +5 −0 .travis.yml
  2. +5 −2 README.md
  3. +3 −0 gex-min.js
  4. +1 −0 gex-min.map
  5. +199 −0 gex.js
  6. +0 −168 lib/gex.js
  7. +29 −14 package.json
  8. +140 −0 test/gex.spec.js
  9. +0 −142 test/gex.test.js
  10. +20 −0 test/jasmine-1.3.1/MIT.LICENSE
  11. +681 −0 test/jasmine-1.3.1/jasmine-html.js
  12. +82 −0 test/jasmine-1.3.1/jasmine.css
  13. +2,600 −0 test/jasmine-1.3.1/jasmine.js
  14. +48 −0 test/jasmine.html
  15. +86 −0 test/run-jasmine.js
View
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+ - "0.11"
+ - "0.10"
+ - "0.8"
View
@@ -2,9 +2,12 @@
If you're using this library, feel free to contact me on twitter if you have any questions! :) [@rjrodger](http://twitter.com/rjrodger)
-Current Version: 0.1.1
+This module works on both Node.js and browsers.
-Tested on: node 0.8
+
+Current Version: 0.1.2
+
+Tested on: Node.js 0.10.19, Chrome 29, Firefox 23, Safari 5.1, Opera 12.11
## Glob expressions for JavaScript
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
199 gex.js
@@ -0,0 +1,199 @@
+/* Copyright (c) 2011-2013 Richard Rodger, MIT License, https://github.com/rjrodger/patrun */
+"use strict";
+
+
+(function() {
+ var root = this
+ var previousGex = root.gex
+
+ var has_require = typeof require !== 'undefined'
+
+ var _ = root._
+
+ if( typeof _ === 'undefined' ) {
+ if( has_require ) {
+ _ = require('underscore')
+ }
+ else throw new Error('gex requires underscore, see http://underscorejs.org');
+ }
+
+
+ function Gex(gexspec) {
+ var self = this
+
+ function dodgy(obj) {
+ return ( _.isNull(obj)
+ || _.isNaN(obj)
+ || _.isUndefined(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
+ }
+*/
+
+ function match(str) {
+ str = ''+str
+ var hasmatch = false
+ 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
+ }
+
+
+ _.noConflict = function() {
+ root._ = previousGex;
+ return self;
+ }
+
+
+ self.on = function(obj) {
+ if( _.isString(obj)
+ || _.isNumber(obj)
+ || _.isBoolean(obj)
+ || _.isDate(obj)
+ || _.isRegExp(obj)
+ )
+ {
+ //return (!!re.exec(''+obj)) ? obj : null
+ 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]) && !!re.exec(''+obj[i]) ) {
+ if( !dodgy(obj[i]) && match(obj[i]) ) {
+ out.push(obj[i])
+ }
+ }
+ return out
+ }
+
+ else if( dodgy(obj) ) {
+ return null
+ }
+
+ else if( _.isObject(obj) ) {
+ var out = {}
+ for( var p in obj ) {
+ if( obj.hasOwnProperty(p) ) {
+ //if( !!re.exec(p) ) {
+ if( match(p) ) {
+ out[p] = obj[p]
+ }
+ }
+ }
+ return out
+ }
+
+ else {
+ return null
+ }
+ }
+
+ 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 {
+ var gexstrs = _.keys(gexmap)
+ return 1 == gexstrs.length ? gexmap[gexstrs[0]] : _.clone(gexmap)
+ }
+ }
+
+ self.escregexp = function(restr) {
+ return restr ? (''+restr).replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") : ''
+ }
+
+ self.toString = function() {
+ return ''+_.keys(gexmap)
+ }
+
+
+ var gexstrs = (null==gexspec||_.isNaN(gexspec)) ? [] : _.isArray(gexspec) ? gexspec : [gexspec]
+ //console.log(gexstrs)
+
+ var gexmap = {}
+
+ _.each( gexstrs, function(str) {
+ var re = self.re(str)
+ gexmap[str]=re
+ })
+
+ //console.dir(gexmap)
+ }
+
+
+ function gex(gexspec) {
+ var gex = new Gex(gexspec)
+ return gex
+ }
+ gex.Gex = Gex
+
+
+
+ if( typeof exports !== 'undefined' ) {
+ if( typeof module !== 'undefined' && module.exports ) {
+ exports = module.exports = gex
+ }
+ exports.gex = gex
+ }
+ else {
+ root.gex = gex
+ }
+
+}).call(this);
View
@@ -1,168 +0,0 @@
-/* Copyright (c) 2011-2013 Richard Rodger, MIT License */
-"use strict";
-
-
-var _ = require('underscore')
-
-
-function Gex(gexspec) {
- var self = this
-
- function dodgy(obj) {
- return ( _.isNull(obj)
- || _.isNaN(obj)
- || _.isUndefined(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
- }
-
-
- function match(str) {
- str = ''+str
- var hasmatch = false
- 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
- }
-
-
- self.on = function(obj) {
- if( _.isString(obj)
- || _.isNumber(obj)
- || _.isBoolean(obj)
- || _.isDate(obj)
- || _.isRegExp(obj)
- )
- {
- //return (!!re.exec(''+obj)) ? obj : null
- 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]) && !!re.exec(''+obj[i]) ) {
- if( !dodgy(obj[i]) && match(obj[i]) ) {
- out.push(obj[i])
- }
- }
- return out
- }
-
- else if( dodgy(obj) ) {
- return null
- }
-
- else if( _.isObject(obj) ) {
- var out = {}
- for( var p in obj ) {
- if( obj.hasOwnProperty(p) ) {
- //if( !!re.exec(p) ) {
- if( match(p) ) {
- out[p] = obj[p]
- }
- }
- }
- return out
- }
-
- else {
- return null
- }
- }
-
- 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 {
- var gexstrs = _.keys(gexmap)
- return 1 == gexstrs.length ? gexmap[gexstrs[0]] : _.clone(gexmap)
- }
- }
-
- self.escregexp = function(restr) {
- return restr ? (''+restr).replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") : ''
- }
-
- self.toString = function() {
- return ''+_.keys(gexmap)
- }
-
-
- var gexstrs = (null==gexspec||_.isNaN(gexspec)) ? [] : _.isArray(gexspec) ? gexspec : [gexspec]
- //console.log(gexstrs)
-
- var gexmap = {}
-
- _.each( gexstrs, function(str) {
- var re = self.re(str)
- gexmap[str]=re
- })
-
- //console.dir(gexmap)
-}
-
-
-function gex(gexspec) {
- var gex = new Gex(gexspec)
- return gex
-}
-gex.Gex = Gex
-
-
-module.exports = gex
Oops, something went wrong.

0 comments on commit 5012cca

Please sign in to comment.