Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@curi/core

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@curi/core - npm Package Compare versions

Comparing version 1.0.0-beta.19 to 1.0.0-beta.20

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## 1.0.0-beta.20
* Added a `body` function to response modifiers, removed the `route.body` property. This change allows the user to just reference the resolved value instead of keeping a store.
* Change response modifiers property name to `set` and renamed response modifier functions: `setData` to `data`, `setStatus` to `status`, and `fail` to `error`
* Group route load functions under the `match` property. The old `preload` function is now `match.initial` (since it is run the initial time that route matches) and `load` is now a mix between `match.every` (since it is run every time that route matches) and `match.finish`.
## 1.0.0-beta.19

@@ -2,0 +8,0 @@

131

dist/curi.common.js

@@ -122,3 +122,3 @@ 'use strict';

}
function createResponse(location, routes, addons) {
function createResponse(location, routes) {
var matches = [];

@@ -146,27 +146,40 @@ var partials = [];

status: route != null ? 200 : 404,
body: undefined,
data: undefined
};
return loadRoute(route, props, addons).then(function (props) {
return freezeResponse(route, props);
});
return loadRoute(route, props);
}
/*
* This will call any load/preload functions for the matching route
* This will call any initial/every match functions for the matching route
*/
function loadRoute(route, props, addons) {
function loadRoute(route, props) {
if (!route) {
return Promise.resolve(props);
return Promise.resolve({
route: route,
props: props
});
}
var match = route.public.match;
return Promise.all([
route.public.preload ? route.public.preload() : null,
route.public.load
? route.public.load(routeProperties(route, props), responseModifiers(props), addons)
: null
]).then(function () { return props; }, function (err) {
match.initial ? match.initial() : undefined,
match.every ? match.every(routeProperties(route, props)) : undefined
]).then(function (_a) {
var initial = _a[0], every = _a[1];
return {
route: route,
props: props,
error: null,
resolved: { initial: initial, every: every }
};
}, function (err) {
// when there is an uncaught error, set it on the response
props.error = err;
return props;
return {
route: route,
props: props,
error: err,
resolved: null
};
});
}
function responseModifiers(props) {
function responseSetters(props) {
return {

@@ -178,10 +191,13 @@ redirect: function (to, code) {

},
fail: function (err) {
error: function (err) {
props.error = err;
},
setStatus: function (code) {
status: function (code) {
props.status = code;
},
setData: function (data) {
data: function (data) {
props.data = data;
},
body: function (body) {
props.body = body;
}

@@ -199,3 +215,2 @@ };

return {
body: undefined,
title: ''

@@ -206,4 +221,17 @@ };

var response = Object.assign({}, props, { key: props.location.key }, route ? route.responseProps(props) : missProps());
return Promise.resolve(response);
return response;
}
function finishResponse(pending, addons) {
var error = pending.error, resolved = pending.resolved, route = pending.route, props = pending.props;
if (route && route.public.match.finish) {
route.public.match.finish({
error: error,
resolved: resolved,
route: routeProperties(route, props),
set: responseSetters(props),
addons: addons
});
}
return freezeResponse(route, props);
}

@@ -230,3 +258,3 @@ function once(fn) {

var createRoute = function (options) {
var name = options.name, path = options.path, _a = options.pathOptions, pathOptions = _a === void 0 ? {} : _a, body = options.body, _b = options.children, descriptorChildren = _b === void 0 ? [] : _b, preload = options.preload, load = options.load, title = options.title, extra = options.extra, paramParsers = options.params;
var name = options.name, path = options.path, _a = options.pathOptions, pathOptions = _a === void 0 ? {} : _a, _b = options.children, descriptorChildren = _b === void 0 ? [] : _b, _c = options.match, match = _c === void 0 ? {} : _c, title = options.title, extra = options.extra, paramParsers = options.params;
// end defaults to true, so end has to be hardcoded for it to be false

@@ -247,6 +275,8 @@ var mustBeExact = pathOptions.end == null || pathOptions.end;

path: path,
body: body,
keys: keys.map(function (key) { return key.name; }),
preload: preload && once(preload),
load: load,
match: {
initial: match.initial && once(match.initial),
every: match.every,
finish: match.finish
},
extra: extra

@@ -264,3 +294,2 @@ },

name: name,
body: this.public.body && this.public.body(),
title: generateTitle(title, props)

@@ -300,16 +329,2 @@ };

}
function getResponse(location) {
if (cache) {
var cachedResponse = cache.get(location);
if (cachedResponse != null) {
return Promise.resolve(cachedResponse);
}
}
return createResponse(location, routes, registeredAddons).then(function (response) {
if (cache) {
cache.set(response);
}
return response;
});
}
var responseHandlers = [];

@@ -363,22 +378,34 @@ var oneTimers = [];

var activeResponse;
function navigationHandler(pending) {
function navigationHandler(pendingNav) {
if (activeResponse) {
activeResponse.cancel(pending.action);
activeResponse.cancel(pendingNav.action);
activeResponse.cancelled = true;
}
activeResponse = pending;
getResponse(pending.location).then(function (response) {
if (pending.cancelled) {
activeResponse = pendingNav;
if (cache) {
var cachedResponse = cache.get(pendingNav.location);
if (cachedResponse != null) {
cacheAndEmit(cachedResponse, pendingNav.action);
}
}
createResponse(pendingNav.location, routes).then(function (pendingResponse) {
if (pendingNav.cancelled) {
return;
}
pending.finish();
activeResponse = undefined;
emit(response, pending.action);
previous = [response, pending.action];
if (response.redirectTo) {
history.replace(response.redirectTo);
}
return response;
pendingNav.finish();
var response = finishResponse(pendingResponse, registeredAddons);
cacheAndEmit(response, pendingNav.action);
});
}
function cacheAndEmit(response, action) {
activeResponse = undefined;
if (cache) {
cache.set(response);
}
emit(response, action);
previous = [response, action];
if (response.redirectTo) {
history.replace(response.redirectTo);
}
}
// now that everything is defined, actually do the setup

@@ -385,0 +412,0 @@ setupRoutesAndAddons(routeArray);

@@ -118,3 +118,3 @@ import PathToRegexp from 'path-to-regexp';

}
function createResponse(location, routes, addons) {
function createResponse(location, routes) {
var matches = [];

@@ -142,27 +142,40 @@ var partials = [];

status: route != null ? 200 : 404,
body: undefined,
data: undefined
};
return loadRoute(route, props, addons).then(function (props) {
return freezeResponse(route, props);
});
return loadRoute(route, props);
}
/*
* This will call any load/preload functions for the matching route
* This will call any initial/every match functions for the matching route
*/
function loadRoute(route, props, addons) {
function loadRoute(route, props) {
if (!route) {
return Promise.resolve(props);
return Promise.resolve({
route: route,
props: props
});
}
var match = route.public.match;
return Promise.all([
route.public.preload ? route.public.preload() : null,
route.public.load
? route.public.load(routeProperties(route, props), responseModifiers(props), addons)
: null
]).then(function () { return props; }, function (err) {
match.initial ? match.initial() : undefined,
match.every ? match.every(routeProperties(route, props)) : undefined
]).then(function (_a) {
var initial = _a[0], every = _a[1];
return {
route: route,
props: props,
error: null,
resolved: { initial: initial, every: every }
};
}, function (err) {
// when there is an uncaught error, set it on the response
props.error = err;
return props;
return {
route: route,
props: props,
error: err,
resolved: null
};
});
}
function responseModifiers(props) {
function responseSetters(props) {
return {

@@ -174,10 +187,13 @@ redirect: function (to, code) {

},
fail: function (err) {
error: function (err) {
props.error = err;
},
setStatus: function (code) {
status: function (code) {
props.status = code;
},
setData: function (data) {
data: function (data) {
props.data = data;
},
body: function (body) {
props.body = body;
}

@@ -195,3 +211,2 @@ };

return {
body: undefined,
title: ''

@@ -202,4 +217,17 @@ };

var response = Object.assign({}, props, { key: props.location.key }, route ? route.responseProps(props) : missProps());
return Promise.resolve(response);
return response;
}
function finishResponse(pending, addons) {
var error = pending.error, resolved = pending.resolved, route = pending.route, props = pending.props;
if (route && route.public.match.finish) {
route.public.match.finish({
error: error,
resolved: resolved,
route: routeProperties(route, props),
set: responseSetters(props),
addons: addons
});
}
return freezeResponse(route, props);
}

@@ -226,3 +254,3 @@ function once(fn) {

var createRoute = function (options) {
var name = options.name, path = options.path, _a = options.pathOptions, pathOptions = _a === void 0 ? {} : _a, body = options.body, _b = options.children, descriptorChildren = _b === void 0 ? [] : _b, preload = options.preload, load = options.load, title = options.title, extra = options.extra, paramParsers = options.params;
var name = options.name, path = options.path, _a = options.pathOptions, pathOptions = _a === void 0 ? {} : _a, _b = options.children, descriptorChildren = _b === void 0 ? [] : _b, _c = options.match, match = _c === void 0 ? {} : _c, title = options.title, extra = options.extra, paramParsers = options.params;
// end defaults to true, so end has to be hardcoded for it to be false

@@ -243,6 +271,8 @@ var mustBeExact = pathOptions.end == null || pathOptions.end;

path: path,
body: body,
keys: keys.map(function (key) { return key.name; }),
preload: preload && once(preload),
load: load,
match: {
initial: match.initial && once(match.initial),
every: match.every,
finish: match.finish
},
extra: extra

@@ -260,3 +290,2 @@ },

name: name,
body: this.public.body && this.public.body(),
title: generateTitle(title, props)

@@ -296,16 +325,2 @@ };

}
function getResponse(location) {
if (cache) {
var cachedResponse = cache.get(location);
if (cachedResponse != null) {
return Promise.resolve(cachedResponse);
}
}
return createResponse(location, routes, registeredAddons).then(function (response) {
if (cache) {
cache.set(response);
}
return response;
});
}
var responseHandlers = [];

@@ -359,22 +374,34 @@ var oneTimers = [];

var activeResponse;
function navigationHandler(pending) {
function navigationHandler(pendingNav) {
if (activeResponse) {
activeResponse.cancel(pending.action);
activeResponse.cancel(pendingNav.action);
activeResponse.cancelled = true;
}
activeResponse = pending;
getResponse(pending.location).then(function (response) {
if (pending.cancelled) {
activeResponse = pendingNav;
if (cache) {
var cachedResponse = cache.get(pendingNav.location);
if (cachedResponse != null) {
cacheAndEmit(cachedResponse, pendingNav.action);
}
}
createResponse(pendingNav.location, routes).then(function (pendingResponse) {
if (pendingNav.cancelled) {
return;
}
pending.finish();
activeResponse = undefined;
emit(response, pending.action);
previous = [response, pending.action];
if (response.redirectTo) {
history.replace(response.redirectTo);
}
return response;
pendingNav.finish();
var response = finishResponse(pendingResponse, registeredAddons);
cacheAndEmit(response, pendingNav.action);
});
}
function cacheAndEmit(response, action) {
activeResponse = undefined;
if (cache) {
cache.set(response);
}
emit(response, action);
previous = [response, action];
if (response.redirectTo) {
history.replace(response.redirectTo);
}
}
// now that everything is defined, actually do the setup

@@ -381,0 +408,0 @@ setupRoutesAndAddons(routeArray);

@@ -496,3 +496,3 @@ var Curi = (function () {

}
function createResponse(location, routes, addons) {
function createResponse(location, routes) {
var matches = [];

@@ -520,27 +520,40 @@ var partials = [];

status: route != null ? 200 : 404,
body: undefined,
data: undefined
};
return loadRoute(route, props, addons).then(function (props) {
return freezeResponse(route, props);
});
return loadRoute(route, props);
}
/*
* This will call any load/preload functions for the matching route
* This will call any initial/every match functions for the matching route
*/
function loadRoute(route, props, addons) {
function loadRoute(route, props) {
if (!route) {
return Promise.resolve(props);
return Promise.resolve({
route: route,
props: props
});
}
var match = route.public.match;
return Promise.all([
route.public.preload ? route.public.preload() : null,
route.public.load
? route.public.load(routeProperties(route, props), responseModifiers(props), addons)
: null
]).then(function () { return props; }, function (err) {
match.initial ? match.initial() : undefined,
match.every ? match.every(routeProperties(route, props)) : undefined
]).then(function (_a) {
var initial = _a[0], every = _a[1];
return {
route: route,
props: props,
error: null,
resolved: { initial: initial, every: every }
};
}, function (err) {
// when there is an uncaught error, set it on the response
props.error = err;
return props;
return {
route: route,
props: props,
error: err,
resolved: null
};
});
}
function responseModifiers(props) {
function responseSetters(props) {
return {

@@ -552,10 +565,13 @@ redirect: function (to, code) {

},
fail: function (err) {
error: function (err) {
props.error = err;
},
setStatus: function (code) {
status: function (code) {
props.status = code;
},
setData: function (data) {
data: function (data) {
props.data = data;
},
body: function (body) {
props.body = body;
}

@@ -573,3 +589,2 @@ };

return {
body: undefined,
title: ''

@@ -580,4 +595,17 @@ };

var response = Object.assign({}, props, { key: props.location.key }, route ? route.responseProps(props) : missProps());
return Promise.resolve(response);
return response;
}
function finishResponse(pending, addons) {
var error = pending.error, resolved = pending.resolved, route = pending.route, props = pending.props;
if (route && route.public.match.finish) {
route.public.match.finish({
error: error,
resolved: resolved,
route: routeProperties(route, props),
set: responseSetters(props),
addons: addons
});
}
return freezeResponse(route, props);
}

@@ -604,3 +632,3 @@ function once(fn) {

var createRoute = function (options) {
var name = options.name, path = options.path, _a = options.pathOptions, pathOptions = _a === void 0 ? {} : _a, body = options.body, _b = options.children, descriptorChildren = _b === void 0 ? [] : _b, preload = options.preload, load = options.load, title = options.title, extra = options.extra, paramParsers = options.params;
var name = options.name, path = options.path, _a = options.pathOptions, pathOptions = _a === void 0 ? {} : _a, _b = options.children, descriptorChildren = _b === void 0 ? [] : _b, _c = options.match, match = _c === void 0 ? {} : _c, title = options.title, extra = options.extra, paramParsers = options.params;
// end defaults to true, so end has to be hardcoded for it to be false

@@ -621,6 +649,8 @@ var mustBeExact = pathOptions.end == null || pathOptions.end;

path: path,
body: body,
keys: keys.map(function (key) { return key.name; }),
preload: preload && once(preload),
load: load,
match: {
initial: match.initial && once(match.initial),
every: match.every,
finish: match.finish
},
extra: extra

@@ -638,3 +668,2 @@ },

name: name,
body: this.public.body && this.public.body(),
title: generateTitle(title, props)

@@ -674,16 +703,2 @@ };

}
function getResponse(location) {
if (cache) {
var cachedResponse = cache.get(location);
if (cachedResponse != null) {
return Promise.resolve(cachedResponse);
}
}
return createResponse(location, routes, registeredAddons).then(function (response) {
if (cache) {
cache.set(response);
}
return response;
});
}
var responseHandlers = [];

@@ -737,22 +752,34 @@ var oneTimers = [];

var activeResponse;
function navigationHandler(pending) {
function navigationHandler(pendingNav) {
if (activeResponse) {
activeResponse.cancel(pending.action);
activeResponse.cancel(pendingNav.action);
activeResponse.cancelled = true;
}
activeResponse = pending;
getResponse(pending.location).then(function (response) {
if (pending.cancelled) {
activeResponse = pendingNav;
if (cache) {
var cachedResponse = cache.get(pendingNav.location);
if (cachedResponse != null) {
cacheAndEmit(cachedResponse, pendingNav.action);
}
}
createResponse(pendingNav.location, routes).then(function (pendingResponse) {
if (pendingNav.cancelled) {
return;
}
pending.finish();
activeResponse = undefined;
emit(response, pending.action);
previous = [response, pending.action];
if (response.redirectTo) {
history.replace(response.redirectTo);
}
return response;
pendingNav.finish();
var response = finishResponse(pendingResponse, registeredAddons);
cacheAndEmit(response, pendingNav.action);
});
}
function cacheAndEmit(response, action) {
activeResponse = undefined;
if (cache) {
cache.set(response);
}
emit(response, action);
previous = [response, action];
if (response.redirectTo) {
history.replace(response.redirectTo);
}
}
// now that everything is defined, actually do the setup

@@ -759,0 +786,0 @@ setupRoutesAndAddons(routeArray);

@@ -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,o=[],i=0,u=0,c="",l=n&&n.delimiter||k,p=n&&n.delimiters||$,f=!1;null!==(r=j.exec(e));){var s=r[0],h=r[1],d=r.index;if(c+=e.slice(u,d),u=d+s.length,h)c+=h[1],f=!0;else{var m="",v=e[u],g=r[2],y=r[3],b=r[4],x=r[5];if(!f&&c.length){var E=c.length-1;p.indexOf(c[E])>-1&&(m=c[E],c=c.slice(0,E))}c&&(o.push(c),c="",f=!1);var w=""!==m&&void 0!==v&&v!==m,T="+"===x||"*"===x,A="?"===x||"*"===x,P=m||l,O=y||b;o.push({name:g||i++,prefix:m,delimiter:P,optional:A,repeat:T,partial:w,pattern:O?a(O):"[^"+t(P)+"]+?"})}}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,l=r?r[u.name]:void 0;if(Array.isArray(l)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but got array');if(0===l.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var p=0;p<l.length;p++){if(c=o(l[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 l&&"number"!=typeof l&&"boolean"!=typeof l){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(l)),!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 l(n(e,t),r,t)}function l(e,n,r){for(var a=(r=r||{}).strict,i=!1!==r.end,u=t(r.delimiter||k),c=r.delimiters||$,l=[].concat(r.endsWith||[]).map(t).concat("$").join("|"),p="",f=!1,s=0;s<e.length;s++){var h=e[s];if("string"==typeof h)p+=t(h),f=s===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+="$"===l?"$":"(?="+l+")"):(a||(p+="(?:"+u+"(?="+l+"))?"),f||(p+="(?="+u+"|"+l+")")),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 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 o;return r&&n[r]&&(o=n[r]),n[t]=o?C(o,a):a,t},get:function(t,a){if(null!=n[t]){var o=r[t]?r[t]:r[t]=w.compile(n[t]);return O(o(a,e))}console.error("Could not generate pathname for "+t+" because it is not registered.")},reset:function(){n={},r={}}}}function s(e,n,r,t){var a=R(n),o=e.match,i=o.re,u=o.keys,c=o.mustBeExact,l=e.children,p=i.exec(a);if(!p)return!1;var f=p[0],h=p.slice(1),d={};u.forEach(function(e,n){d[e.name]=h[n]});var m=null!=t?C(t,f):O(f);if(r.push({route:e,params:d}),!l||!l.length)return!0;var v=a.slice(f.length),g=!!v.length,y=l.some(function(e){return s(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,r){var t,a=[],o=[],i={};if(n.some(function(n){return s(n,e.pathname,a)}),a.length){var u=a.pop();a.forEach(function(e){o.push(e.route.public.name),Object.assign(i,h(e.params,e.route.paramParsers))}),t=u.route,Object.assign(i,h(u.params,t.paramParsers))}return m(t,{location:e,params:i,partials:o,status:null!=t?200:404,data:void 0},r).then(function(e){return b(t,e)})}function m(e,n,r){return e?Promise.all([e.public.preload?e.public.preload():null,e.public.load?e.public.load(g(e,n),v(n),r):null]).then(function(){return n},function(e){return n.error=e,n}):Promise.resolve(n)}function v(e){return{redirect:function(n,r){void 0===r&&(r=301),e.status=r,e.redirectTo=n},fail:function(n){e.error=n},setStatus:function(n){e.status=n},setData:function(n){e.data=n}}}function g(e,n){return{params:n.params,location:n.location,name:e.public.name}}function y(){return{body:void 0,title:""}}function b(e,n){var r=Object.assign({},n,{key:n.location.key},e?e.responseProps(n):y());return Promise.resolve(r)}function x(e){var n=null,r=!1;return function(){return r?n:(n=e(),r=!0,n)}}function E(e,n){return e?"function"==typeof e?e(n.params,n.data):e:""}var w=p,T=n,A=r,P=l,k="/",$="./",j=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");w.parse=T,w.compile=function(e,t){return r(n(e,t))},w.tokensToFunction=A,w.tokensToRegExp=P;var O=function(e){return"/"===e.charAt(0)?e:"/"+e},R=function(e){return"/"===e.charAt(0)?e.slice(1):e},B=function(e){return"/"===e.charAt(e.length-1)?e:e+"/"},C=function(e,n){return B(e)+n},S=function(e){var n=e.name,r=e.path,t=e.pathOptions,a=void 0===t?{}:t,o=e.body,i=e.children,u=void 0===i?[]:i,c=e.preload,l=e.load,p=e.title,f=e.extra,s=e.params,h=null==a.end||a.end,d=[];u.length&&(a.end=!1,d=u.map(S));var m=[],v=w(r,m,a);return{public:{name:n,path:r,body:o,keys:m.map(function(e){return e.name}),preload:c&&x(c),load:l,extra:f},match:{re:v,keys:m,mustBeExact:h},children:d,paramParsers:s,responseProps:function(e){return{name:n,body:this.public.body&&this.public.body(),title:E(p,e)}}}};return function(n,r,t){function a(n){b=n.map(S);for(var r in x)delete x[r];E.forEach(function(n){n.reset(),x[n.name]=n.get,e(b,n)})}function o(e){if(h){var n=h.get(e);if(null!=n)return Promise.resolve(n)}return d(e,b,x).then(function(e){return h&&h.set(e),e})}function i(e,n){for(v.forEach(function(r){r(e,n)}),w.forEach(function(r){null!=r&&r(e,n)});T.length;)T.pop()(e,n);g.forEach(function(r){r(e,n)})}void 0===t&&(t={});var u=t,c=u.addons,l=void 0===c?[]:c,p=u.sideEffects,s=void 0===p?[]:p,h=u.cache,m=u.pathnameOptions,v=[],g=[];s.forEach(function(e){e.after?g.push(e.fn):v.push(e.fn)});var y,b=[],x={},E=l.concat(f(m)),w=[],T=[],A=[];return a(r),n.respondWith(function(e){y&&(y.cancel(e.action),y.cancelled=!0),y=e,o(e.location).then(function(r){if(!e.cancelled)return e.finish(),y=void 0,i(r,e.action),A=[r,e.action],r.redirectTo&&n.replace(r.redirectTo),r})}),{addons:x,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){A.length&&e.apply(null,A);var t=w.push(e);return function(){w[t-1]=null}}A.length?e.apply(null,A):T.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,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}}}();
//# sourceMappingURL=curi.min.js.map
{
"name": "@curi/core",
"version": "1.0.0-beta.19",
"version": "1.0.0-beta.20",
"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, Params, LoadRoute, LoadModifiers, LoadFn, PreloadFn } from './interface';
export { AddonRegister, AddonGet, Addon, Addons, ResponseHandler, RemoveResponseHandler, SideEffect, Cache, RawParams, Params, RouteProps, ResponseSetters, FinishProps, EveryMatchFn, InitialMatchFn, FinishMatchFn } from './interface';
export { Route, RouteDescriptor, Title, ParamParser, ParamParsers } from './route';

@@ -3,0 +3,0 @@ export { Response } from './response';

@@ -16,2 +16,3 @@ import { HickoryLocation, Action } from '@hickory/root';

export declare type ResponseHandler = (response: Response, action?: Action) => void;
export declare type RemoveResponseHandler = () => void;
export interface SideEffect {

@@ -21,3 +22,2 @@ fn: ResponseHandler;

}
export declare type RemoveResponseHandler = () => void;
export interface Cache {

@@ -33,3 +33,3 @@ set: (response: Response) => void;

};
export interface LoadRoute {
export interface RouteProps {
params: object;

@@ -39,9 +39,18 @@ location: object;

}
export interface LoadModifiers {
fail: (err: any) => void;
export interface ResponseSetters {
error: (err: any) => void;
redirect: (to: any, status?: number) => void;
setData: (data: any) => void;
setStatus: (status: number) => void;
data: (data: any) => void;
status: (status: number) => void;
body: (body: any) => void;
}
export declare type LoadFn = (route?: LoadRoute, modifiers?: LoadModifiers, addons?: Addons) => Promise<any>;
export declare type PreloadFn = () => Promise<any>;
export interface FinishProps {
error: any;
resolved: any;
route: RouteProps;
set: ResponseSetters;
addons: Addons;
}
export declare type EveryMatchFn = (route?: RouteProps) => Promise<any>;
export declare type InitialMatchFn = () => Promise<any>;
export declare type FinishMatchFn = (props: FinishProps) => void;

@@ -9,2 +9,3 @@ import { HickoryLocation, ToArgument } from '@hickory/root';

status: number;
body: any;
data: any;

@@ -14,2 +15,12 @@ error?: any;

}
export interface ResolvedObject {
initial: any;
every: any;
}
export interface PendingResponse {
error?: any;
resolved?: ResolvedObject;
route: InternalRoute;
props: ResponseProps;
}
export interface Response {

@@ -28,3 +39,3 @@ key: string;

}
declare function createResponse(location: HickoryLocation, routes: Array<InternalRoute>, addons: Addons): Promise<Response>;
export default createResponse;
export declare function createResponse(location: HickoryLocation, routes: Array<InternalRoute>): Promise<PendingResponse>;
export declare function finishResponse(pending: PendingResponse, addons: Addons): Response;
import { RegExpOptions, Key } from 'path-to-regexp';
import { LoadFn, PreloadFn } from './interface';
import { EveryMatchFn, InitialMatchFn, FinishMatchFn } from './interface';
import { ResponseProps } from './response';

@@ -10,6 +10,10 @@ export declare type Title = string | ((params?: object, data?: any) => string);

export interface RouteProps {
body: any;
title: string;
name?: string;
}
export interface MatchFns {
initial?: InitialMatchFn;
every?: EveryMatchFn;
finish?: FinishMatchFn;
}
export interface RouteDescriptor {

@@ -20,6 +24,4 @@ name: string;

params?: ParamParsers;
body?: () => any;
children?: Array<RouteDescriptor>;
preload?: PreloadFn;
load?: LoadFn;
match?: MatchFns;
title?: Title;

@@ -33,6 +35,4 @@ extra?: {

path: string;
body: () => any;
keys: Array<string | number>;
preload: PreloadFn;
load: LoadFn;
match: MatchFns;
extra: {

@@ -39,0 +39,0 @@ [key: string]: any;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc