From b69c72edcb76f1ea73c916425d8dfbeb6c62b6ed Mon Sep 17 00:00:00 2001 From: Javier Marquez Date: Tue, 18 Dec 2018 16:56:46 +0100 Subject: [PATCH] Bumps to v0.7 --- changelog.md | 4 +- dist/urlhub.js | 732 ++++++++++++++++++++++----------------------- dist/urlhub.min.js | 2 +- package.json | 4 +- urlhub.js | 2 +- 5 files changed, 369 insertions(+), 375 deletions(-) diff --git a/changelog.md b/changelog.md index b24c0a1..7929946 100644 --- a/changelog.md +++ b/changelog.md @@ -1,8 +1,6 @@ -# v0.7.1 +# v0.7.0 * Adds the nodeStrategy for running the router in the server. * Updates the urlhub to be run in a node environment. - -# v0.7.0 * Updates testing dependencies. # v0.6.0 diff --git a/dist/urlhub.js b/dist/urlhub.js index d9edcc2..be42532 100644 --- a/dist/urlhub.js +++ b/dist/urlhub.js @@ -54,333 +54,329 @@ return /******/ (function(modules) { // webpackBootstrap /* 0 */ /***/ (function(module, exports, __webpack_require__) { - module.exports = { - urlhub: __webpack_require__(1), - pushStrategy: __webpack_require__(7), - hashStrategy: __webpack_require__(8) - }; + module.exports = { + urlhub: __webpack_require__(1), + pushStrategy: __webpack_require__(7), + hashStrategy: __webpack_require__(8) + }; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { - /* WEBPACK VAR INJECTION */(function(global) {var parser = __webpack_require__(2); - var qs = __webpack_require__(4); - - /* - routes = { - path: '/hola', - cb: fn, - children: [] - } - */ - - // parseUrl function needed for testing - var parseUrl; - if( typeof global === 'undefined' || !global.parseUrl ){ - parseUrl = function( url ){ - var a = document.createElement('a'); - a.href = url; - return a; - }; - } - else { - parseUrl = global.parseUrl; - } - - // The lib - var urlhub = { - create: function( options ){ - return new Urlhub( options ); - }, - joinUrls: joinUrls // just for testing never used, see helpers at bottom - } - - - // The class - var Urlhub = function( options ){ - if( !options || !options.strategy ){ - throw new Error('Router needs an strategy to listen to url changes.'); - } - - var s = options.strategy; - - var ops = {}; - Object.keys( options ).forEach( function( key ){ - if( key === 'strategy' ) return; - ops[key] = options[key]; - }); - - s.init && s.init( ops ); - this.strategy = s; - - // Callbacks before the route change - this.obc = []; - - // Callbacks to be called on route change - this.cbs = []; - } - - var prototype = { - setRoutes: function( routes ){ - this.routes = this.parseRoutes( routes ); - }, - // Route translation methods - parseRoutes: function( routes, parent ){ - if( !routes ) console.warn( 'No routes provided to parseRoutes' ); - - if( !routes.length ){ - routes = [routes]; - } - - var parsedRoutes = [], - me = this - ; - - routes.forEach( function(r){ - var path = joinUrls(parent, r.path); - - var params = [], - parsed = { - regex: parser( path, params ), - id: path, - cb: r.cb - } - ; - - parsed.params = params.map( function(p){ return p.name } ); - - if( r.children && r.children.length ){ - parsed.childRegex = parser( path, [], {end: false} ); - parsed.children = me.parseRoutes( r.children, path ); - } - - parsedRoutes.push( parsed ); - }); - - return parsedRoutes; - }, - - match: function( location, candidates, isChild ){ - var i = 0, - url = sanitizeUrl( location ), - path, found, match, c - ; - - if( !candidates ){ - candidates = this.routes; - } - - var parsed = parseUrl( url ); - path = parsed.pathname; - - // Normalize pathname - if( path[0] !== '/' ){ - path = '/' + path; - } - - while( i < candidates.length && !found ){ - c = candidates[i]; - if( c.childRegex ){ - //console.log( 'failed', c.regex, path ); - found = c.childRegex.exec( path ); - if( found ){ - match = this.match( url, c.children, true ); - if( match.matches.length ){ - match.matches = [c.cb].concat( match.matches ); - match.matchIds = [c.id].concat( match.matchIds ); - return match; // The recursive call will give all the info - } - else { - found = false; - } - } - } - - found = c.regex.exec( path ); - if( found ){ - found = { - id: c.id, cb: c.cb, params: found.slice(1) - }; - } - - if( !found ){ - i++; - } - } - - var matches = []; - var matchIds = []; - - if( found ){ - matches.push( found.cb ) - matchIds.push( found.id ) - } - else if( !isChild ){ - console.error('There is no route match for ' + location); - } - - match = { - matches: matches, - matchIds: matchIds, - pathname: path, - search: parsed.search, - query: qs.parse( parsed.search ), - hash: parsed.hash, - route: found && found.id || false, - params: {} - }; - - if( found ){ - c.params.forEach( function( p, i ){ - match.params[ p ] = found.params[i]; - }); - } - - return match; - }, - - // Routing methods - start: function(){ - var me = this; - this.strategy.onChange( function(){ - var change = me.checkChange(); - if( !change.next ) return; - - if( change.current !== change.next ){ - me.strategy.replace( change.next ); - } - else { - me.location = change.nextLocation; - me.cbs.forEach( function( cb ){ - cb( change.nextLocation ); - }); - } - }); - - this.strategy.start(); - this.location = this.match( this.strategy.getLocation() ); - return this.location; - }, - stop: function(){ - this.strategy.onChange( function(){} ); - }, - refresh: function(){ - var change = this.checkChange(); - change.next && change.current !== change.next && this.strategy.replace( change.next ); - }, - checkChange: function(){ - var current = this.strategy.getLocation(), - nextLocation = this.runOnBeforeChange( this.match(current) ), - next = nextLocation && (nextLocation.pathname + nextLocation.search + nextLocation.hash) - ; - - return {current:current, next:next, nextLocation:nextLocation}; - }, - runOnBeforeChange: function( match ){ - var me = this; - - this.obc.forEach( function(cb){ - if( match ){ - match = cb( match ); - if( typeof match === 'string' ){ - match = me.match( match ); - } - } - }); - - return match; - }, - onBeforeChange: function( cb ){ - this.obc.push( cb ); - }, - onChange: function( cb ){ - this.cbs.push( cb ); - }, - push: function( location ){ - this.updateLocation('push', location); - }, - replace: function( location ){ - this.updateLocation('replace', location); - }, - back: function(){ - window.history.back(); - }, - updateLocation: function( method, location ){ - var current = this.strategy.getLocation(); - var next; - - if(typeof location === 'string'){ - next = location; - } - else { - next = mergeLocations( this.match( current ), location ); - } - - var nextLocation = this.runOnBeforeChange( this.match(next) ); - if( nextLocation ){ - next = nextLocation.pathname + nextLocation.search + nextLocation.hash; - if( current !== next ){ - this.strategy[ method ]( next ); - } - } - } - } - - for( var method in prototype ) Urlhub.prototype[ method ] = prototype[method]; - - module.exports = urlhub; - - - /********* HELPERS */ - function joinUrls( one, two ){ - var first = sanitizeUrl(one), - second = sanitizeUrl(two) - ; - - if( !one ) return second; - if( !two ) return first; - - if( first === '/'){ - return second; - } - else if( second === '/' ){ - return first; - } - else { - return first + second; - } - } - - function sanitizeUrl( url ){ - if( !url ) return '/'; - var sanitized = url; - if( sanitized[ sanitized.length - 1 ] === '/' ){ - sanitized = sanitized.slice(0, sanitized.length - 1); - } - if( sanitized[0] !== '/' ){ - sanitized = '/' + sanitized; - } - return sanitized; - } - - function mergeLocations( prev, next ){ - var location = Object.assign( prev, next ), - search = location.search - ; - - if( Object.keys(location.query).length ){ - search = '?' + qs.stringify( location.query ); - } - else { - search = ''; - } - - return location.pathname + search + location.hash; - } + var parser = __webpack_require__(2); + var qs = __webpack_require__(4); + + /* + routes = { + path: '/hola', + cb: fn, + children: [] + } + */ + + // parseUrl function needed for testing + var parseUrl; + if( typeof window !== 'undefined' ){ + parseUrl = function( url ){ + var a = document.createElement('a'); + a.href = url; + return a; + }; + } + + // The lib + var urlhub = { + create: function( options ){ + return new Urlhub( options ); + }, + joinUrls: joinUrls // just for testing never used, see helpers at bottom + } + + + // The class + var Urlhub = function( options ){ + if( !options || !options.strategy ){ + throw new Error('Router needs an strategy to listen to url changes.'); + } + + var s = options.strategy; + + var ops = {}; + Object.keys( options ).forEach( function( key ){ + if( key === 'strategy' ) return; + ops[key] = options[key]; + }); + + s.init && s.init( ops ); + this.strategy = s; + + // Callbacks before the route change + this.obc = []; + + // Callbacks to be called on route change + this.cbs = []; + } + + var prototype = { + setRoutes: function( routes ){ + this.routes = this.parseRoutes( routes ); + }, + // Route translation methods + parseRoutes: function( routes, parent ){ + if( !routes ) console.warn( 'No routes provided to parseRoutes' ); + + if( !routes.length ){ + routes = [routes]; + } + + var parsedRoutes = [], + me = this + ; + + routes.forEach( function(r){ + var path = joinUrls(parent, r.path); + + var params = [], + parsed = { + regex: parser( path, params ), + id: path, + cb: r.cb + } + ; + + parsed.params = params.map( function(p){ return p.name } ); + + if( r.children && r.children.length ){ + parsed.childRegex = parser( path, [], {end: false} ); + parsed.children = me.parseRoutes( r.children, path ); + } + + parsedRoutes.push( parsed ); + }); + + return parsedRoutes; + }, + + match: function( location, candidates, isChild ){ + var i = 0, + url = sanitizeUrl( location ), + path, found, match, c + ; + + if( !candidates ){ + candidates = this.routes; + } + + var parsed = (this.strategy.parseUrl || parseUrl)( url ); + path = parsed.pathname; + + // Normalize pathname + if( path[0] !== '/' ){ + path = '/' + path; + } + + while( i < candidates.length && !found ){ + c = candidates[i]; + if( c.childRegex ){ + //console.log( 'failed', c.regex, path ); + found = c.childRegex.exec( path ); + if( found ){ + match = this.match( url, c.children, true ); + if( match.matches.length ){ + match.matches = [c.cb].concat( match.matches ); + match.matchIds = [c.id].concat( match.matchIds ); + return match; // The recursive call will give all the info + } + else { + found = false; + } + } + } + + found = c.regex.exec( path ); + if( found ){ + found = { + id: c.id, cb: c.cb, params: found.slice(1) + }; + } + + if( !found ){ + i++; + } + } + + var matches = []; + var matchIds = []; + + if( found ){ + matches.push( found.cb ) + matchIds.push( found.id ) + } + else if( !isChild ){ + console.error('There is no route match for ' + location); + } + + match = { + matches: matches, + matchIds: matchIds, + pathname: path, + search: parsed.search, + query: qs.parse( parsed.search ), + hash: parsed.hash, + route: found && found.id || false, + params: {} + }; + + if( found ){ + c.params.forEach( function( p, i ){ + match.params[ p ] = found.params[i]; + }); + } + + return match; + }, + + // Routing methods + start: function(){ + var me = this; + this.strategy.onChange( function(){ + var change = me.checkChange(); + if( !change.next ) return; + + if( change.current !== change.next ){ + me.strategy.replace( change.next ); + } + else { + me.location = change.nextLocation; + me.cbs.forEach( function( cb ){ + cb( change.nextLocation ); + }); + } + }); + + this.strategy.start(); + this.location = this.match( this.strategy.getLocation() ); + return this.location; + }, + stop: function(){ + this.strategy.onChange( function(){} ); + }, + refresh: function(){ + var change = this.checkChange(); + change.next && change.current !== change.next && this.strategy.replace( change.next ); + }, + checkChange: function(){ + var current = this.strategy.getLocation(), + nextLocation = this.runOnBeforeChange( this.match(current) ), + next = nextLocation && (nextLocation.pathname + nextLocation.search + nextLocation.hash) + ; + + return {current:current, next:next, nextLocation:nextLocation}; + }, + runOnBeforeChange: function( match ){ + var me = this; + + this.obc.forEach( function(cb){ + if( match ){ + match = cb( match ); + if( typeof match === 'string' ){ + match = me.match( match ); + } + } + }); + + return match; + }, + onBeforeChange: function( cb ){ + this.obc.push( cb ); + }, + onChange: function( cb ){ + this.cbs.push( cb ); + }, + push: function( location ){ + this.updateLocation('push', location); + }, + replace: function( location ){ + this.updateLocation('replace', location); + }, + back: function(){ + window.history.back(); + }, + updateLocation: function( method, location ){ + var current = this.strategy.getLocation(); + var next; + + if(typeof location === 'string'){ + next = location; + } + else { + next = mergeLocations( this.match( current ), location ); + } + + var nextLocation = this.runOnBeforeChange( this.match(next) ); + if( nextLocation ){ + next = nextLocation.pathname + nextLocation.search + nextLocation.hash; + if( current !== next ){ + this.strategy[ method ]( next ); + } + } + } + } + + for( var method in prototype ) Urlhub.prototype[ method ] = prototype[method]; + + module.exports = urlhub; + + + /********* HELPERS */ + function joinUrls( one, two ){ + var first = sanitizeUrl(one), + second = sanitizeUrl(two) + ; + + if( !one ) return second; + if( !two ) return first; + + if( first === '/'){ + return second; + } + else if( second === '/' ){ + return first; + } + else { + return first + second; + } + } + + function sanitizeUrl( url ){ + if( !url ) return '/'; + var sanitized = url; + if( sanitized[ sanitized.length - 1 ] === '/' ){ + sanitized = sanitized.slice(0, sanitized.length - 1); + } + if( sanitized[0] !== '/' ){ + sanitized = '/' + sanitized; + } + return sanitized; + } + + function mergeLocations( prev, next ){ + var location = Object.assign( prev, next ), + search = location.search + ; + + if( Object.keys(location.query).length ){ + search = '?' + qs.stringify( location.query ); + } + else { + search = ''; + } + + return location.pathname + search + location.hash; + } - /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) /***/ }), /* 2 */ @@ -1052,54 +1048,54 @@ return /******/ (function(modules) { // webpackBootstrap /* 7 */ /***/ (function(module, exports) { - var onChange = function () {}; - var pushStrategy = { - init: function( options ){ - this.basePath = options.basePath || ''; - if( this.basePath.slice(-1) === '/' ){ - this.basePath = this.basePath.slice(0, -1); - } - }, - - start: function(){ - var me = this; - - // Register event listener - window.onpopstate = function(){ - me.emit(); - }; - - // Emit first onChange - me.emit(); - }, - push: function( location ){ - history.pushState( {}, '', this.basePath + location ); - this.emit(); - }, - replace: function( location ){ - history.replaceState( {}, '', this.basePath + location ); - this.emit(); - }, - onChange: function( cb ){ - onChange = cb; - }, - getLocation: function(){ - var l = location.pathname + location.search + location.hash, - basePathLength = this.basePath.length - ; - - if( l.slice(0, basePathLength) === this.basePath ){ - l = l.slice( basePathLength ); - } - - return l; - }, - emit: function(){ - onChange && onChange( this.getLocation() ); - } - }; - - module.exports = pushStrategy; + var onChange = function () {}; + + var pushStrategy = { + init: function( options ){ + this.basePath = options.basePath || ''; + if( this.basePath.slice(-1) === '/' ){ + this.basePath = this.basePath.slice(0, -1); + } + }, + start: function(){ + var me = this; + + // Register event listener + window.onpopstate = function(){ + me.emit(); + }; + + // Emit first onChange + me.emit(); + }, + push: function( location ){ + history.pushState( {}, '', this.basePath + location ); + this.emit(); + }, + replace: function( location ){ + history.replaceState( {}, '', this.basePath + location ); + this.emit(); + }, + onChange: function( cb ){ + onChange = cb; + }, + getLocation: function(){ + var l = location.pathname + location.search + location.hash, + basePathLength = this.basePath.length + ; + + if( l.slice(0, basePathLength) === this.basePath ){ + l = l.slice( basePathLength ); + } + + return l; + }, + emit: function(){ + onChange && onChange( this.getLocation() ); + } + }; + + module.exports = pushStrategy; /***/ }), diff --git a/dist/urlhub.min.js b/dist/urlhub.min.js index b73fea7..a7adebe 100644 --- a/dist/urlhub.min.js +++ b/dist/urlhub.min.js @@ -1 +1 @@ -!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var r in n)("object"==typeof exports?exports:t)[r]=n[r]}}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){t.exports={urlhub:n(1),pushStrategy:n(7),hashStrategy:n(8)}},function(t,e,n){(function(e){function r(t,e){var n=o(t),r=o(e);return t?e?"/"===n?r:"/"===r?n:n+r:n:r}function o(t){if(!t)return"/";var e=t;return"/"===e[e.length-1]&&(e=e.slice(0,e.length-1)),"/"!==e[0]&&(e="/"+e),e}function a(t,e){var n=Object.assign(t,e),r=n.search;return r=Object.keys(n.query).length?"?"+s.stringify(n.query):"",n.pathname+r+n.hash}var i,c=n(2),s=n(4);i="undefined"!=typeof e&&e.parseUrl?e.parseUrl:function(t){var e=document.createElement("a");return e.href=t,e};var h={create:function(t){return new u(t)},joinUrls:r},u=function(t){if(!t||!t.strategy)throw new Error("Router needs an strategy to listen to url changes.");var e=t.strategy,n={};Object.keys(t).forEach(function(e){"strategy"!==e&&(n[e]=t[e])}),e.init&&e.init(n),this.strategy=e,this.obc=[],this.cbs=[]},f={setRoutes:function(t){this.routes=this.parseRoutes(t)},parseRoutes:function(t,e){t||console.warn("No routes provided to parseRoutes"),t.length||(t=[t]);var n=[],o=this;return t.forEach(function(t){var a=r(e,t.path),i=[],s={regex:c(a,i),id:a,cb:t.cb};s.params=i.map(function(t){return t.name}),t.children&&t.children.length&&(s.childRegex=c(a,[],{end:!1}),s.children=o.parseRoutes(t.children,a)),n.push(s)}),n},match:function(t,e,n){var r,a,c,h,u=0,f=o(t);e||(e=this.routes);var p=i(f);for(r=p.pathname,"/"!==r[0]&&(r="/"+r);un&&(n=a)}}return n+1}Object.defineProperty(e,"__esModule",{value:!0});var i=/[^\[\]]+|\[\]/g,c=/^\d+$/,s=[];e.deep=n,e.shallow=r},function(t,e){var n=function(){},r={init:function(t){this.basePath=t.basePath||"","/"===this.basePath.slice(-1)&&(this.basePath=this.basePath.slice(0,-1))},start:function(){var t=this;window.onpopstate=function(){t.emit()},t.emit()},push:function(t){history.pushState({},"",this.basePath+t),this.emit()},replace:function(t){history.replaceState({},"",this.basePath+t),this.emit()},onChange:function(t){n=t},getLocation:function(){var t=location.pathname+location.search+location.hash,e=this.basePath.length;return t.slice(0,e)===this.basePath&&(t=t.slice(e)),t},emit:function(){n&&n(this.getLocation())}};t.exports=r},function(t,e){var n=function(){},r={init:function(t){},start:function(){var t=this;location.hash||(location.hash="#/"),window.onhashchange=function(){t.emit()},t.emit()},push:function(t){window.location.hash="#"+t},replace:function(t){var e=location.protocol+"//"+location.host+location.pathname+"#"+t;location.replace(e)},onChange:function(t){n=t},getLocation:function(){return location.hash?"/"!==location.hash[1]?"/"+location.hash:location.hash.slice(1):"/"},emit:function(){n(this.getLocation())}};t.exports=r}])}); \ No newline at end of file +!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var r in n)("object"==typeof exports?exports:t)[r]=n[r]}}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){t.exports={urlhub:n(1),pushStrategy:n(7),hashStrategy:n(8)}},function(t,e,n){function r(t,e){var n=o(t),r=o(e);return t?e?"/"===n?r:"/"===r?n:n+r:n:r}function o(t){if(!t)return"/";var e=t;return"/"===e[e.length-1]&&(e=e.slice(0,e.length-1)),"/"!==e[0]&&(e="/"+e),e}function a(t,e){var n=Object.assign(t,e),r=n.search;return r=Object.keys(n.query).length?"?"+s.stringify(n.query):"",n.pathname+r+n.hash}var i,c=n(2),s=n(4);"undefined"!=typeof window&&(i=function(t){var e=document.createElement("a");return e.href=t,e});var h={create:function(t){return new u(t)},joinUrls:r},u=function(t){if(!t||!t.strategy)throw new Error("Router needs an strategy to listen to url changes.");var e=t.strategy,n={};Object.keys(t).forEach(function(e){"strategy"!==e&&(n[e]=t[e])}),e.init&&e.init(n),this.strategy=e,this.obc=[],this.cbs=[]},f={setRoutes:function(t){this.routes=this.parseRoutes(t)},parseRoutes:function(t,e){t||console.warn("No routes provided to parseRoutes"),t.length||(t=[t]);var n=[],o=this;return t.forEach(function(t){var a=r(e,t.path),i=[],s={regex:c(a,i),id:a,cb:t.cb};s.params=i.map(function(t){return t.name}),t.children&&t.children.length&&(s.childRegex=c(a,[],{end:!1}),s.children=o.parseRoutes(t.children,a)),n.push(s)}),n},match:function(t,e,n){var r,a,c,h,u=0,f=o(t);e||(e=this.routes);var p=(this.strategy.parseUrl||i)(f);for(r=p.pathname,"/"!==r[0]&&(r="/"+r);un&&(n=a)}}return n+1}Object.defineProperty(e,"__esModule",{value:!0});var i=/[^\[\]]+|\[\]/g,c=/^\d+$/,s=[];e.deep=n,e.shallow=r},function(t,e){var n=function(){},r={init:function(t){this.basePath=t.basePath||"","/"===this.basePath.slice(-1)&&(this.basePath=this.basePath.slice(0,-1))},start:function(){var t=this;window.onpopstate=function(){t.emit()},t.emit()},push:function(t){history.pushState({},"",this.basePath+t),this.emit()},replace:function(t){history.replaceState({},"",this.basePath+t),this.emit()},onChange:function(t){n=t},getLocation:function(){var t=location.pathname+location.search+location.hash,e=this.basePath.length;return t.slice(0,e)===this.basePath&&(t=t.slice(e)),t},emit:function(){n&&n(this.getLocation())}};t.exports=r},function(t,e){var n=function(){},r={init:function(t){},start:function(){var t=this;location.hash||(location.hash="#/"),window.onhashchange=function(){t.emit()},t.emit()},push:function(t){window.location.hash="#"+t},replace:function(t){var e=location.protocol+"//"+location.host+location.pathname+"#"+t;location.replace(e)},onChange:function(t){n=t},getLocation:function(){return location.hash?"/"!==location.hash[1]?"/"+location.hash:location.hash.slice(1):"/"},emit:function(){n(this.getLocation())}};t.exports=r}])}); \ No newline at end of file diff --git a/package.json b/package.json index b0be9f2..bbfed64 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urlhub", - "version": "0.7.1", + "version": "0.7.0", "description": "Another router library, yet the simplest one.", "main": "urlhub.js", "scripts": { @@ -27,11 +27,11 @@ "gulp": "^3.9.1", "gulp-rename": "^1.2.2", "jasmine": "^3.3.1", - "jasmine-core": "^3.3.0", "karma": "^3.1.3", "karma-cli": "^2.0.0", "karma-jasmine": "^2.0.1", "karma-phantomjs-launcher": "^1.0.4", + "natives": "^1.1.6", "webpack-stream": "^3.2.0" } } diff --git a/urlhub.js b/urlhub.js index f929adc..00b653f 100644 --- a/urlhub.js +++ b/urlhub.js @@ -11,7 +11,7 @@ routes = { // parseUrl function needed for testing var parseUrl; -if( typeof global === 'undefined' ){ +if( typeof window !== 'undefined' ){ parseUrl = function( url ){ var a = document.createElement('a'); a.href = url;