@curi/core
Advanced tools
Comparing version 1.0.0-beta.4 to 1.0.0-beta.5
@@ -0,1 +1,6 @@ | ||
## 1.0.0-beta.5 | ||
* Update to `path-to-regexp` v2. The changes can be seen [here](https://github.com/pillarjs/path-to-regexp/blob/master/History.md#200--2017-08-23). Most significantly, instead of using `*` as a wildcard, you now need to use `(.*)`. | ||
* Pass the last `action` type as second argument to subscriber function calls. This makes it so that subscribers and side effects both receive the same arguments. | ||
## 1.0.0-beta.4 | ||
@@ -2,0 +7,0 @@ |
@@ -400,3 +400,3 @@ 'use strict'; | ||
var mostRecentKey = void 0; | ||
var previousResponse = void 0; | ||
var previous = []; | ||
var responseInProgress = void 0; | ||
@@ -467,3 +467,2 @@ | ||
previousResponse = respObject; | ||
return respObject; | ||
@@ -494,5 +493,7 @@ } | ||
// Immediately call subscriber function. If the initial response | ||
// has not resolved, the subscriber will be passed undefined | ||
fn(previousResponse); | ||
// Immediately call subscriber function. If this is called before the | ||
// initial response has resolved, both params will be undefined. If called | ||
// after init resp has resolved, first param is the most recent response and | ||
// action is last history.action. | ||
fn.apply(null, previous); | ||
@@ -508,3 +509,3 @@ var newLength = subscribers.push(fn); | ||
if (response.key !== mostRecentKey) { | ||
return; | ||
return false; | ||
} | ||
@@ -518,5 +519,7 @@ | ||
if (fn != null) { | ||
fn(response); | ||
fn(response, action); | ||
} | ||
}); | ||
return true; | ||
} | ||
@@ -528,3 +531,7 @@ | ||
responseInProgress = prepareResponse(location).then(function (response) { | ||
emit(response, action); | ||
var emitted = emit(response, action); | ||
// only store these after we have emitted. | ||
if (emitted) { | ||
previous = [response, action]; | ||
} | ||
return response; | ||
@@ -531,0 +538,0 @@ }); |
@@ -396,3 +396,3 @@ import PathToRegexp from 'path-to-regexp'; | ||
var mostRecentKey = void 0; | ||
var previousResponse = void 0; | ||
var previous = []; | ||
var responseInProgress = void 0; | ||
@@ -463,3 +463,2 @@ | ||
previousResponse = respObject; | ||
return respObject; | ||
@@ -490,5 +489,7 @@ } | ||
// Immediately call subscriber function. If the initial response | ||
// has not resolved, the subscriber will be passed undefined | ||
fn(previousResponse); | ||
// Immediately call subscriber function. If this is called before the | ||
// initial response has resolved, both params will be undefined. If called | ||
// after init resp has resolved, first param is the most recent response and | ||
// action is last history.action. | ||
fn.apply(null, previous); | ||
@@ -504,3 +505,3 @@ var newLength = subscribers.push(fn); | ||
if (response.key !== mostRecentKey) { | ||
return; | ||
return false; | ||
} | ||
@@ -514,5 +515,7 @@ | ||
if (fn != null) { | ||
fn(response); | ||
fn(response, action); | ||
} | ||
}); | ||
return true; | ||
} | ||
@@ -524,3 +527,7 @@ | ||
responseInProgress = prepareResponse(location).then(function (response) { | ||
emit(response, action); | ||
var emitted = emit(response, action); | ||
// only store these after we have emitted. | ||
if (emitted) { | ||
previous = [response, action]; | ||
} | ||
return response; | ||
@@ -527,0 +534,0 @@ }); |
259
dist/curi.js
@@ -35,10 +35,6 @@ var Curi = (function () { | ||
var index$1 = Array.isArray || function (arr) { | ||
return Object.prototype.toString.call(arr) == '[object Array]'; | ||
}; | ||
/** | ||
* Expose `pathToRegexp`. | ||
*/ | ||
var index = pathToRegexp; | ||
var pathToRegexp_1 = pathToRegexp; | ||
var parse_1 = parse; | ||
@@ -61,6 +57,5 @@ var compile_1 = compile; | ||
// | ||
// "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?", undefined] | ||
// "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined] | ||
// "/*" => ["/", undefined, undefined, undefined, undefined, "*"] | ||
'([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))'].join('|'), 'g'); | ||
// "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?"] | ||
// "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined] | ||
'(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?'].join('|'), 'g'); | ||
@@ -80,5 +75,7 @@ /** | ||
var defaultDelimiter = options && options.delimiter || '/'; | ||
var delimiters = options && options.delimiters || './'; | ||
var pathEscaped = false; | ||
var res; | ||
while ((res = PATH_REGEXP.exec(str)) != null) { | ||
while ((res = PATH_REGEXP.exec(str)) !== null) { | ||
var m = res[0]; | ||
@@ -93,13 +90,22 @@ var escaped = res[1]; | ||
path += escaped[1]; | ||
pathEscaped = true; | ||
continue; | ||
} | ||
var prev = ''; | ||
var next = str[index]; | ||
var prefix = res[2]; | ||
var name = res[3]; | ||
var capture = res[4]; | ||
var group = res[5]; | ||
var modifier = res[6]; | ||
var asterisk = res[7]; | ||
var name = res[2]; | ||
var capture = res[3]; | ||
var group = res[4]; | ||
var modifier = res[5]; | ||
if (!pathEscaped && path.length) { | ||
var k = path.length - 1; | ||
if (delimiters.indexOf(path[k]) > -1) { | ||
prev = path[k]; | ||
path = path.slice(0, k); | ||
} | ||
} | ||
// Push the current path onto the tokens. | ||
@@ -109,8 +115,9 @@ if (path) { | ||
path = ''; | ||
pathEscaped = false; | ||
} | ||
var partial = prefix != null && next != null && next !== prefix; | ||
var partial = prev !== '' && next !== undefined && next !== prev; | ||
var repeat = modifier === '+' || modifier === '*'; | ||
var optional = modifier === '?' || modifier === '*'; | ||
var delimiter = res[2] || defaultDelimiter; | ||
var delimiter = prev || defaultDelimiter; | ||
var pattern = capture || group; | ||
@@ -120,3 +127,3 @@ | ||
name: name || key++, | ||
prefix: prefix || '', | ||
prefix: prev, | ||
delimiter: delimiter, | ||
@@ -126,17 +133,11 @@ optional: optional, | ||
partial: partial, | ||
asterisk: !!asterisk, | ||
pattern: pattern ? escapeGroup(pattern) : asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?' | ||
pattern: pattern ? escapeGroup(pattern) : '[^' + escapeString(delimiter) + ']+?' | ||
}); | ||
} | ||
// Match any characters still remaining. | ||
if (index < str.length) { | ||
path += str.substr(index); | ||
// Push any remaining characters. | ||
if (path || index < str.length) { | ||
tokens.push(path + str.substr(index)); | ||
} | ||
// If the path exists, push it onto the end. | ||
if (path) { | ||
tokens.push(path); | ||
} | ||
return tokens; | ||
@@ -157,26 +158,2 @@ } | ||
/** | ||
* Prettier encoding of URI path segments. | ||
* | ||
* @param {string} | ||
* @return {string} | ||
*/ | ||
function encodeURIComponentPretty(str) { | ||
return encodeURI(str).replace(/[\/?#]/g, function (c) { | ||
return '%' + c.charCodeAt(0).toString(16).toUpperCase(); | ||
}); | ||
} | ||
/** | ||
* Encode the asterisk parameter. Similar to `pretty`, but allows slashes. | ||
* | ||
* @param {string} | ||
* @return {string} | ||
*/ | ||
function encodeAsterisk(str) { | ||
return encodeURI(str).replace(/[?#]/g, function (c) { | ||
return '%' + c.charCodeAt(0).toString(16).toUpperCase(); | ||
}); | ||
} | ||
/** | ||
* Expose a method for transforming tokens into the path function. | ||
@@ -195,7 +172,5 @@ */ | ||
return function (obj, opts) { | ||
return function (data, options) { | ||
var path = ''; | ||
var data = obj || {}; | ||
var options = opts || {}; | ||
var encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent; | ||
var encode = options && options.encode || encodeURIComponent; | ||
@@ -207,33 +182,17 @@ for (var i = 0; i < tokens.length; i++) { | ||
path += token; | ||
continue; | ||
} | ||
var value = data[token.name]; | ||
var value = data ? data[token.name] : undefined; | ||
var segment; | ||
if (value == null) { | ||
if (token.optional) { | ||
// Prepend partial segment prefixes. | ||
if (token.partial) { | ||
path += token.prefix; | ||
} | ||
continue; | ||
} else { | ||
throw new TypeError('Expected "' + token.name + '" to be defined'); | ||
} | ||
} | ||
if (index$1(value)) { | ||
if (Array.isArray(value)) { | ||
if (!token.repeat) { | ||
throw new TypeError('Expected "' + token.name + '" to not repeat, but received `' + JSON.stringify(value) + '`'); | ||
throw new TypeError('Expected "' + token.name + '" to not repeat, but got array'); | ||
} | ||
if (value.length === 0) { | ||
if (token.optional) { | ||
continue; | ||
} else { | ||
throw new TypeError('Expected "' + token.name + '" to not be empty'); | ||
} | ||
if (token.optional) continue; | ||
throw new TypeError('Expected "' + token.name + '" to not be empty'); | ||
} | ||
@@ -245,3 +204,3 @@ | ||
if (!matches[i].test(segment)) { | ||
throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but received `' + JSON.stringify(segment) + '`'); | ||
throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '"'); | ||
} | ||
@@ -255,9 +214,21 @@ | ||
segment = token.asterisk ? encodeAsterisk(value) : encode(value); | ||
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { | ||
segment = encode(String(value)); | ||
if (!matches[i].test(segment)) { | ||
throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but received "' + segment + '"'); | ||
if (!matches[i].test(segment)) { | ||
throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but got "' + segment + '"'); | ||
} | ||
path += token.prefix + segment; | ||
continue; | ||
} | ||
path += token.prefix + segment; | ||
if (token.optional) { | ||
// Prepend partial segment prefixes. | ||
if (token.partial) path += token.prefix; | ||
continue; | ||
} | ||
throw new TypeError('Expected "' + token.name + '" to be ' + (token.repeat ? 'an array' : 'a string')); | ||
} | ||
@@ -276,3 +247,3 @@ | ||
function escapeString(str) { | ||
return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1'); | ||
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1'); | ||
} | ||
@@ -287,18 +258,6 @@ | ||
function escapeGroup(group) { | ||
return group.replace(/([=!:$\/()])/g, '\\$1'); | ||
return group.replace(/([=!:$/()])/g, '\\$1'); | ||
} | ||
/** | ||
* Attach the keys as a property of the regexp. | ||
* | ||
* @param {!RegExp} re | ||
* @param {Array} keys | ||
* @return {!RegExp} | ||
*/ | ||
function attachKeys(re, keys) { | ||
re.keys = keys; | ||
return re; | ||
} | ||
/** | ||
* Get the flags for a regexp from the options. | ||
@@ -310,3 +269,3 @@ * | ||
function flags(options) { | ||
return options.sensitive ? '' : 'i'; | ||
return options && options.sensitive ? '' : 'i'; | ||
} | ||
@@ -318,6 +277,8 @@ | ||
* @param {!RegExp} path | ||
* @param {!Array} keys | ||
* @param {Array=} keys | ||
* @return {!RegExp} | ||
*/ | ||
function regexpToRegexp(path, keys) { | ||
if (!keys) return path; | ||
// Use a negative lookahead to match only capturing groups. | ||
@@ -335,3 +296,2 @@ var groups = path.source.match(/\((?!\?)/g); | ||
partial: false, | ||
asterisk: false, | ||
pattern: null | ||
@@ -342,3 +302,3 @@ }); | ||
return attachKeys(path, keys); | ||
return path; | ||
} | ||
@@ -350,4 +310,4 @@ | ||
* @param {!Array} path | ||
* @param {Array} keys | ||
* @param {!Object} options | ||
* @param {Array=} keys | ||
* @param {Object=} options | ||
* @return {!RegExp} | ||
@@ -362,5 +322,3 @@ */ | ||
var regexp = new RegExp('(?:' + parts.join('|') + ')', flags(options)); | ||
return attachKeys(regexp, keys); | ||
return new RegExp('(?:' + parts.join('|') + ')', flags(options)); | ||
} | ||
@@ -372,4 +330,4 @@ | ||
* @param {string} path | ||
* @param {!Array} keys | ||
* @param {!Object} options | ||
* @param {Array=} keys | ||
* @param {Object=} options | ||
* @return {!RegExp} | ||
@@ -384,13 +342,8 @@ */ | ||
* | ||
* @param {!Array} tokens | ||
* @param {(Array|Object)=} keys | ||
* @param {Object=} options | ||
* @param {!Array} tokens | ||
* @param {Array=} keys | ||
* @param {Object=} options | ||
* @return {!RegExp} | ||
*/ | ||
function tokensToRegExp(tokens, keys, options) { | ||
if (!index$1(keys)) { | ||
options = /** @type {!Object} */keys || options; | ||
keys = []; | ||
} | ||
options = options || {}; | ||
@@ -400,2 +353,4 @@ | ||
var end = options.end !== false; | ||
var delimiter = escapeString(options.delimiter || '/'); | ||
var endsWith = [].concat(options.endsWith || []).map(escapeString).concat('$').join('|'); | ||
var route = ''; | ||
@@ -413,3 +368,3 @@ | ||
keys.push(token); | ||
if (keys) keys.push(token); | ||
@@ -434,22 +389,16 @@ if (token.repeat) { | ||
var delimiter = escapeString(options.delimiter || '/'); | ||
var endsWithDelimiter = route.slice(-delimiter.length) === delimiter; | ||
// In non-strict mode we allow a slash at the end of match. If the path to | ||
// match already ends with a slash, we remove it for consistency. The slash | ||
// is valid at the end of a path match, not in the middle. This is important | ||
// in non-ending mode, where "/test/" shouldn't match "/test//route". | ||
// In non-strict mode we allow a delimiter at the end of a match. | ||
if (!strict) { | ||
route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?'; | ||
route += '(?:' + delimiter + '(?=' + endsWith + '))?'; | ||
} | ||
if (end) { | ||
route += '$'; | ||
route += endsWith === '$' ? endsWith : '(?=' + endsWith + ')'; | ||
} else { | ||
// In non-ending mode, we need the capturing groups to match as much as | ||
// possible by using a positive lookahead to the end or next path segment. | ||
route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)'; | ||
route += '(?=' + delimiter + '|' + endsWith + ')'; | ||
} | ||
return attachKeys(new RegExp('^' + route, flags(options)), keys); | ||
return new RegExp('^' + route, flags(options)); | ||
} | ||
@@ -465,3 +414,3 @@ | ||
* @param {(string|RegExp|Array)} path | ||
* @param {(Array|Object)=} keys | ||
* @param {Array=} keys | ||
* @param {Object=} options | ||
@@ -471,24 +420,17 @@ * @return {!RegExp} | ||
function pathToRegexp(path, keys, options) { | ||
if (!index$1(keys)) { | ||
options = /** @type {!Object} */keys || options; | ||
keys = []; | ||
} | ||
options = options || {}; | ||
if (path instanceof RegExp) { | ||
return regexpToRegexp(path, /** @type {!Array} */keys); | ||
return regexpToRegexp(path, keys); | ||
} | ||
if (index$1(path)) { | ||
return arrayToRegexp( /** @type {!Array} */path, /** @type {!Array} */keys, options); | ||
if (Array.isArray(path)) { | ||
return arrayToRegexp( /** @type {!Array} */path, keys, options); | ||
} | ||
return stringToRegexp( /** @type {string} */path, /** @type {!Array} */keys, options); | ||
return stringToRegexp( /** @type {string} */path, keys, options); | ||
} | ||
index.parse = parse_1; | ||
index.compile = compile_1; | ||
index.tokensToFunction = tokensToFunction_1; | ||
index.tokensToRegExp = tokensToRegExp_1; | ||
pathToRegexp_1.parse = parse_1; | ||
pathToRegexp_1.compile = compile_1; | ||
pathToRegexp_1.tokensToFunction = tokensToFunction_1; | ||
pathToRegexp_1.tokensToRegExp = tokensToRegExp_1; | ||
@@ -595,3 +537,3 @@ var classCallCheck = function (instance, Constructor) { | ||
var mergedOptions = _extends({}, DEFAULT_OPTIONS, options); | ||
var re = index(pathString, keys, mergedOptions); | ||
var re = pathToRegexp_1(pathString, keys, mergedOptions); | ||
@@ -733,3 +675,3 @@ return { re: re, keys: keys }; | ||
} | ||
var compile = cache[name] ? cache[name] : cache[name] = index.compile(knownPaths[name]); | ||
var compile = cache[name] ? cache[name] : cache[name] = pathToRegexp_1.compile(knownPaths[name]); | ||
return withLeadingSlash(compile(params, { pretty: true })); | ||
@@ -859,3 +801,3 @@ } | ||
var mostRecentKey = void 0; | ||
var previousResponse = void 0; | ||
var previous = []; | ||
var responseInProgress = void 0; | ||
@@ -926,3 +868,2 @@ | ||
previousResponse = respObject; | ||
return respObject; | ||
@@ -953,5 +894,7 @@ } | ||
// Immediately call subscriber function. If the initial response | ||
// has not resolved, the subscriber will be passed undefined | ||
fn(previousResponse); | ||
// Immediately call subscriber function. If this is called before the | ||
// initial response has resolved, both params will be undefined. If called | ||
// after init resp has resolved, first param is the most recent response and | ||
// action is last history.action. | ||
fn.apply(null, previous); | ||
@@ -967,3 +910,3 @@ var newLength = subscribers.push(fn); | ||
if (response.key !== mostRecentKey) { | ||
return; | ||
return false; | ||
} | ||
@@ -977,5 +920,7 @@ | ||
if (fn != null) { | ||
fn(response); | ||
fn(response, action); | ||
} | ||
}); | ||
return true; | ||
} | ||
@@ -987,3 +932,7 @@ | ||
responseInProgress = prepareResponse(location).then(function (response) { | ||
emit(response, action); | ||
var emitted = emit(response, action); | ||
// only store these after we have emitted. | ||
if (emitted) { | ||
previous = [response, action]; | ||
} | ||
return response; | ||
@@ -990,0 +939,0 @@ }); |
@@ -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,n=[],i=0,u=0,s="",c=e&&e.delimiter||"/";null!=(r=S.exec(t));){var l=r[0],f=r[1],h=r.index;if(s+=t.slice(u,h),u=h+l.length,f)s+=f[1];else{var p=t[u],d=r[2],v=r[3],m=r[4],y=r[5],g=r[6],b=r[7];s&&(n.push(s),s="");var w=null!=d&&null!=p&&p!==d,E="+"===g||"*"===g,k="?"===g||"*"===g,x=r[2]||c,T=m||y;n.push({name:v||i++,prefix:d||"",delimiter:x,optional:k,repeat:E,partial:w,asterisk:!!b,pattern:T?o(T):b?".*":"[^"+a(x)+"]+?"})}}return u<t.length&&(s+=t.substr(u)),s&&n.push(s),n}function r(t){return encodeURI(t).replace(/[\/?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function n(t){return encodeURI(t).replace(/[?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function i(t){for(var e=new Array(t.length),i=0;i<t.length;i++)"object"==typeof t[i]&&(e[i]=new RegExp("^(?:"+t[i].pattern+")$"));return function(i,a){for(var o="",u=i||{},s=(a||{}).pretty?r:encodeURIComponent,c=0;c<t.length;c++){var l=t[c];if("string"!=typeof l){var f,h=u[l.name];if(null==h){if(l.optional){l.partial&&(o+=l.prefix);continue}throw new TypeError('Expected "'+l.name+'" to be defined')}if(x(h)){if(!l.repeat)throw new TypeError('Expected "'+l.name+'" to not repeat, but received `'+JSON.stringify(h)+"`");if(0===h.length){if(l.optional)continue;throw new TypeError('Expected "'+l.name+'" to not be empty')}for(var p=0;p<h.length;p++){if(f=s(h[p]),!e[c].test(f))throw new TypeError('Expected all "'+l.name+'" to match "'+l.pattern+'", but received `'+JSON.stringify(f)+"`");o+=(0===p?l.prefix:l.delimiter)+f}}else{if(f=l.asterisk?n(h):s(h),!e[c].test(f))throw new TypeError('Expected "'+l.name+'" to match "'+l.pattern+'", but received "'+f+'"');o+=l.prefix+f}}else o+=l}return o}}function a(t){return t.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function o(t){return t.replace(/([=!:$\/()])/g,"\\$1")}function u(t,e){return t.keys=e,t}function s(t){return t.sensitive?"":"i"}function c(t,e){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,asterisk:!1,pattern:null});return u(t,e)}function l(t,e,r){for(var n=[],i=0;i<t.length;i++)n.push(p(t[i],e,r).source);return u(new RegExp("(?:"+n.join("|")+")",s(r)),e)}function f(t,r,n){return h(e(t,n),r,n)}function h(t,e,r){x(e)||(r=e||r,e=[]);for(var n=(r=r||{}).strict,i=!1!==r.end,o="",c=0;c<t.length;c++){var l=t[c];if("string"==typeof l)o+=a(l);else{var f=a(l.prefix),h="(?:"+l.pattern+")";e.push(l),l.repeat&&(h+="(?:"+f+h+")*"),o+=h=l.optional?l.partial?f+"("+h+")?":"(?:"+f+"("+h+"))?":f+"("+h+")"}}var p=a(r.delimiter||"/"),d=o.slice(-p.length)===p;return n||(o=(d?o.slice(0,-p.length):o)+"(?:"+p+"(?=$))?"),o+=i?"$":n&&d?"":"(?="+p+"|$)",u(new RegExp("^"+o,s(r)),e)}function p(t,e,r){return x(e)||(r=e||r,e=[]),r=r||{},t instanceof RegExp?c(t,e):x(t)?l(t,e,r):f(t,e,r)}function d(t,e){var r=v(t);return m(e,r),r}function v(t){return t.map(function(t){var e=t.children?v(t.children):[];return I($({},t,{children:e}))})}function m(t,e){t.forEach(function(t){y(e,t)})}function y(t,e,r){t.forEach(function(t){var n=e.register(t,r);t.children&&y(t.children,e,n)})}function g(){var t={},e={};return{name:"pathname",register:function(e,r){var n=e.name,i=e.path;void 0!==t[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=void 0;return r&&t[r]&&(a=t[r]),t[n]=a?k(a,i):i,n},get:function(r,n){if(null!=t[r]){var i=e[r]?e[r]:e[r]=T.compile(t[r]);return b(i(n,{pretty:!0}))}console.error("Could not generate pathname for "+r+" because it is not registered.")}}}var b=function(t){return"/"===t.charAt(0)?t:"/"+t},w=function(t){return"/"===t.charAt(0)?t.slice(1):t},E=function(t){return"/"===t.charAt(t.length-1)?t:t+"/"},k=function(t,e){return E(t)+e},x=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},T=p,A=e,O=i,j=h,S=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");T.parse=A,T.compile=function(t,r){return i(e(t,r))},T.tokensToFunction=O,T.tokensToRegExp=j;var R=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},C=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),$=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},P=function(t,e){var r={};for(var n in t)e.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n]);return r},U=function(t){return Array.isArray(t)?t:Array.from(t)},B={sensitive:!1,strict:!1,end:!0,delimiter:"/"},D=function(t,e){var r=[],n=$({},B,e);return{re:T(t,r,n),keys:r}},I=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,l=r.load,f=P(r,["name","path","pathOptions","body","children","preload","load"]);if(null==n||null==i)throw new Error("A route must have defined name and path properties");var h=null==o.end||o.end;s&&(o.end=!1);var p=D(i,o);return $({},f,{name:n,path:i,body:u,getBody:function(){return this.body&&this.body()},children:s,preload:c?t(c):void 0,load:l,keys:p.keys.map(function(t){return t.name}),match:function(t,e,r){var n=w(t),i=p.re.exec(n);if(!i)return!1;var a=U(i),o=a[0],u=a.slice(1),c={};p.keys.forEach(function(t,e){c[t.name]=u[e]});var l=null!=r?k(r,o):b(o);if(e.push(this,c),!s||!s.length)return!0;var f=n.slice(o.length),d=!!f.length,v=s.some(function(t){return t.match(f,e,l)});return!(h&&d&&!v)||(e.pop(),!1)}})},z=function(){function t(e,r){R(this,t),this.key=e,this.location=r,this.status=200,this.matches=[],this.route,this.partials=[],this.params={},this.body}return C(t,[{key:"redirect",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:301;this.setStatus(e),this.redirectTo=t}},{key:"fail",value:function(t){this.error=t}},{key:"setStatus",value:function(t){this.status=t}},{key:"push",value:function(t,e){this.matches.push({route:t,params:e})}},{key:"pop",value:function(){this.matches.pop()}},{key:"setData",value:function(t){this.data=t}},{key:"freeze",value:function(){var t=this;if(this.matches.length){var e=this.matches.pop();this.matches.forEach(function(e){t.partials.push(e.route.name),$(t.params,e.params)}),this.route=e.route,$(this.params,e.params)}}},{key:"generateTitle",value:function(){return this.route&&this.route.title?"function"==typeof this.route.title?this.route.title(this.params,this.data):this.route.title:""}},{key:"asObject",value:function(){var t={key:this.key,location:this.location,status:this.status,data:this.data,title:this.generateTitle()};return null!=this.redirectTo?$({},t,{redirectTo:this.redirectTo}):$({},t,{body:this.route&&this.route.getBody(),name:this.route?this.route.name:void 0,partials:this.partials,params:this.params,error:this.error})}}]),t}();return function(t,e){function r(e){var r=[];for(var n in w)delete w[n];y.forEach(function(t){var e=t();w[e.name]=e.get,r.push(e)}),b=d(e,r,{}),s(t.location,t.action)}function n(e){return b.some(function(r){return r.match(t.location.pathname,e)}),e.freeze(),Promise.resolve(e)}function i(t){if(!t.route)return t.setStatus(404),Promise.resolve(t);var e=t.route,r=e.preload,n=e.load,i=n?{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([r?r():null,n?n(t.params,t.location,i):null]).catch(function(e){t.fail(e)}).then(function(){return t})}function a(t){var e=t.asObject();return m&&m.set(e),x=e,e}function o(t){var e=t.key||Math.random().toString(36).slice(2,8);if(k=e,m){var r=m.get(t);if(null!=r)return Promise.resolve(r)}return n(new z(e,t)).then(i).then(a)}function u(t,e){t.key===k&&(p.forEach(function(r){r(t,e)}),E.forEach(function(e){null!=e&&e(t)}))}function s(t,e){T=o(t).then(function(t){return u(t,e),t})}var c=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},l=c.addons,f=void 0===l?[]:l,h=c.sideEffects,p=void 0===h?[]:h,v=c.cache,m=void 0!==v&&v,y=f.concat(g),b=[],w={},E=[],k=void 0,x=void 0,T=void 0;r(e);t.subscribe(s);return{ready:function(){return T},refresh:r,subscribe:function(t){if("function"!=typeof t)throw new Error("The argument passed to subscribe must be a function");t(x);var e=E.push(t);return function(){E[e-1]=null}},addons:w,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||"/",l=e&&e.delimiters||"./",h=!1;null!==(r=T.exec(t));){var f=r[0],p=r[1],d=r.index;if(s+=t.slice(u,d),u=d+f.length,p)s+=p[1],h=!0;else{var v="",m=t[u],y=r[2],g=r[3],b=r[4],w=r[5];if(!h&&s.length){var E=s.length-1;l.indexOf(s[E])>-1&&(v=s[E],s=s.slice(0,E))}s&&(a.push(s),s="",h=!1);var x=""!==v&&void 0!==m&&m!==v,k="+"===w||"*"===w,A="?"===w||"*"===w,O=v||c,j=g||b;a.push({name:y||o++,prefix:v,delimiter:O,optional:A,repeat:k,partial:x,pattern:j?i(j):"[^"+n(O)+"]+?"})}}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 l=0;l<c.length;l++){if(s=a(c[l]),!e[o].test(s))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'"');i+=(0===l?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(l(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="",l=0;l<t.length;l++){var h=t[l];if("string"==typeof h)c+=n(h);else{var f=n(h.prefix),p="(?:"+h.pattern+")";e&&e.push(h),h.repeat&&(p+="(?:"+f+p+")*"),c+=p=h.optional?h.partial?f+"("+p+")?":"(?:"+f+"("+p+"))?":f+"("+p+")"}}return i||(c+="(?:"+u+"(?="+s+"))?"),c+=o?"$"===s?s:"(?="+s+")":"(?="+u+"|"+s+")",new RegExp("^"+c,a(r))}function l(t,e,r){return t instanceof RegExp?o(t,e):Array.isArray(t)?u(t,e,r):s(t,e,r)}function h(t,e){var r=f(t);return p(e,r),r}function f(t){return t.map(function(t){var e=t.children?f(t.children):[];return C(j({},t,{children:e}))})}function p(t,e){t.forEach(function(t){d(e,t)})}function d(t,e,r){t.forEach(function(t){var n=e.register(t,r);t.children&&d(t.children,e,n)})}function v(){var t={},e={};return{name:"pathname",register:function(e,r){var n=e.name,i=e.path;void 0!==t[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=void 0;return r&&t[r]&&(a=t[r]),t[n]=a?b(a,i):i,n},get:function(r,n){if(null!=t[r]){var i=e[r]?e[r]:e[r]=w.compile(t[r]);return m(i(n,{pretty:!0}))}console.error("Could not generate pathname for "+r+" because it is not registered.")}}}var m=function(t){return"/"===t.charAt(0)?t:"/"+t},y=function(t){return"/"===t.charAt(0)?t.slice(1):t},g=function(t){return"/"===t.charAt(t.length-1)?t:t+"/"},b=function(t,e){return g(t)+e},w=l,E=e,x=r,k=c,T=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");w.parse=E,w.compile=function(t,n){return r(e(t,n))},w.tokensToFunction=x,w.tokensToRegExp=k;var A=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},O=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),j=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},P=function(t,e){var r={};for(var n in t)e.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n]);return r},R=function(t){return Array.isArray(t)?t:Array.from(t)},S={sensitive:!1,strict:!1,end:!0,delimiter:"/"},$=function(t,e){var r=[],n=j({},S,e);return{re:w(t,r,n),keys:r}},C=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,l=r.load,h=P(r,["name","path","pathOptions","body","children","preload","load"]);if(null==n||null==i)throw new Error("A route must have defined name and path properties");var f=null==o.end||o.end;s&&(o.end=!1);var p=$(i,o);return j({},h,{name:n,path:i,body:u,getBody:function(){return this.body&&this.body()},children:s,preload:c?t(c):void 0,load:l,keys:p.keys.map(function(t){return t.name}),match:function(t,e,r){var n=y(t),i=p.re.exec(n);if(!i)return!1;var a=R(i),o=a[0],u=a.slice(1),c={};p.keys.forEach(function(t,e){c[t.name]=u[e]});var l=null!=r?b(r,o):m(o);if(e.push(this,c),!s||!s.length)return!0;var h=n.slice(o.length),d=!!h.length,v=s.some(function(t){return t.match(h,e,l)});return!(f&&d&&!v)||(e.pop(),!1)}})},B=function(){function t(e,r){A(this,t),this.key=e,this.location=r,this.status=200,this.matches=[],this.route,this.partials=[],this.params={},this.body}return O(t,[{key:"redirect",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:301;this.setStatus(e),this.redirectTo=t}},{key:"fail",value:function(t){this.error=t}},{key:"setStatus",value:function(t){this.status=t}},{key:"push",value:function(t,e){this.matches.push({route:t,params:e})}},{key:"pop",value:function(){this.matches.pop()}},{key:"setData",value:function(t){this.data=t}},{key:"freeze",value:function(){var t=this;if(this.matches.length){var e=this.matches.pop();this.matches.forEach(function(e){t.partials.push(e.route.name),j(t.params,e.params)}),this.route=e.route,j(this.params,e.params)}}},{key:"generateTitle",value:function(){return this.route&&this.route.title?"function"==typeof this.route.title?this.route.title(this.params,this.data):this.route.title:""}},{key:"asObject",value:function(){var t={key:this.key,location:this.location,status:this.status,data:this.data,title:this.generateTitle()};return null!=this.redirectTo?j({},t,{redirectTo:this.redirectTo}):j({},t,{body:this.route&&this.route.getBody(),name:this.route?this.route.name:void 0,partials:this.partials,params:this.params,error:this.error})}}]),t}();return function(t,e){function r(e){var r=[];for(var n in w)delete w[n];g.forEach(function(t){var e=t();w[e.name]=e.get,r.push(e)}),b=h(e,r,{}),s(t.location,t.action)}function n(e){return b.some(function(r){return r.match(t.location.pathname,e)}),e.freeze(),Promise.resolve(e)}function i(t){if(!t.route)return t.setStatus(404),Promise.resolve(t);var e=t.route,r=e.preload,n=e.load,i=n?{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([r?r():null,n?n(t.params,t.location,i):null]).catch(function(e){t.fail(e)}).then(function(){return t})}function a(t){var e=t.asObject();return y&&y.set(e),e}function o(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 n(new B(e,t)).then(i).then(a)}function u(t,e){return t.key===x&&(d.forEach(function(r){r(t,e)}),E.forEach(function(r){null!=r&&r(t,e)}),!0)}function s(t,e){T=o(t).then(function(t){return u(t,e)&&(k=[t,e]),t})}var c=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},l=c.addons,f=void 0===l?[]:l,p=c.sideEffects,d=void 0===p?[]:p,m=c.cache,y=void 0!==m&&m,g=f.concat(v),b=[],w={},E=[],x=void 0,k=[],T=void 0;r(e);t.subscribe(s);return{ready:function(){return T},refresh:r,subscribe:function(t){if("function"!=typeof t)throw new Error("The argument passed to subscribe must be a function");t.apply(null,k);var e=E.push(t);return function(){E[e-1]=null}},addons:w,history:t}}}(); | ||
//# sourceMappingURL=curi.min.js.map |
{ | ||
"name": "@curi/core", | ||
"version": "1.0.0-beta.4", | ||
"description": "curi is a configuration based routing solution", | ||
"version": "1.0.0-beta.5", | ||
"description": "A JavaScript router you can use with anywhere", | ||
"main": "dist/curi.common.js", | ||
@@ -33,3 +33,3 @@ "module": "dist/curi.es.js", | ||
"dependencies": { | ||
"path-to-regexp": "^1.7.0" | ||
"path-to-regexp": "^2.0.0" | ||
}, | ||
@@ -47,4 +47,4 @@ "devDependencies": { | ||
"rimraf": "^2.6.1", | ||
"rollup": "^0.43.0" | ||
"rollup": "^0.48.2" | ||
} | ||
} |
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
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
179595
1661
+ Addedpath-to-regexp@2.4.0(transitive)
- Removedisarray@0.0.1(transitive)
- Removedpath-to-regexp@1.9.0(transitive)
Updatedpath-to-regexp@^2.0.0