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.11 to 1.0.0-beta.12

4

CHANGELOG.md

@@ -0,1 +1,5 @@

## 1.0.0-beta.12
* Routes can have a `params` object, which is an object whose keys are params (from the `path`) and whose values are functions that will parse the parsed value. This can be used if any of the parsed values should not be strings. Any params that are not included in the `params` object will be kept as strings. Likewise, any params whose parsing function throws an error will be kept as strings.
## 1.0.0-beta.11

@@ -2,0 +6,0 @@

53

dist/curi.common.js

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

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

@@ -88,2 +88,3 @@ var expectedExact = pathOptions.end == null || pathOptions.end;

extra: extra,
paramParsers: paramParsers,
match: function (pathname, rc, parentPath) {

@@ -190,2 +191,25 @@ var testPath = stripLeadingSlash(pathname);

function parseParams(params, fns) {
if (!fns) {
return params;
}
var output = {};
// For each param, attempt to parse it. However, if that
// fails, fall back to the string value.
for (var key in params) {
var value = params[key];
var fn = fns[key];
if (fn) {
try {
value = fn(value);
}
catch (e) {
console.error(e);
value = params[key];
}
}
output[key] = value;
}
return output;
}
var ResponseCreator = /** #__PURE__ */ (function () {

@@ -224,3 +248,3 @@ function ResponseCreator(key, location) {

};
ResponseCreator.prototype.freeze = function () {
ResponseCreator.prototype.freezeMatch = function () {
var _this = this;

@@ -231,6 +255,6 @@ if (this.matches.length) {

_this.partials.push(m.route.name);
Object.assign(_this.params, m.params);
Object.assign(_this.params, parseParams(m.params, m.route.paramParsers));
});
this.route = bestMatch.route;
Object.assign(this.params, bestMatch.params);
Object.assign(this.params, parseParams(bestMatch.params, bestMatch.route.paramParsers));
}

@@ -298,11 +322,9 @@ };

}
function matchRoute(rc) {
routes.some(function (route) { return (route.match(history.location.pathname, rc)); });
routes.some(function (route) { return route.match(history.location.pathname, rc); });
// once we have matched the route, we freeze the responseCreator to
// set its route/params/partials properties
rc.freeze();
rc.freezeMatch();
return Promise.resolve(rc);
}
function loadRoute(rc) {

@@ -326,6 +348,7 @@ var route = rc.route;

route.preload ? route.preload() : null,
route.load ? route.load(rc.params, rc.location, modifiers, registeredAddons) : null
route.load
? route.load(rc.params, rc.location, modifiers, registeredAddons)
: null
]).then(function () { return rc; });
}
function finalizeResponse(rc) {

@@ -338,6 +361,8 @@ var respObject = rc.asObject();

}
function prepareResponse(location) {
// generate a random key when none is provided (old browsers, maybe unecessary?)
var key = location.key || Math.random().toString(36).slice(2, 8);
var key = location.key ||
Math.random()
.toString(36)
.slice(2, 8);
mostRecentKey = key;

@@ -355,3 +380,2 @@ if (cache) {

}
function subscribe(fn) {

@@ -371,3 +395,2 @@ if (typeof fn !== 'function') {

}
function emit(response, action) {

@@ -391,3 +414,2 @@ // don't emit old responses

}
// create a response object using the current location and

@@ -411,3 +433,2 @@ // emit it to any subscribed functions

}
// now that everything is defined, actually do the setup

@@ -414,0 +435,0 @@ setupRoutesAndAddons(routeArray);

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

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

@@ -84,2 +84,3 @@ var expectedExact = pathOptions.end == null || pathOptions.end;

extra: extra,
paramParsers: paramParsers,
match: function (pathname, rc, parentPath) {

@@ -186,2 +187,25 @@ var testPath = stripLeadingSlash(pathname);

function parseParams(params, fns) {
if (!fns) {
return params;
}
var output = {};
// For each param, attempt to parse it. However, if that
// fails, fall back to the string value.
for (var key in params) {
var value = params[key];
var fn = fns[key];
if (fn) {
try {
value = fn(value);
}
catch (e) {
console.error(e);
value = params[key];
}
}
output[key] = value;
}
return output;
}
var ResponseCreator = /** #__PURE__ */ (function () {

@@ -220,3 +244,3 @@ function ResponseCreator(key, location) {

};
ResponseCreator.prototype.freeze = function () {
ResponseCreator.prototype.freezeMatch = function () {
var _this = this;

@@ -227,6 +251,6 @@ if (this.matches.length) {

_this.partials.push(m.route.name);
Object.assign(_this.params, m.params);
Object.assign(_this.params, parseParams(m.params, m.route.paramParsers));
});
this.route = bestMatch.route;
Object.assign(this.params, bestMatch.params);
Object.assign(this.params, parseParams(bestMatch.params, bestMatch.route.paramParsers));
}

@@ -294,11 +318,9 @@ };

}
function matchRoute(rc) {
routes.some(function (route) { return (route.match(history.location.pathname, rc)); });
routes.some(function (route) { return route.match(history.location.pathname, rc); });
// once we have matched the route, we freeze the responseCreator to
// set its route/params/partials properties
rc.freeze();
rc.freezeMatch();
return Promise.resolve(rc);
}
function loadRoute(rc) {

@@ -322,6 +344,7 @@ var route = rc.route;

route.preload ? route.preload() : null,
route.load ? route.load(rc.params, rc.location, modifiers, registeredAddons) : null
route.load
? route.load(rc.params, rc.location, modifiers, registeredAddons)
: null
]).then(function () { return rc; });
}
function finalizeResponse(rc) {

@@ -334,6 +357,8 @@ var respObject = rc.asObject();

}
function prepareResponse(location) {
// generate a random key when none is provided (old browsers, maybe unecessary?)
var key = location.key || Math.random().toString(36).slice(2, 8);
var key = location.key ||
Math.random()
.toString(36)
.slice(2, 8);
mostRecentKey = key;

@@ -351,3 +376,2 @@ if (cache) {

}
function subscribe(fn) {

@@ -367,3 +391,2 @@ if (typeof fn !== 'function') {

}
function emit(response, action) {

@@ -387,3 +410,2 @@ // don't emit old responses

}
// create a response object using the current location and

@@ -407,3 +429,2 @@ // emit it to any subscribed functions

}
// now that everything is defined, actually do the setup

@@ -410,0 +431,0 @@ setupRoutesAndAddons(routeArray);

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

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

@@ -461,2 +461,3 @@ var expectedExact = pathOptions.end == null || pathOptions.end;

extra: extra,
paramParsers: paramParsers,
match: function (pathname, rc, parentPath) {

@@ -563,2 +564,25 @@ var testPath = stripLeadingSlash(pathname);

function parseParams(params, fns) {
if (!fns) {
return params;
}
var output = {};
// For each param, attempt to parse it. However, if that
// fails, fall back to the string value.
for (var key in params) {
var value = params[key];
var fn = fns[key];
if (fn) {
try {
value = fn(value);
}
catch (e) {
console.error(e);
value = params[key];
}
}
output[key] = value;
}
return output;
}
var ResponseCreator = /** #__PURE__ */ (function () {

@@ -597,3 +621,3 @@ function ResponseCreator(key, location) {

};
ResponseCreator.prototype.freeze = function () {
ResponseCreator.prototype.freezeMatch = function () {
var _this = this;

@@ -604,6 +628,6 @@ if (this.matches.length) {

_this.partials.push(m.route.name);
Object.assign(_this.params, m.params);
Object.assign(_this.params, parseParams(m.params, m.route.paramParsers));
});
this.route = bestMatch.route;
Object.assign(this.params, bestMatch.params);
Object.assign(this.params, parseParams(bestMatch.params, bestMatch.route.paramParsers));
}

@@ -671,11 +695,9 @@ };

}
function matchRoute(rc) {
routes.some(function (route) { return (route.match(history.location.pathname, rc)); });
routes.some(function (route) { return route.match(history.location.pathname, rc); });
// once we have matched the route, we freeze the responseCreator to
// set its route/params/partials properties
rc.freeze();
rc.freezeMatch();
return Promise.resolve(rc);
}
function loadRoute(rc) {

@@ -699,6 +721,7 @@ var route = rc.route;

route.preload ? route.preload() : null,
route.load ? route.load(rc.params, rc.location, modifiers, registeredAddons) : null
route.load
? route.load(rc.params, rc.location, modifiers, registeredAddons)
: null
]).then(function () { return rc; });
}
function finalizeResponse(rc) {

@@ -711,6 +734,8 @@ var respObject = rc.asObject();

}
function prepareResponse(location) {
// generate a random key when none is provided (old browsers, maybe unecessary?)
var key = location.key || Math.random().toString(36).slice(2, 8);
var key = location.key ||
Math.random()
.toString(36)
.slice(2, 8);
mostRecentKey = key;

@@ -728,3 +753,2 @@ if (cache) {

}
function subscribe(fn) {

@@ -744,3 +768,2 @@ if (typeof fn !== 'function') {

}
function emit(response, action) {

@@ -764,3 +787,2 @@ // don't emit old responses

}
// create a response object using the current location and

@@ -784,3 +806,2 @@ // emit it to any subscribed functions

}
// now that everything is defined, actually do the setup

@@ -787,0 +808,0 @@ setupRoutesAndAddons(routeArray);

@@ -1,2 +0,2 @@

var Curi=function(){"use strict";function t(t){var e=null,r=!1;return function(){return r?e:(e=t(),r=!0,e)}}function e(t,e){for(var r,o=[],a=0,u=0,s="",c=e&&e.delimiter||"/",h=e&&e.delimiters||"./",f=!1;null!==(r=O.exec(t));){var p=r[0],l=r[1],d=r.index;if(s+=t.slice(u,d),u=d+p.length,l)s+=l[1],f=!0;else{var m="",v=t[u],y=r[2],g=r[3],b=r[4],E=r[5];if(!f&&s.length){var x=s.length-1;h.indexOf(s[x])>-1&&(m=s[x],s=s.slice(0,x))}s&&(o.push(s),s="",f=!1);var w=""!==m&&void 0!==v&&v!==m,T="+"===E||"*"===E,k="?"===E||"*"===E,j=m||c,A=g||b;o.push({name:y||a++,prefix:m,delimiter:j,optional:k,repeat:T,partial:w,pattern:A?i(A):"[^"+n(j)+"]+?"})}}return(s||u<t.length)&&o.push(s+t.substr(u)),o}function r(t){for(var e=new Array(t.length),r=0;r<t.length;r++)"object"==typeof t[r]&&(e[r]=new RegExp("^(?:"+t[r].pattern+")$"));return function(r,n){for(var i="",o=n&&n.encode||encodeURIComponent,a=0;a<t.length;a++){var u=t[a];if("string"!=typeof u){var s,c=r?r[u.name]:void 0;if(Array.isArray(c)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but got array');if(0===c.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var h=0;h<c.length;h++){if(s=o(c[h]),!e[a].test(s))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'"');i+=(0===h?u.prefix:u.delimiter)+s}}else if("string"!=typeof c&&"number"!=typeof c&&"boolean"!=typeof c){if(!u.optional)throw new TypeError('Expected "'+u.name+'" to be '+(u.repeat?"an array":"a string"));u.partial&&(i+=u.prefix)}else{if(s=o(String(c)),!e[a].test(s))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but got "'+s+'"');i+=u.prefix+s}}else i+=u}return i}}function n(t){return t.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function i(t){return t.replace(/([=!:$/()])/g,"\\$1")}function o(t){return t&&t.sensitive?"":"i"}function a(t,e){if(!e)return t;var r=t.source.match(/\((?!\?)/g);if(r)for(var n=0;n<r.length;n++)e.push({name:n,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,pattern:null});return t}function u(t,e,r){for(var n=[],i=0;i<t.length;i++)n.push(h(t[i],e,r).source);return new RegExp("(?:"+n.join("|")+")",o(r))}function s(t,r,n){return c(e(t,n),r,n)}function c(t,e,r){for(var i=(r=r||{}).strict,a=!1!==r.end,u=n(r.delimiter||"/"),s=[].concat(r.endsWith||[]).map(n).concat("$").join("|"),c="",h=0;h<t.length;h++){var f=t[h];if("string"==typeof f)c+=n(f);else{var p=n(f.prefix),l="(?:"+f.pattern+")";e&&e.push(f),f.repeat&&(l+="(?:"+p+l+")*"),c+=l=f.optional?f.partial?p+"("+l+")?":"(?:"+p+"("+l+"))?":p+"("+l+")"}}return i||(c+="(?:"+u+"(?="+s+"))?"),c+=a?"$"===s?s:"(?="+s+")":"(?="+u+"|"+s+")",new RegExp("^"+c,o(r))}function h(t,e,r){return t instanceof RegExp?a(t,e):Array.isArray(t)?u(t,e,r):s(t,e,r)}function f(t,e){var r=[];return{re:w(t,r,e),keys:r}}function p(t,e){var r=l(t);return d(e,r),r}function l(t){return t.map(function(t){var e=t.children?l(t.children):[];return A(y({},t,{children:e}))})}function d(t,e){t.forEach(function(t){m(e,t)})}function m(t,e,r){t.forEach(function(t){var n=e.register(t,r);t.children&&m(t.children,e,n)})}function v(t){var e={},r={};return{name:"pathname",register:function(t,r){var n=t.name,i=t.path;void 0!==e[n]&&console.warn('A pathname with the name "'+n+'" 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&&e[r]&&(o=e[r]),e[n]=o?x(o,i):i,n},get:function(n,i){if(null!=e[n]){var o=r[n]?r[n]:r[n]=w.compile(e[n]);return g(o(i,t))}console.error("Could not generate pathname for "+n+" because it is not registered.")},reset:function(){e={},r={}}}}var y=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++){e=arguments[r];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},g=function(t){return"/"===t.charAt(0)?t:"/"+t},b=function(t){return"/"===t.charAt(0)?t.slice(1):t},E=function(t){return"/"===t.charAt(t.length-1)?t:t+"/"},x=function(t,e){return E(t)+e},w=h,T=e,k=r,j=c,O=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");w.parse=T,w.compile=function(t,n){return r(e(t,n))},w.tokensToFunction=k,w.tokensToRegExp=j;var A=function(e){var r=e||{},n=r.name,i=r.path,o=r.pathOptions,a=void 0===o?{}:o,u=r.body,s=r.children,c=r.preload,h=r.load,p=r.title,l=r.extra,d=null==a.end||a.end;s.length&&(a.end=!1);var m=f(i,a);return{name:n,path:i,body:u,getBody:function(){return this.body&&this.body()},children:s,preload:c?t(c):void 0,load:h,keys:m.keys.map(function(t){return t.name}),title:p,extra:l,match:function(t,e,r){var n=b(t),i=m.re.exec(n);if(!i)return!1;var o=i[0],a=i.slice(1),u={};m.keys.forEach(function(t,e){u[t.name]=a[e]});var c=null!=r?x(r,o):g(o);if(e.push(this,u),!s||!s.length)return!0;var h=n.slice(o.length),f=!!h.length,p=s.some(function(t){return t.match(h,e,c)});return!(d&&f&&!p)||(e.pop(),!1)}}},R=function(){function t(t,e){this.key=t,this.location=e,this.status=200,this.matches=[],this.route,this.partials=[],this.params={},this.body}return t.prototype.redirect=function(t,e){void 0===e&&(e=301),this.setStatus(e),this.redirectTo=t},t.prototype.fail=function(t){this.error=t},t.prototype.setStatus=function(t){this.status=t},t.prototype.push=function(t,e){this.matches.push({route:t,params:e})},t.prototype.pop=function(){this.matches.pop()},t.prototype.setData=function(t){this.data=t},t.prototype.freeze=function(){var t=this;if(this.matches.length){var e=this.matches.pop();this.matches.forEach(function(e){t.partials.push(e.route.name),Object.assign(t.params,e.params)}),this.route=e.route,Object.assign(this.params,e.params)}},t.prototype.generateTitle=function(){return this.route&&this.route.title?"function"==typeof this.route.title?this.route.title(this.params,this.data):this.route.title:""},t.prototype.asObject=function(){var t={key:this.key,location:this.location,status:this.status,data:this.data,title:this.generateTitle(),body:this.route&&this.route.getBody()};return null!=this.redirectTo?y({},t,{redirectTo:this.redirectTo}):y({},t,{name:this.route?this.route.name:void 0,partials:this.partials,params:this.params,error:this.error})},t}();return function(t,e,r){function n(e){var r=[];for(var n in j)delete j[n];T.forEach(function(t){t.reset(),j[t.name]=t.get,r.push(t)}),k=p(e,r),c(t.location,t.action)}function i(e){return k.some(function(r){return r.match(t.location.pathname,e)}),e.freeze(),Promise.resolve(e)}function o(t){var e=t.route;if(!e)return t.setStatus(404),Promise.resolve(t);var r=e.load?{fail:t.fail.bind(t),redirect:t.redirect.bind(t),setData:t.setData.bind(t),setStatus:t.setStatus.bind(t)}:void 0;return Promise.all([e.preload?e.preload():null,e.load?e.load(t.params,t.location,r,j):null]).then(function(){return t})}function a(t){var e=t.asObject();return y&&y.set(e),e}function u(t){var e=t.key||Math.random().toString(36).slice(2,8);if(x=e,y){var r=y.get(t);if(null!=r)return Promise.resolve(r)}return i(new R(e,t)).then(o).then(a)}function s(t,e){return t.key===x&&(b.forEach(function(r){r(t,e)}),O.forEach(function(r){null!=r&&r(t,e)}),E.forEach(function(r){r(t,e)}),!0)}function c(e,r){w=u(e).then(function(e){return s(e,r)&&(A=[e,r]),e.redirectTo&&t.replace(e.redirectTo),e},function(t){return console.error(t),null})}void 0===r&&(r={});var h=r,f=h.addons,l=void 0===f?[]:f,d=h.sideEffects,m=void 0===d?[]:d,y=h.cache,g=h.pathnameOptions,b=[],E=[];m.forEach(function(t){t.after?E.push(t.fn):b.push(t.fn)});var x,w,T=l.concat(v(g)),k=[],j={},O=[],A=[];n(e);t.subscribe(c);return{ready:function(){return w},refresh:n,subscribe:function(t){if("function"!=typeof t)throw new Error("The argument passed to subscribe must be a function");t.apply(null,A);var e=O.push(t);return function(){O[e-1]=null}},addons:j,history:t}}}();
var Curi=function(){"use strict";function t(t){var e=null,r=!1;return function(){return r?e:(e=t(),r=!0,e)}}function e(t,e){for(var r,a=[],o=0,u=0,s="",c=e&&e.delimiter||"/",h=e&&e.delimiters||"./",f=!1;null!==(r=A.exec(t));){var p=r[0],l=r[1],d=r.index;if(s+=t.slice(u,d),u=d+p.length,l)s+=l[1],f=!0;else{var m="",v=t[u],y=r[2],g=r[3],b=r[4],E=r[5];if(!f&&s.length){var x=s.length-1;h.indexOf(s[x])>-1&&(m=s[x],s=s.slice(0,x))}s&&(a.push(s),s="",f=!1);var w=""!==m&&void 0!==v&&v!==m,T="+"===E||"*"===E,k="?"===E||"*"===E,j=m||c,O=g||b;a.push({name:y||o++,prefix:m,delimiter:j,optional:k,repeat:T,partial:w,pattern:O?i(O):"[^"+n(j)+"]+?"})}}return(s||u<t.length)&&a.push(s+t.substr(u)),a}function r(t){for(var e=new Array(t.length),r=0;r<t.length;r++)"object"==typeof t[r]&&(e[r]=new RegExp("^(?:"+t[r].pattern+")$"));return function(r,n){for(var i="",a=n&&n.encode||encodeURIComponent,o=0;o<t.length;o++){var u=t[o];if("string"!=typeof u){var s,c=r?r[u.name]:void 0;if(Array.isArray(c)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but got array');if(0===c.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var h=0;h<c.length;h++){if(s=a(c[h]),!e[o].test(s))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'"');i+=(0===h?u.prefix:u.delimiter)+s}}else if("string"!=typeof c&&"number"!=typeof c&&"boolean"!=typeof c){if(!u.optional)throw new TypeError('Expected "'+u.name+'" to be '+(u.repeat?"an array":"a string"));u.partial&&(i+=u.prefix)}else{if(s=a(String(c)),!e[o].test(s))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but got "'+s+'"');i+=u.prefix+s}}else i+=u}return i}}function n(t){return t.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function i(t){return t.replace(/([=!:$/()])/g,"\\$1")}function a(t){return t&&t.sensitive?"":"i"}function o(t,e){if(!e)return t;var r=t.source.match(/\((?!\?)/g);if(r)for(var n=0;n<r.length;n++)e.push({name:n,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,pattern:null});return t}function u(t,e,r){for(var n=[],i=0;i<t.length;i++)n.push(h(t[i],e,r).source);return new RegExp("(?:"+n.join("|")+")",a(r))}function s(t,r,n){return c(e(t,n),r,n)}function c(t,e,r){for(var i=(r=r||{}).strict,o=!1!==r.end,u=n(r.delimiter||"/"),s=[].concat(r.endsWith||[]).map(n).concat("$").join("|"),c="",h=0;h<t.length;h++){var f=t[h];if("string"==typeof f)c+=n(f);else{var p=n(f.prefix),l="(?:"+f.pattern+")";e&&e.push(f),f.repeat&&(l+="(?:"+p+l+")*"),c+=l=f.optional?f.partial?p+"("+l+")?":"(?:"+p+"("+l+"))?":p+"("+l+")"}}return i||(c+="(?:"+u+"(?="+s+"))?"),c+=o?"$"===s?s:"(?="+s+")":"(?="+u+"|"+s+")",new RegExp("^"+c,a(r))}function h(t,e,r){return t instanceof RegExp?o(t,e):Array.isArray(t)?u(t,e,r):s(t,e,r)}function f(t,e){var r=[];return{re:T(t,r,e),keys:r}}function p(t,e){var r=l(t);return d(e,r),r}function l(t){return t.map(function(t){var e=t.children?l(t.children):[];return P(g({},t,{children:e}))})}function d(t,e){t.forEach(function(t){m(e,t)})}function m(t,e,r){t.forEach(function(t){var n=e.register(t,r);t.children&&m(t.children,e,n)})}function v(t){var e={},r={};return{name:"pathname",register:function(t,r){var n=t.name,i=t.path;void 0!==e[n]&&console.warn('A pathname with the name "'+n+'" 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 a;return r&&e[r]&&(a=e[r]),e[n]=a?w(a,i):i,n},get:function(n,i){if(null!=e[n]){var a=r[n]?r[n]:r[n]=T.compile(e[n]);return b(a(i,t))}console.error("Could not generate pathname for "+n+" because it is not registered.")},reset:function(){e={},r={}}}}function y(t,e){if(!e)return t;var r={};for(var n in t){var i=t[n],a=e[n];if(a)try{i=a(i)}catch(e){console.error(e),i=t[n]}r[n]=i}return r}var g=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++){e=arguments[r];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},b=function(t){return"/"===t.charAt(0)?t:"/"+t},E=function(t){return"/"===t.charAt(0)?t.slice(1):t},x=function(t){return"/"===t.charAt(t.length-1)?t:t+"/"},w=function(t,e){return x(t)+e},T=h,k=e,j=r,O=c,A=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");T.parse=k,T.compile=function(t,n){return r(e(t,n))},T.tokensToFunction=j,T.tokensToRegExp=O;var P=function(e){var r=e||{},n=r.name,i=r.path,a=r.pathOptions,o=void 0===a?{}:a,u=r.body,s=r.children,c=r.preload,h=r.load,p=r.title,l=r.extra,d=r.params,m=null==o.end||o.end;s.length&&(o.end=!1);var v=f(i,o);return{name:n,path:i,body:u,getBody:function(){return this.body&&this.body()},children:s,preload:c?t(c):void 0,load:h,keys:v.keys.map(function(t){return t.name}),title:p,extra:l,paramParsers:d,match:function(t,e,r){var n=E(t),i=v.re.exec(n);if(!i)return!1;var a=i[0],o=i.slice(1),u={};v.keys.forEach(function(t,e){u[t.name]=o[e]});var c=null!=r?w(r,a):b(a);if(e.push(this,u),!s||!s.length)return!0;var h=n.slice(a.length),f=!!h.length,p=s.some(function(t){return t.match(h,e,c)});return!(m&&f&&!p)||(e.pop(),!1)}}},R=function(){function t(t,e){this.key=t,this.location=e,this.status=200,this.matches=[],this.route,this.partials=[],this.params={},this.body}return t.prototype.redirect=function(t,e){void 0===e&&(e=301),this.setStatus(e),this.redirectTo=t},t.prototype.fail=function(t){this.error=t},t.prototype.setStatus=function(t){this.status=t},t.prototype.push=function(t,e){this.matches.push({route:t,params:e})},t.prototype.pop=function(){this.matches.pop()},t.prototype.setData=function(t){this.data=t},t.prototype.freezeMatch=function(){var t=this;if(this.matches.length){var e=this.matches.pop();this.matches.forEach(function(e){t.partials.push(e.route.name),Object.assign(t.params,y(e.params,e.route.paramParsers))}),this.route=e.route,Object.assign(this.params,y(e.params,e.route.paramParsers))}},t.prototype.generateTitle=function(){return this.route&&this.route.title?"function"==typeof this.route.title?this.route.title(this.params,this.data):this.route.title:""},t.prototype.asObject=function(){var t={key:this.key,location:this.location,status:this.status,data:this.data,title:this.generateTitle(),body:this.route&&this.route.getBody()};return null!=this.redirectTo?g({},t,{redirectTo:this.redirectTo}):g({},t,{name:this.route?this.route.name:void 0,partials:this.partials,params:this.params,error:this.error})},t}();return function(t,e,r){function n(e){var r=[];for(var n in j)delete j[n];T.forEach(function(t){t.reset(),j[t.name]=t.get,r.push(t)}),k=p(e,r),c(t.location,t.action)}function i(e){return k.some(function(r){return r.match(t.location.pathname,e)}),e.freezeMatch(),Promise.resolve(e)}function a(t){var e=t.route;if(!e)return t.setStatus(404),Promise.resolve(t);var r=e.load?{fail:t.fail.bind(t),redirect:t.redirect.bind(t),setData:t.setData.bind(t),setStatus:t.setStatus.bind(t)}:void 0;return Promise.all([e.preload?e.preload():null,e.load?e.load(t.params,t.location,r,j):null]).then(function(){return t})}function o(t){var e=t.asObject();return y&&y.set(e),e}function u(t){var e=t.key||Math.random().toString(36).slice(2,8);if(x=e,y){var r=y.get(t);if(null!=r)return Promise.resolve(r)}return i(new R(e,t)).then(a).then(o)}function s(t,e){return t.key===x&&(b.forEach(function(r){r(t,e)}),O.forEach(function(r){null!=r&&r(t,e)}),E.forEach(function(r){r(t,e)}),!0)}function c(e,r){w=u(e).then(function(e){return s(e,r)&&(A=[e,r]),e.redirectTo&&t.replace(e.redirectTo),e},function(t){return console.error(t),null})}void 0===r&&(r={});var h=r,f=h.addons,l=void 0===f?[]:f,d=h.sideEffects,m=void 0===d?[]:d,y=h.cache,g=h.pathnameOptions,b=[],E=[];m.forEach(function(t){t.after?E.push(t.fn):b.push(t.fn)});var x,w,T=l.concat(v(g)),k=[],j={},O=[],A=[];n(e);t.subscribe(c);return{ready:function(){return w},refresh:n,subscribe:function(t){if("function"!=typeof t)throw new Error("The argument passed to subscribe must be a function");t.apply(null,A);var e=O.push(t);return function(){O[e-1]=null}},addons:j,history:t}}}();
//# sourceMappingURL=curi.min.js.map
{
"name": "@curi/core",
"version": "1.0.0-beta.11",
"version": "1.0.0-beta.12",
"description": "A JavaScript router you can use with anywhere",

@@ -19,3 +19,3 @@ "main": "dist/curi.common.js",

"prepublishOnly": "npm test",
"prettier": "prettier --single-quote --write \"{src,tests}/**/*.js\"",
"prettier": "prettier --single-quote --write \"{src,tests}/**/*.ts\"",
"test": "jest"

@@ -22,0 +22,0 @@ },

@@ -1,3 +0,4 @@

export { Addon, Subscriber, SideEffect, Params } from './interface';
export { Route, RouteDescriptor, LoadModifiers, LoadFn, PreloadFn } from './utils/createRoute';
export { AddonRegister, AddonGet, Addon, AddonFactory, Subscriber, SideEffect, UnsubscribeFn, Cache, RawParams, Params } from './interface';
export { Path } from './utils/createPath';
export { Route, RouteDescriptor, Title, ParamParser, ParamParsers, LoadModifiers, LoadFn, PreloadFn } from './utils/createRoute';
export { Response, RedirectResponse, AnyResponse } from './utils/createResponse';

@@ -4,0 +5,0 @@ export { CuriConfig, ConfigOptions } from './createConfig';

@@ -23,4 +23,7 @@ import { HickoryLocation } from '@hickory/root';

}
export declare type Params = {
export declare type RawParams = {
[key: string]: string;
};
export declare type Params = {
[key: string]: any;
};
import { HickoryLocation, ToArgument } from '@hickory/root';
import { Route } from './createRoute';
import { Params } from '../interface';
import { RawParams, Params } from '../interface';
export interface BaseResponse {

@@ -42,6 +42,6 @@ key: string;

setStatus(code: number): void;
push(route: Route, params: Params): void;
push(route: Route, params: RawParams): void;
pop(): void;
setData(data: any): void;
freeze(): void;
freezeMatch(): void;
generateTitle(): string;

@@ -48,0 +48,0 @@ asObject(): AnyResponse;

@@ -10,2 +10,6 @@ import { HickoryLocation } from '@hickory/root';

export declare type PreloadFn = () => Promise<any>;
export declare type ParamParser = (input: string) => any;
export interface ParamParsers {
[key: string]: ParamParser;
}
export interface RouteDescriptor {

@@ -15,2 +19,3 @@ name: string;

pathOptions?: RegExpOptions;
params?: ParamParsers;
body?: () => any;

@@ -39,2 +44,3 @@ children?: Array<RouteDescriptor>;

title: Title;
paramParsers: ParamParsers;
extra: {

@@ -41,0 +47,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