preact-router
Advanced tools
Comparing version 1.2.4 to 1.3.0
@@ -77,3 +77,16 @@ (function (global, factory) { | ||
if (route[i] && route[i].charAt(0) === ':') { | ||
matches[route[i].substring(1)] = decodeURIComponent(url[i] || ''); | ||
var param = route[i].replace(/(^\:|[+*?]+$)/g, ''), | ||
flags = (route[i].match(/[+*?]+$/) || EMPTY$1)[0] || '', | ||
plus = ~flags.indexOf('+'), | ||
star = ~flags.indexOf('*'), | ||
val = url[i] || ''; | ||
if (!val && !star && (flags.indexOf('?') < 0 || plus)) { | ||
ret = false; | ||
break; | ||
} | ||
matches[param] = decodeURIComponent(val); | ||
if (plus || star) { | ||
matches[param] = url.slice(i).map(decodeURIComponent).join('/'); | ||
break; | ||
} | ||
} else { | ||
@@ -80,0 +93,0 @@ if (route[i] !== url[i]) { |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("preact")):"function"==typeof define&&define.amd?define(["preact"],e):t.preactRouter=e(t.preact)}(this,function(t){"use strict";function e(t,e){var n=arguments.length<=2||void 0===arguments[2]?l:arguments[2],o=/(?:\?([^#]*))?(#.*)?$/,i=t.match(o),u={},a=void 0;if(i&&i[1])for(var c=i[1].split("&"),p=0;p<c.length;p++){var s=c[p].split("=");u[decodeURIComponent(s[0])]=decodeURIComponent(s.slice(1).join("="))}t=r(t.replace(o,"")),e=r(e||"");for(var f=Math.max(t.length,e.length),p=0;f>p;p++)if(e[p]&&":"===e[p].charAt(0))u[e[p].substring(1)]=decodeURIComponent(t[p]||"");else if(e[p]!==t[p]){a=!1;break}return n["default"]!==!0&&a===!1?!1:u}function n(t,e){var n=t.attributes||l,r=e.attributes||l;if(n["default"])return 1;if(r["default"])return-1;var i=o(n.path)-o(r.path);return i||n.path.length-r.path.length}function r(t){return i(t).split("/")}function o(t){return(i(t).match(/\/+/g)||"").length}function i(t){return t.replace(/(^\/+|\/+$)/g,"")}function u(t){var e=arguments.length<=1||void 0===arguments[1]?!1:arguments[1];"string"!=typeof t&&t.url&&(e=t.replace,t=t.url),history&&(e===!0?history.replaceState(null,null,t):history.pushState(null,null,t)),a(t)}function a(t){f.forEach(function(e){return e.routeTo(t)})}function c(){var t="undefined"!=typeof location?location:h;return""+(t.pathname||"")+(t.search||"")}function p(t){return u(this.getAttribute("href")),t.stopImmediatePropagation&&t.stopImmediatePropagation(),t.stopPropagation(),t.preventDefault(),!1}var s={};s.inherits=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},s.objectWithoutProperties=function(t,e){var n={};for(var r in t)e.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n},s._extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},s.a=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")};var l={},f=[],h={};"function"==typeof addEventListener&&addEventListener("popstate",function(){return a(c())});var d=function(e){var n=e.children,r=s.objectWithoutProperties(e,["children"]);return t.h("a",s._extends({},r,{onClick:p}),n)},m=function(t){function r(){s.a(this,r),t.apply(this,arguments)}return s.inherits(r,t),r.prototype.getInitialState=function(){return{url:c()}},r.prototype.routeTo=function(t){this.setState({url:t})},r.prototype.componentWillMount=function(){f.push(this)},r.prototype.componentWillUnmount=function(){f.splice(f.indexOf(this),1)},r.prototype.render=function(t,r){var o=t.children,i=t.onChange,u=r.url,a=o.slice().sort(n).filter(function(t){var n=t.attributes,r=n.path,o=e(u,r,n);if(o){n.url=u,n.matches=o;for(var i in o)o.hasOwnProperty(i)&&(n[i]=o[i]);return!0}}),c=this.previousUrl;return u!==c&&(this.previousUrl=u,"function"==typeof i&&i({router:this,url:u,previous:c,active:a,current:a[0]})),a[0]||null},r}(t.Component),v=function(e){var n=e.component,r=e.url,o=e.matches;return t.h(n,{url:r,matches:o})};return m.route=u,m.Router=m,m.Route=v,m.Link=d,m}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("preact")):"function"==typeof define&&define.amd?define(["preact"],e):t.preactRouter=e(t.preact)}(this,function(t){"use strict";function e(t,e){var n=arguments.length<=2||void 0===arguments[2]?l:arguments[2],o=/(?:\?([^#]*))?(#.*)?$/,i=t.match(o),u={},a=void 0;if(i&&i[1])for(var c=i[1].split("&"),p=0;p<c.length;p++){var f=c[p].split("=");u[decodeURIComponent(f[0])]=decodeURIComponent(f.slice(1).join("="))}t=r(t.replace(o,"")),e=r(e||"");for(var s=Math.max(t.length,e.length),p=0;s>p;p++)if(e[p]&&":"===e[p].charAt(0)){var h=e[p].replace(/(^\:|[+*?]+$)/g,""),d=(e[p].match(/[+*?]+$/)||l)[0]||"",v=~d.indexOf("+"),y=~d.indexOf("*"),m=t[p]||"";if(!m&&!y&&(d.indexOf("?")<0||v)){a=!1;break}if(u[h]=decodeURIComponent(m),v||y){u[h]=t.slice(p).map(decodeURIComponent).join("/");break}}else if(e[p]!==t[p]){a=!1;break}return n["default"]!==!0&&a===!1?!1:u}function n(t,e){var n=t.attributes||l,r=e.attributes||l;if(n["default"])return 1;if(r["default"])return-1;var i=o(n.path)-o(r.path);return i||n.path.length-r.path.length}function r(t){return i(t).split("/")}function o(t){return(i(t).match(/\/+/g)||"").length}function i(t){return t.replace(/(^\/+|\/+$)/g,"")}function u(t){var e=arguments.length<=1||void 0===arguments[1]?!1:arguments[1];"string"!=typeof t&&t.url&&(e=t.replace,t=t.url),history&&(e===!0?history.replaceState(null,null,t):history.pushState(null,null,t)),a(t)}function a(t){s.forEach(function(e){return e.routeTo(t)})}function c(){var t="undefined"!=typeof location?location:h;return""+(t.pathname||"")+(t.search||"")}function p(t){return u(this.getAttribute("href")),t.stopImmediatePropagation&&t.stopImmediatePropagation(),t.stopPropagation(),t.preventDefault(),!1}var f={};f.inherits=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},f.objectWithoutProperties=function(t,e){var n={};for(var r in t)e.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n},f._extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},f.a=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")};var l={},s=[],h={};"function"==typeof addEventListener&&addEventListener("popstate",function(){return a(c())});var d=function(e){var n=e.children,r=f.objectWithoutProperties(e,["children"]);return t.h("a",f._extends({},r,{onClick:p}),n)},v=function(t){function r(){f.a(this,r),t.apply(this,arguments)}return f.inherits(r,t),r.prototype.getInitialState=function(){return{url:c()}},r.prototype.routeTo=function(t){this.setState({url:t})},r.prototype.componentWillMount=function(){s.push(this)},r.prototype.componentWillUnmount=function(){s.splice(s.indexOf(this),1)},r.prototype.render=function(t,r){var o=t.children,i=t.onChange,u=r.url,a=o.slice().sort(n).filter(function(t){var n=t.attributes,r=n.path,o=e(u,r,n);if(o){n.url=u,n.matches=o;for(var i in o)o.hasOwnProperty(i)&&(n[i]=o[i]);return!0}}),c=this.previousUrl;return u!==c&&(this.previousUrl=u,"function"==typeof i&&i({router:this,url:u,previous:c,active:a,current:a[0]})),a[0]||null},r}(t.Component),y=function(e){var n=e.component,r=e.url,o=e.matches;return t.h(n,{url:r,matches:o})};return v.route=u,v.Router=v,v.Route=y,v.Link=d,v}); | ||
//# sourceMappingURL=preact-router.min.js.map |
{ | ||
"name": "preact-router", | ||
"amdName": "preactRouter", | ||
"version": "1.2.4", | ||
"version": "1.3.0", | ||
"description": "Connect your components up to that address bar.", | ||
@@ -40,3 +40,3 @@ "main": "dist/preact-router.js", | ||
"chai": "^3.5.0", | ||
"eslint": "^2.0.0", | ||
"eslint": "^2.2.0", | ||
"gzip-size-cli": "^1.0.0", | ||
@@ -46,3 +46,3 @@ "mkdirp": "^0.5.1", | ||
"npm-run-all": "^1.5.1", | ||
"preact": "^3.4.0", | ||
"preact": "^4.1.1", | ||
"pretty-bytes-cli": "^1.0.0", | ||
@@ -49,0 +49,0 @@ "rimraf": "^2.5.1", |
@@ -21,3 +21,16 @@ | ||
if (route[i] && route[i].charAt(0)===':') { | ||
matches[route[i].substring(1)] = decodeURIComponent(url[i] || ''); | ||
let param = route[i].replace(/(^\:|[+*?]+$)/g, ''), | ||
flags = (route[i].match(/[+*?]+$/) || EMPTY)[0] || '', | ||
plus = ~flags.indexOf('+'), | ||
star = ~flags.indexOf('*'), | ||
val = url[i] || ''; | ||
if (!val && !star && (flags.indexOf('?')<0 || plus)) { | ||
ret = false; | ||
break; | ||
} | ||
matches[param] = decodeURIComponent(val); | ||
if (plus || star) { | ||
matches[param] = url.slice(i).map(decodeURIComponent).join('/'); | ||
break; | ||
} | ||
} | ||
@@ -24,0 +37,0 @@ else { |
@@ -67,2 +67,41 @@ import { exec, pathRankSort, segmentize, rank, strip } from '../src/util'; | ||
}); | ||
describe('exec', () => { | ||
it('should match explicit equality', () => { | ||
expect(exec('/','/')).to.eql({}); | ||
expect(exec('/a','/a')).to.eql({}); | ||
expect(exec('/a','/b')).to.eql(false); | ||
expect(exec('/a/b','/a/b')).to.eql({}); | ||
expect(exec('/a/b','/a/a')).to.eql(false); | ||
expect(exec('/a/b','/b/b')).to.eql(false); | ||
}); | ||
it('should match param segments', () => { | ||
expect(exec('/', '/:foo')).to.eql(false); | ||
expect(exec('/bar', '/:foo')).to.eql({ foo:'bar' }); | ||
}); | ||
it('should match optional param segments', () => { | ||
expect(exec('/', '/:foo?')).to.eql({ foo:'' }); | ||
expect(exec('/bar', '/:foo?')).to.eql({ foo:'bar' }); | ||
expect(exec('/', '/:foo?/:bar?')).to.eql({ foo:'', bar:'' }); | ||
expect(exec('/bar', '/:foo?/:bar?')).to.eql({ foo:'bar', bar:'' }); | ||
expect(exec('/bar', '/:foo?/bar')).to.eql(false); | ||
expect(exec('/foo/bar', '/:foo?/bar')).to.eql({ foo:'foo' }); | ||
}); | ||
it('should match splat param segments', () => { | ||
expect(exec('/', '/:foo*')).to.eql({ foo:'' }); | ||
expect(exec('/a', '/:foo*')).to.eql({ foo:'a' }); | ||
expect(exec('/a/b', '/:foo*')).to.eql({ foo:'a/b' }); | ||
expect(exec('/a/b/c', '/:foo*')).to.eql({ foo:'a/b/c' }); | ||
}); | ||
it('should match required splat param segments', () => { | ||
expect(exec('/', '/:foo+')).to.eql(false); | ||
expect(exec('/a', '/:foo+')).to.eql({ foo:'a' }); | ||
expect(exec('/a/b', '/:foo+')).to.eql({ foo:'a/b' }); | ||
expect(exec('/a/b/c', '/:foo+')).to.eql({ foo:'a/b/c' }); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
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
584
40092