@curi/core
Advanced tools
Comparing version 1.0.0-beta.20 to 1.0.0-beta.21
@@ -0,1 +1,5 @@ | ||
## 1.0.0-beta.21 | ||
* `match.response` instead of `match.finish`. | ||
## 1.0.0-beta.20 | ||
@@ -2,0 +6,0 @@ |
@@ -221,4 +221,4 @@ 'use strict'; | ||
var error = pending.error, resolved = pending.resolved, route = pending.route, props = pending.props; | ||
if (route && route.public.match.finish) { | ||
route.public.match.finish({ | ||
if (route && route.public.match.response) { | ||
route.public.match.response({ | ||
error: error, | ||
@@ -274,3 +274,3 @@ resolved: resolved, | ||
every: match.every, | ||
finish: match.finish | ||
response: match.response | ||
}, | ||
@@ -277,0 +277,0 @@ extra: extra |
@@ -217,4 +217,4 @@ import PathToRegexp from 'path-to-regexp'; | ||
var error = pending.error, resolved = pending.resolved, route = pending.route, props = pending.props; | ||
if (route && route.public.match.finish) { | ||
route.public.match.finish({ | ||
if (route && route.public.match.response) { | ||
route.public.match.response({ | ||
error: error, | ||
@@ -270,3 +270,3 @@ resolved: resolved, | ||
every: match.every, | ||
finish: match.finish | ||
response: match.response | ||
}, | ||
@@ -273,0 +273,0 @@ extra: extra |
@@ -595,4 +595,4 @@ var Curi = (function () { | ||
var error = pending.error, resolved = pending.resolved, route = pending.route, props = pending.props; | ||
if (route && route.public.match.finish) { | ||
route.public.match.finish({ | ||
if (route && route.public.match.response) { | ||
route.public.match.response({ | ||
error: error, | ||
@@ -648,3 +648,3 @@ resolved: resolved, | ||
every: match.every, | ||
finish: match.finish | ||
response: match.response | ||
}, | ||
@@ -651,0 +651,0 @@ extra: extra |
@@ -1,2 +0,2 @@ | ||
var Curi=function(){"use strict";function e(n,r,t){n.forEach(function(n){var a=r.register(n.public,t);e(n.children,r,a)})}function n(e,n){for(var r,i=[],o=0,u=0,c="",s=n&&n.delimiter||j,l=n&&n.delimiters||O,f=!1;null!==(r=P.exec(e));){var p=r[0],h=r[1],d=r.index;if(c+=e.slice(u,d),u=d+p.length,h)c+=h[1],f=!0;else{var m="",v=e[u],g=r[2],y=r[3],x=r[4],E=r[5];if(!f&&c.length){var b=c.length-1;l.indexOf(c[b])>-1&&(m=c[b],c=c.slice(0,b))}c&&(i.push(c),c="",f=!1);var w=""!==m&&void 0!==v&&v!==m,T="+"===E||"*"===E,A="?"===E||"*"===E,k=m||s,$=y||x;i.push({name:g||o++,prefix:m,delimiter:k,optional:A,repeat:T,partial:w,pattern:$?a($):"[^"+t(k)+"]+?"})}}return(c||u<e.length)&&i.push(c+e.substr(u)),i}function r(e){for(var n=new Array(e.length),r=0;r<e.length;r++)"object"==typeof e[r]&&(n[r]=new RegExp("^(?:"+e[r].pattern+")$"));return function(r,t){for(var a="",i=t&&t.encode||encodeURIComponent,o=0;o<e.length;o++){var u=e[o];if("string"!=typeof u){var c,s=r?r[u.name]:void 0;if(Array.isArray(s)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but got array');if(0===s.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var l=0;l<s.length;l++){if(c=i(s[l]),!n[o].test(c))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'"');a+=(0===l?u.prefix:u.delimiter)+c}}else if("string"!=typeof s&&"number"!=typeof s&&"boolean"!=typeof s){if(!u.optional)throw new TypeError('Expected "'+u.name+'" to be '+(u.repeat?"an array":"a string"));u.partial&&(a+=u.prefix)}else{if(c=i(String(s)),!n[o].test(c))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but got "'+c+'"');a+=u.prefix+c}}else a+=u}return a}}function t(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function a(e){return e.replace(/([=!:$/()])/g,"\\$1")}function i(e){return e&&e.sensitive?"":"i"}function o(e,n){if(!n)return e;var r=e.source.match(/\((?!\?)/g);if(r)for(var t=0;t<r.length;t++)n.push({name:t,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,pattern:null});return e}function u(e,n,r){for(var t=[],a=0;a<e.length;a++)t.push(l(e[a],n,r).source);return new RegExp("(?:"+t.join("|")+")",i(r))}function c(e,r,t){return s(n(e,t),r,t)}function s(e,n,r){for(var a=(r=r||{}).strict,o=!1!==r.end,u=t(r.delimiter||j),c=r.delimiters||O,s=[].concat(r.endsWith||[]).map(t).concat("$").join("|"),l="",f=!1,p=0;p<e.length;p++){var h=e[p];if("string"==typeof h)l+=t(h),f=p===e.length-1&&c.indexOf(h[h.length-1])>-1;else{var d=t(h.prefix),m=h.repeat?"(?:"+h.pattern+")(?:"+d+"(?:"+h.pattern+"))*":h.pattern;n&&n.push(h),h.optional?h.partial?l+=d+"("+m+")?":l+="(?:"+d+"("+m+"))?":l+=d+"("+m+")"}}return o?(a||(l+="(?:"+u+")?"),l+="$"===s?"$":"(?="+s+")"):(a||(l+="(?:"+u+"(?="+s+"))?"),f||(l+="(?="+u+"|"+s+")")),new RegExp("^"+l,i(r))}function l(e,n,r){return e instanceof RegExp?o(e,n):Array.isArray(e)?u(e,n,r):c(e,n,r)}function f(e){var n={},r={};return{name:"pathname",register:function(e,r){var t=e.name,a=e.path;void 0!==n[t]&&console.warn('A pathname with the name "'+t+'" already exists. Each route shouldhave a unique name. By registering a pathname with a name that already exists, you are overwriting the existing pathname. This may break your application.');var i;return r&&n[r]&&(i=n[r]),n[t]=i?W(i,a):a,t},get:function(t,a){if(null!=n[t]){var i=r[t]?r[t]:r[t]=T.compile(n[t]);return R(i(a,e))}console.error("Could not generate pathname for "+t+" because it is not registered.")},reset:function(){n={},r={}}}}function p(e,n,r,t){var a=B(n),i=e.match,o=i.re,u=i.keys,c=i.mustBeExact,s=e.children,l=o.exec(a);if(!l)return!1;var f=l[0],h=l.slice(1),d={};u.forEach(function(e,n){d[e.name]=h[n]});var m=null!=t?W(t,f):R(f);if(r.push({route:e,params:d}),!s||!s.length)return!0;var v=a.slice(f.length),g=!!v.length,y=s.some(function(e){return p(e,v,r,m)});return!(c&&g&&!y)||(r.pop(),!1)}function h(e,n){if(!n)return e;var r={};for(var t in e){var a=e[t],i=n[t];if(i)try{a=i(a)}catch(n){console.error(n),a=e[t]}r[t]=a}return r}function d(e,n){var r,t=[],a=[],i={};if(n.some(function(n){return p(n,e.pathname,t)}),t.length){var o=t.pop();t.forEach(function(e){a.push(e.route.public.name),Object.assign(i,h(e.params,e.route.paramParsers))}),r=o.route,Object.assign(i,h(o.params,r.paramParsers))}return m(r,{location:e,params:i,partials:a,status:null!=r?200:404,body:void 0,data:void 0})}function m(e,n){if(!e)return Promise.resolve({route:e,props:n});var r=e.public.match;return Promise.all([r.initial?r.initial():void 0,r.every?r.every(g(e,n)):void 0]).then(function(r){var t=r[0],a=r[1];return{route:e,props:n,error:null,resolved:{initial:t,every:a}}},function(r){return{route:e,props:n,error:r,resolved:null}})}function v(e){return{redirect:function(n,r){void 0===r&&(r=301),e.status=r,e.redirectTo=n},error:function(n){e.error=n},status:function(n){e.status=n},data:function(n){e.data=n},body:function(n){e.body=n}}}function g(e,n){return{params:n.params,location:n.location,name:e.public.name}}function y(){return{title:""}}function x(e,n){return Object.assign({},n,{key:n.location.key},e?e.responseProps(n):y())}function E(e,n){var r=e.error,t=e.resolved,a=e.route,i=e.props;return a&&a.public.match.finish&&a.public.match.finish({error:r,resolved:t,route:g(a,i),set:v(i),addons:n}),x(a,i)}function b(e){var n=null,r=!1;return function(){return r?n:(n=e(),r=!0,n)}}function w(e,n){return e?"function"==typeof e?e(n.params,n.data):e:""}var T=l,A=n,k=r,$=s,j="/",O="./",P=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");T.parse=A,T.compile=function(e,t){return r(n(e,t))},T.tokensToFunction=k,T.tokensToRegExp=$;var R=function(e){return"/"===e.charAt(0)?e:"/"+e},B=function(e){return"/"===e.charAt(0)?e.slice(1):e},C=function(e){return"/"===e.charAt(e.length-1)?e:e+"/"},W=function(e,n){return C(e)+n},q=function(e){var n=e.name,r=e.path,t=e.pathOptions,a=void 0===t?{}:t,i=e.children,o=void 0===i?[]:i,u=e.match,c=void 0===u?{}:u,s=e.title,l=e.extra,f=e.params,p=null==a.end||a.end,h=[];o.length&&(a.end=!1,h=o.map(q));var d=[],m=T(r,d,a);return{public:{name:n,path:r,keys:d.map(function(e){return e.name}),match:{initial:c.initial&&b(c.initial),every:c.every,finish:c.finish},extra:l},match:{re:m,keys:d,mustBeExact:p},children:h,paramParsers:f,responseProps:function(e){return{name:n,title:w(s,e)}}}};return function(n,r,t){function a(n){x=n.map(q);for(var r in b)delete b[r];w.forEach(function(n){n.reset(),b[n.name]=n.get,e(x,n)})}function i(e,n){for(v.forEach(function(r){r(e,n)}),T.forEach(function(r){null!=r&&r(e,n)});A.length;)A.pop()(e,n);g.forEach(function(r){r(e,n)})}function o(e,r){y=void 0,h&&h.set(e),i(e,r),k=[e,r],e.redirectTo&&n.replace(e.redirectTo)}void 0===t&&(t={});var u=t,c=u.addons,s=void 0===c?[]:c,l=u.sideEffects,p=void 0===l?[]:l,h=u.cache,m=u.pathnameOptions,v=[],g=[];p.forEach(function(e){e.after?g.push(e.fn):v.push(e.fn)});var y,x=[],b={},w=s.concat(f(m)),T=[],A=[],k=[];return a(r),n.respondWith(function(e){if(y&&(y.cancel(e.action),y.cancelled=!0),y=e,h){var n=h.get(e.location);null!=n&&o(n,e.action)}d(e.location,x).then(function(n){e.cancelled||(e.finish(),o(E(n,b),e.action))})}),{addons:b,history:n,respond:function(e,n){if("function"!=typeof e)throw new Error('The first argument passed to "respond" must be a function');var r=(n||{}).once;if(void 0===r||!r){k.length&&e.apply(null,k);var t=T.push(e);return function(){T[t-1]=null}}k.length?e.apply(null,k):A.push(e)},refresh:a}}}(); | ||
var Curi=function(){"use strict";function e(n,r,t){n.forEach(function(n){var a=r.register(n.public,t);e(n.children,r,a)})}function n(e,n){for(var r,o=[],i=0,u=0,c="",s=n&&n.delimiter||j,p=n&&n.delimiters||O,l=!1;null!==(r=P.exec(e));){var f=r[0],h=r[1],d=r.index;if(c+=e.slice(u,d),u=d+f.length,h)c+=h[1],l=!0;else{var m="",v=e[u],g=r[2],y=r[3],x=r[4],E=r[5];if(!l&&c.length){var b=c.length-1;p.indexOf(c[b])>-1&&(m=c[b],c=c.slice(0,b))}c&&(o.push(c),c="",l=!1);var w=""!==m&&void 0!==v&&v!==m,T="+"===E||"*"===E,A="?"===E||"*"===E,k=m||s,$=y||x;o.push({name:g||i++,prefix:m,delimiter:k,optional:A,repeat:T,partial:w,pattern:$?a($):"[^"+t(k)+"]+?"})}}return(c||u<e.length)&&o.push(c+e.substr(u)),o}function r(e){for(var n=new Array(e.length),r=0;r<e.length;r++)"object"==typeof e[r]&&(n[r]=new RegExp("^(?:"+e[r].pattern+")$"));return function(r,t){for(var a="",o=t&&t.encode||encodeURIComponent,i=0;i<e.length;i++){var u=e[i];if("string"!=typeof u){var c,s=r?r[u.name]:void 0;if(Array.isArray(s)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but got array');if(0===s.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var p=0;p<s.length;p++){if(c=o(s[p]),!n[i].test(c))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'"');a+=(0===p?u.prefix:u.delimiter)+c}}else if("string"!=typeof s&&"number"!=typeof s&&"boolean"!=typeof s){if(!u.optional)throw new TypeError('Expected "'+u.name+'" to be '+(u.repeat?"an array":"a string"));u.partial&&(a+=u.prefix)}else{if(c=o(String(s)),!n[i].test(c))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but got "'+c+'"');a+=u.prefix+c}}else a+=u}return a}}function t(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function a(e){return e.replace(/([=!:$/()])/g,"\\$1")}function o(e){return e&&e.sensitive?"":"i"}function i(e,n){if(!n)return e;var r=e.source.match(/\((?!\?)/g);if(r)for(var t=0;t<r.length;t++)n.push({name:t,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,pattern:null});return e}function u(e,n,r){for(var t=[],a=0;a<e.length;a++)t.push(p(e[a],n,r).source);return new RegExp("(?:"+t.join("|")+")",o(r))}function c(e,r,t){return s(n(e,t),r,t)}function s(e,n,r){for(var a=(r=r||{}).strict,i=!1!==r.end,u=t(r.delimiter||j),c=r.delimiters||O,s=[].concat(r.endsWith||[]).map(t).concat("$").join("|"),p="",l=!1,f=0;f<e.length;f++){var h=e[f];if("string"==typeof h)p+=t(h),l=f===e.length-1&&c.indexOf(h[h.length-1])>-1;else{var d=t(h.prefix),m=h.repeat?"(?:"+h.pattern+")(?:"+d+"(?:"+h.pattern+"))*":h.pattern;n&&n.push(h),h.optional?h.partial?p+=d+"("+m+")?":p+="(?:"+d+"("+m+"))?":p+=d+"("+m+")"}}return i?(a||(p+="(?:"+u+")?"),p+="$"===s?"$":"(?="+s+")"):(a||(p+="(?:"+u+"(?="+s+"))?"),l||(p+="(?="+u+"|"+s+")")),new RegExp("^"+p,o(r))}function p(e,n,r){return e instanceof RegExp?i(e,n):Array.isArray(e)?u(e,n,r):c(e,n,r)}function l(e){var n={},r={};return{name:"pathname",register:function(e,r){var t=e.name,a=e.path;void 0!==n[t]&&console.warn('A pathname with the name "'+t+'" already exists. Each route shouldhave a unique name. By registering a pathname with a name that already exists, you are overwriting the existing pathname. This may break your application.');var o;return r&&n[r]&&(o=n[r]),n[t]=o?W(o,a):a,t},get:function(t,a){if(null!=n[t]){var o=r[t]?r[t]:r[t]=T.compile(n[t]);return R(o(a,e))}console.error("Could not generate pathname for "+t+" because it is not registered.")},reset:function(){n={},r={}}}}function f(e,n,r,t){var a=B(n),o=e.match,i=o.re,u=o.keys,c=o.mustBeExact,s=e.children,p=i.exec(a);if(!p)return!1;var l=p[0],h=p.slice(1),d={};u.forEach(function(e,n){d[e.name]=h[n]});var m=null!=t?W(t,l):R(l);if(r.push({route:e,params:d}),!s||!s.length)return!0;var v=a.slice(l.length),g=!!v.length,y=s.some(function(e){return f(e,v,r,m)});return!(c&&g&&!y)||(r.pop(),!1)}function h(e,n){if(!n)return e;var r={};for(var t in e){var a=e[t],o=n[t];if(o)try{a=o(a)}catch(n){console.error(n),a=e[t]}r[t]=a}return r}function d(e,n){var r,t=[],a=[],o={};if(n.some(function(n){return f(n,e.pathname,t)}),t.length){var i=t.pop();t.forEach(function(e){a.push(e.route.public.name),Object.assign(o,h(e.params,e.route.paramParsers))}),r=i.route,Object.assign(o,h(i.params,r.paramParsers))}return m(r,{location:e,params:o,partials:a,status:null!=r?200:404,body:void 0,data:void 0})}function m(e,n){if(!e)return Promise.resolve({route:e,props:n});var r=e.public.match;return Promise.all([r.initial?r.initial():void 0,r.every?r.every(g(e,n)):void 0]).then(function(r){var t=r[0],a=r[1];return{route:e,props:n,error:null,resolved:{initial:t,every:a}}},function(r){return{route:e,props:n,error:r,resolved:null}})}function v(e){return{redirect:function(n,r){void 0===r&&(r=301),e.status=r,e.redirectTo=n},error:function(n){e.error=n},status:function(n){e.status=n},data:function(n){e.data=n},body:function(n){e.body=n}}}function g(e,n){return{params:n.params,location:n.location,name:e.public.name}}function y(){return{title:""}}function x(e,n){return Object.assign({},n,{key:n.location.key},e?e.responseProps(n):y())}function E(e,n){var r=e.error,t=e.resolved,a=e.route,o=e.props;return a&&a.public.match.response&&a.public.match.response({error:r,resolved:t,route:g(a,o),set:v(o),addons:n}),x(a,o)}function b(e){var n=null,r=!1;return function(){return r?n:(n=e(),r=!0,n)}}function w(e,n){return e?"function"==typeof e?e(n.params,n.data):e:""}var T=p,A=n,k=r,$=s,j="/",O="./",P=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");T.parse=A,T.compile=function(e,t){return r(n(e,t))},T.tokensToFunction=k,T.tokensToRegExp=$;var R=function(e){return"/"===e.charAt(0)?e:"/"+e},B=function(e){return"/"===e.charAt(0)?e.slice(1):e},C=function(e){return"/"===e.charAt(e.length-1)?e:e+"/"},W=function(e,n){return C(e)+n},q=function(e){var n=e.name,r=e.path,t=e.pathOptions,a=void 0===t?{}:t,o=e.children,i=void 0===o?[]:o,u=e.match,c=void 0===u?{}:u,s=e.title,p=e.extra,l=e.params,f=null==a.end||a.end,h=[];i.length&&(a.end=!1,h=i.map(q));var d=[],m=T(r,d,a);return{public:{name:n,path:r,keys:d.map(function(e){return e.name}),match:{initial:c.initial&&b(c.initial),every:c.every,response:c.response},extra:p},match:{re:m,keys:d,mustBeExact:f},children:h,paramParsers:l,responseProps:function(e){return{name:n,title:w(s,e)}}}};return function(n,r,t){function a(n){x=n.map(q);for(var r in b)delete b[r];w.forEach(function(n){n.reset(),b[n.name]=n.get,e(x,n)})}function o(e,n){for(v.forEach(function(r){r(e,n)}),T.forEach(function(r){null!=r&&r(e,n)});A.length;)A.pop()(e,n);g.forEach(function(r){r(e,n)})}function i(e,r){y=void 0,h&&h.set(e),o(e,r),k=[e,r],e.redirectTo&&n.replace(e.redirectTo)}void 0===t&&(t={});var u=t,c=u.addons,s=void 0===c?[]:c,p=u.sideEffects,f=void 0===p?[]:p,h=u.cache,m=u.pathnameOptions,v=[],g=[];f.forEach(function(e){e.after?g.push(e.fn):v.push(e.fn)});var y,x=[],b={},w=s.concat(l(m)),T=[],A=[],k=[];return a(r),n.respondWith(function(e){if(y&&(y.cancel(e.action),y.cancelled=!0),y=e,h){var n=h.get(e.location);null!=n&&i(n,e.action)}d(e.location,x).then(function(n){e.cancelled||(e.finish(),i(E(n,b),e.action))})}),{addons:b,history:n,respond:function(e,n){if("function"!=typeof e)throw new Error('The first argument passed to "respond" must be a function');var r=(n||{}).once;if(void 0===r||!r){k.length&&e.apply(null,k);var t=T.push(e);return function(){T[t-1]=null}}k.length?e.apply(null,k):A.push(e)},refresh:a}}}(); | ||
//# sourceMappingURL=curi.min.js.map |
{ | ||
"name": "@curi/core", | ||
"version": "1.0.0-beta.20", | ||
"version": "1.0.0-beta.21", | ||
"description": "A JavaScript router you can use with anywhere", | ||
@@ -5,0 +5,0 @@ "main": "dist/curi.common.js", |
@@ -1,2 +0,2 @@ | ||
export { AddonRegister, AddonGet, Addon, Addons, ResponseHandler, RemoveResponseHandler, SideEffect, Cache, RawParams, Params, RouteProps, ResponseSetters, FinishProps, EveryMatchFn, InitialMatchFn, FinishMatchFn } from './interface'; | ||
export { AddonRegister, AddonGet, Addon, Addons, ResponseHandler, RemoveResponseHandler, SideEffect, Cache, RawParams, Params, RouteProps, ResponseSetters, ResponseBuilder, EveryMatchFn, InitialMatchFn, ResponseMatchFn } from './interface'; | ||
export { Route, RouteDescriptor, Title, ParamParser, ParamParsers } from './route'; | ||
@@ -3,0 +3,0 @@ export { Response } from './response'; |
@@ -43,3 +43,3 @@ import { HickoryLocation, Action } from '@hickory/root'; | ||
} | ||
export interface FinishProps { | ||
export interface ResponseBuilder { | ||
error: any; | ||
@@ -53,2 +53,2 @@ resolved: any; | ||
export declare type InitialMatchFn = () => Promise<any>; | ||
export declare type FinishMatchFn = (props: FinishProps) => void; | ||
export declare type ResponseMatchFn = (props: ResponseBuilder) => void; |
import { RegExpOptions, Key } from 'path-to-regexp'; | ||
import { EveryMatchFn, InitialMatchFn, FinishMatchFn } from './interface'; | ||
import { EveryMatchFn, InitialMatchFn, ResponseMatchFn } from './interface'; | ||
import { ResponseProps } from './response'; | ||
@@ -16,3 +16,3 @@ export declare type Title = string | ((params?: object, data?: any) => string); | ||
every?: EveryMatchFn; | ||
finish?: FinishMatchFn; | ||
response?: ResponseMatchFn; | ||
} | ||
@@ -19,0 +19,0 @@ export interface RouteDescriptor { |
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
111242