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

agnostic-router

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

agnostic-router - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

2

bower.json
{
"name": "agnostic-router",
"version": "0.1.0",
"version": "0.2.0",
"description": "Route URLs without requiring Express, or even a webserver",

@@ -5,0 +5,0 @@ "authors": [

{
"name": "agnostic-router",
"version": "0.1.0",
"version": "0.2.0",
"description": "Route URLs without requiring Express and friends",

@@ -15,8 +15,7 @@ "license": "MIT",

"devDependencies": {
"browserify": "11.2.x",
"minifyify": "7.3.x",
"mocha": "2.4.x"
"browserify": "14.4.x",
"minifyify": "7.3.x"
},
"dependencies": {
"url-pattern": "0.10.x"
"url-pattern": "1.0.x"
},

@@ -23,0 +22,0 @@ "scripts": {

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Router = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var slice=[].slice;!function(e,r){return"function"==typeof define&&null!=define.amd?define([],r):"undefined"!=typeof exports&&null!==exports?module.exports=r():e.UrlPattern=r()}(this,function(){var e,r,t,n,a,i,u,s,o,l,c,g,f,h,m;return o=function(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")},u=function(e,r){var t,n,a;for(a=[],t=-1,n=e.length;++t<n;)a=a.concat(r(e[t]));return a},h=function(e,r){var t,n,a;for(a="",t=-1,n=e.length;++t<n;)a+=r(e[t]);return a},f=function(e){return new RegExp(e.toString()+"|").exec("").length-1},c=function(e,r){var t,n,a,i,u;for(i={},t=-1,a=e.length;++t<a;)n=e[t],u=r[t],null!=u&&(null!=i[n]?(Array.isArray(i[n])||(i[n]=[i[n]]),i[n].push(u)):i[n]=u);return i},e={},e.Result=function(e,r){this.value=e,this.rest=r},e.Tagged=function(e,r){this.tag=e,this.value=r},e.tag=function(r,t){return function(n){var a,i;if(a=t(n),null!=a)return i=new e.Tagged(r,a.value),new e.Result(i,a.rest)}},e.regex=function(r){return function(t){var n,a;if(n=r.exec(t),null!=n)return a=n[0],new e.Result(a,t.slice(a.length))}},e.sequence=function(){var r;return r=1<=arguments.length?slice.call(arguments,0):[],function(t){var n,a,i,u,s,o;for(n=-1,a=r.length,o=[],u=t;++n<a;){if(i=r[n],s=i(u),null==s)return;o.push(s.value),u=s.rest}return new e.Result(o,u)}},e.pick=function(){var r,t;return r=arguments[0],t=2<=arguments.length?slice.call(arguments,1):[],function(n){var a,i;if(i=e.sequence.apply(e,t)(n),null!=i)return a=i.value,i.value=a[r],i}},e.string=function(r){var t;return t=r.length,function(n){if(n.slice(0,t)===r)return new e.Result(r,n.slice(t))}},e.lazy=function(e){var r;return r=null,function(t){return null==r&&(r=e()),r(t)}},e.baseMany=function(r,t,n,a,i){var u,s,o,l;for(o=i,l=n?"":[];;){if(null!=t&&(u=t(o),null!=u))break;if(s=r(o),null==s)break;n?l+=s.value:l.push(s.value),o=s.rest}if(!a||0!==l.length)return new e.Result(l,o)},e.many1=function(r){return function(t){return e.baseMany(r,null,!1,!0,t)}},e.concatMany1Till=function(r,t){return function(n){return e.baseMany(r,t,!0,!0,n)}},e.firstChoice=function(){var e;return e=1<=arguments.length?slice.call(arguments,0):[],function(r){var t,n,a,i;for(t=-1,n=e.length;++t<n;)if(a=e[t],i=a(r),null!=i)return i}},g=function(r){var t;return t={},t.wildcard=e.tag("wildcard",e.string(r.wildcardChar)),t.optional=e.tag("optional",e.pick(1,e.string(r.optionalSegmentStartChar),e.lazy(function(){return t.pattern}),e.string(r.optionalSegmentEndChar))),t.name=e.regex(new RegExp("^["+r.segmentNameCharset+"]+")),t.named=e.tag("named",e.pick(1,e.string(r.segmentNameStartChar),e.lazy(function(){return t.name}))),t.escapedChar=e.pick(1,e.string(r.escapeChar),e.regex(/^./)),t.static=e.tag("static",e.concatMany1Till(e.firstChoice(e.lazy(function(){return t.escapedChar}),e.regex(/^./)),e.firstChoice(e.string(r.segmentNameStartChar),e.string(r.optionalSegmentStartChar),e.string(r.optionalSegmentEndChar),t.wildcard))),t.token=e.lazy(function(){return e.firstChoice(t.wildcard,t.optional,t.named,t.static)}),t.pattern=e.many1(e.lazy(function(){return t.token})),t},s={escapeChar:"\\",segmentNameStartChar:":",segmentValueCharset:"a-zA-Z0-9-_~ %",segmentNameCharset:"a-zA-Z0-9",optionalSegmentStartChar:"(",optionalSegmentEndChar:")",wildcardChar:"*"},i=function(e,r){if(Array.isArray(e))return h(e,function(e){return i(e,r)});switch(e.tag){case"wildcard":return"(.*?)";case"named":return"(["+r+"]+)";case"static":return o(e.value);case"optional":return"(?:"+i(e.value,r)+")?"}},a=function(e,r){return null==r&&(r=s.segmentValueCharset),"^"+i(e,r)+"$"},n=function(e){if(Array.isArray(e))return u(e,n);switch(e.tag){case"wildcard":return["_"];case"named":return[e.value];case"static":return[];case"optional":return n(e.value)}},l=function(e,r,t,n){var a,i,u,s;if(null==n&&(n=!1),s=e[r],null!=s){if(a=t[r]||0,i=Array.isArray(s)?s.length-1:0,!(a>i))return u=Array.isArray(s)?s[a]:s,n&&(t[r]=a+1),u;if(n)throw new Error("too few values provided for key `"+r+"`")}else if(n)throw new Error("no values provided for key `"+r+"`")},t=function(e,r,n){var a,i;if(Array.isArray(e)){for(a=-1,i=e.length;++a<i;)if(t(e[a],r,n))return!0;return!1}switch(e.tag){case"wildcard":return null!=l(r,"_",n,!1);case"named":return null!=l(r,e.value,n,!1);case"static":return!1;case"optional":return t(e.value,r,n)}},m=function(e,r,n){if(Array.isArray(e))return h(e,function(e){return m(e,r,n)});switch(e.tag){case"wildcard":return l(r,"_",n,!0);case"named":return l(r,e.value,n,!0);case"static":return e.value;case"optional":return t(e.value,r,n)?m(e.value,r,n):""}},r=function(e,t){var i,u,o,l,c;if(e instanceof r)return this.isRegex=e.isRegex,this.regex=e.regex,this.ast=e.ast,void(this.names=e.names);if(this.isRegex=e instanceof RegExp,"string"!=typeof e&&!this.isRegex)throw new TypeError("argument must be a regex or a string");if(this.isRegex){if(this.regex=e,null!=t){if(!Array.isArray(t))throw new Error("if first argument is a regex the second argument may be an array of group names but you provided something else");if(i=f(this.regex),t.length!==i)throw new Error("regex contains "+i+" groups but array of group names contains "+t.length);this.names=t}}else{if(""===e)throw new Error("argument must not be the empty string");if(c=e.replace(/\s+/g,""),c!==e)throw new Error("argument must not contain whitespace");if(u={escapeChar:(null!=t?t.escapeChar:void 0)||s.escapeChar,segmentNameStartChar:(null!=t?t.segmentNameStartChar:void 0)||s.segmentNameStartChar,segmentNameCharset:(null!=t?t.segmentNameCharset:void 0)||s.segmentNameCharset,segmentValueCharset:(null!=t?t.segmentValueCharset:void 0)||s.segmentValueCharset,optionalSegmentStartChar:(null!=t?t.optionalSegmentStartChar:void 0)||s.optionalSegmentStartChar,optionalSegmentEndChar:(null!=t?t.optionalSegmentEndChar:void 0)||s.optionalSegmentEndChar,wildcardChar:(null!=t?t.wildcardChar:void 0)||s.wildcardChar},l=g(u),o=l.pattern(e),null==o)throw new Error("couldn't parse pattern");if(""!==o.rest)throw new Error("could only partially parse pattern");this.ast=o.value,this.regex=new RegExp(a(this.ast,u.segmentValueCharset)),this.names=n(this.ast)}},r.prototype.match=function(e){var r,t;return t=this.regex.exec(e),null==t?null:(r=t.slice(1),this.names?c(this.names,r):r)},r.prototype.stringify=function(e){if(null==e&&(e={}),this.isRegex)throw new Error("can't stringify patterns generated from a regex");if(e!==Object(e))throw new Error("argument must be an object or undefined");return m(this.ast,e,{})},r.escapeForRegex=o,r.concatMap=u,r.stringConcatMap=h,r.regexGroupCount=f,r.keysAndValuesToObject=c,r.P=e,r.newParser=g,r.defaultOptions=s,r.astNodeToRegexString=a,r.astNodeToNames=n,r.getParam=l,r.astNodeContainsSegmentsForProvidedParams=t,r.stringify=m,r});
var slice=[].slice;!function(e,r){"function"==typeof define&&null!=define.amd?define([],r):"undefined"!=typeof exports&&null!==exports?module.exports=r():e.UrlPattern=r()}(this,function(){var e,r,t,n,a,i,s,u,o,l,c,g,f,h,m;return o=function(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")},s=function(e,r){var t,n,a;for(a=[],t=-1,n=e.length;++t<n;)a=a.concat(r(e[t]));return a},h=function(e,r){var t,n,a;for(a="",t=-1,n=e.length;++t<n;)a+=r(e[t]);return a},f=function(e){return new RegExp(e.toString()+"|").exec("").length-1},c=function(e,r){var t,n,a,i,s;for(i={},t=-1,a=e.length;++t<a;)n=e[t],null!=(s=r[t])&&(null!=i[n]?(Array.isArray(i[n])||(i[n]=[i[n]]),i[n].push(s)):i[n]=s);return i},e={},e.Result=function(e,r){this.value=e,this.rest=r},e.Tagged=function(e,r){this.tag=e,this.value=r},e.tag=function(r,t){return function(n){var a,i;if(null!=(a=t(n)))return i=new e.Tagged(r,a.value),new e.Result(i,a.rest)}},e.regex=function(r){return function(t){var n,a;if(null!=(n=r.exec(t)))return a=n[0],new e.Result(a,t.slice(a.length))}},e.sequence=function(){var r;return r=1<=arguments.length?slice.call(arguments,0):[],function(t){var n,a,i,s,u,o;for(n=-1,a=r.length,o=[],s=t;++n<a;){if(i=r[n],null==(u=i(s)))return;o.push(u.value),s=u.rest}return new e.Result(o,s)}},e.pick=function(){var r,t;return r=arguments[0],t=2<=arguments.length?slice.call(arguments,1):[],function(n){var a,i;if(null!=(i=e.sequence.apply(e,t)(n)))return a=i.value,i.value=a[r],i}},e.string=function(r){var t;return t=r.length,function(n){if(n.slice(0,t)===r)return new e.Result(r,n.slice(t))}},e.lazy=function(e){var r;return r=null,function(t){return null==r&&(r=e()),r(t)}},e.baseMany=function(r,t,n,a,i){var s,u,o;for(u=i,o=n?"":[];;){if(null!=t&&null!=t(u))break;if(null==(s=r(u)))break;n?o+=s.value:o.push(s.value),u=s.rest}if(!a||0!==o.length)return new e.Result(o,u)},e.many1=function(r){return function(t){return e.baseMany(r,null,!1,!0,t)}},e.concatMany1Till=function(r,t){return function(n){return e.baseMany(r,t,!0,!0,n)}},e.firstChoice=function(){var e;return e=1<=arguments.length?slice.call(arguments,0):[],function(r){var t,n,a,i;for(t=-1,n=e.length;++t<n;)if(a=e[t],null!=(i=a(r)))return i}},g=function(r){var t;return t={},t.wildcard=e.tag("wildcard",e.string(r.wildcardChar)),t.optional=e.tag("optional",e.pick(1,e.string(r.optionalSegmentStartChar),e.lazy(function(){return t.pattern}),e.string(r.optionalSegmentEndChar))),t.name=e.regex(new RegExp("^["+r.segmentNameCharset+"]+")),t.named=e.tag("named",e.pick(1,e.string(r.segmentNameStartChar),e.lazy(function(){return t.name}))),t.escapedChar=e.pick(1,e.string(r.escapeChar),e.regex(/^./)),t.static=e.tag("static",e.concatMany1Till(e.firstChoice(e.lazy(function(){return t.escapedChar}),e.regex(/^./)),e.firstChoice(e.string(r.segmentNameStartChar),e.string(r.optionalSegmentStartChar),e.string(r.optionalSegmentEndChar),t.wildcard))),t.token=e.lazy(function(){return e.firstChoice(t.wildcard,t.optional,t.named,t.static)}),t.pattern=e.many1(e.lazy(function(){return t.token})),t},u={escapeChar:"\\",segmentNameStartChar:":",segmentValueCharset:"a-zA-Z0-9-_~ %",segmentNameCharset:"a-zA-Z0-9",optionalSegmentStartChar:"(",optionalSegmentEndChar:")",wildcardChar:"*"},i=function(e,r){if(Array.isArray(e))return h(e,function(e){return i(e,r)});switch(e.tag){case"wildcard":return"(.*?)";case"named":return"(["+r+"]+)";case"static":return o(e.value);case"optional":return"(?:"+i(e.value,r)+")?"}},a=function(e,r){return null==r&&(r=u.segmentValueCharset),"^"+i(e,r)+"$"},n=function(e){if(Array.isArray(e))return s(e,n);switch(e.tag){case"wildcard":return["_"];case"named":return[e.value];case"static":return[];case"optional":return n(e.value)}},l=function(e,r,t,n){var a,i,s,u;if(null==n&&(n=!1),null!=(u=e[r])){if(a=t[r]||0,i=Array.isArray(u)?u.length-1:0,!(a>i))return s=Array.isArray(u)?u[a]:u,n&&(t[r]=a+1),s;if(n)throw new Error("too few values provided for key `"+r+"`")}else if(n)throw new Error("no values provided for key `"+r+"`")},t=function(e,r,n){var a,i;if(Array.isArray(e)){for(a=-1,i=e.length;++a<i;)if(t(e[a],r,n))return!0;return!1}switch(e.tag){case"wildcard":return null!=l(r,"_",n,!1);case"named":return null!=l(r,e.value,n,!1);case"static":return!1;case"optional":return t(e.value,r,n)}},m=function(e,r,n){if(Array.isArray(e))return h(e,function(e){return m(e,r,n)});switch(e.tag){case"wildcard":return l(r,"_",n,!0);case"named":return l(r,e.value,n,!0);case"static":return e.value;case"optional":return t(e.value,r,n)?m(e.value,r,n):""}},r=function(e,t){var i,s,o,l;if(e instanceof r)return this.isRegex=e.isRegex,this.regex=e.regex,this.ast=e.ast,void(this.names=e.names);if(this.isRegex=e instanceof RegExp,"string"!=typeof e&&!this.isRegex)throw new TypeError("argument must be a regex or a string");if(this.isRegex){if(this.regex=e,null!=t){if(!Array.isArray(t))throw new Error("if first argument is a regex the second argument may be an array of group names but you provided something else");if(i=f(this.regex),t.length!==i)throw new Error("regex contains "+i+" groups but array of group names contains "+t.length);this.names=t}}else{if(""===e)throw new Error("argument must not be the empty string");if(e.replace(/\s+/g,"")!==e)throw new Error("argument must not contain whitespace");if(s={escapeChar:(null!=t?t.escapeChar:void 0)||u.escapeChar,segmentNameStartChar:(null!=t?t.segmentNameStartChar:void 0)||u.segmentNameStartChar,segmentNameCharset:(null!=t?t.segmentNameCharset:void 0)||u.segmentNameCharset,segmentValueCharset:(null!=t?t.segmentValueCharset:void 0)||u.segmentValueCharset,optionalSegmentStartChar:(null!=t?t.optionalSegmentStartChar:void 0)||u.optionalSegmentStartChar,optionalSegmentEndChar:(null!=t?t.optionalSegmentEndChar:void 0)||u.optionalSegmentEndChar,wildcardChar:(null!=t?t.wildcardChar:void 0)||u.wildcardChar},l=g(s),null==(o=l.pattern(e)))throw new Error("couldn't parse pattern");if(""!==o.rest)throw new Error("could only partially parse pattern");this.ast=o.value,this.regex=new RegExp(a(this.ast,s.segmentValueCharset)),this.names=n(this.ast)}},r.prototype.match=function(e){var r,t;return null==(t=this.regex.exec(e))?null:(r=t.slice(1),this.names?c(this.names,r):r)},r.prototype.stringify=function(e){if(null==e&&(e={}),this.isRegex)throw new Error("can't stringify patterns generated from a regex");if(e!==Object(e))throw new Error("argument must be an object or undefined");return m(this.ast,e,{})},r.escapeForRegex=o,r.concatMap=s,r.stringConcatMap=h,r.regexGroupCount=f,r.keysAndValuesToObject=c,r.P=e,r.newParser=g,r.defaultOptions=u,r.astNodeToRegexString=a,r.astNodeToNames=n,r.getParam=l,r.astNodeContainsSegmentsForProvidedParams=t,r.stringify=m,r});
},{}],2:[function(require,module,exports){
function Router(){this.useRoutes=[],this.methodRoutes={},this.index=0}var UrlPattern=require("url-pattern");Router.prototype.route=function(){function t(){var r=a.shift();"undefined"!=typeof r?(e.params=r.params,"function"==typeof r.handler?r.handler(e,o,t):Router._isRouter(r.handler)?r.handler.route(e.method,"/"+e.params._,e,o,t):t()):"function"==typeof n&&n()}if(3==arguments.length)var e={},o=arguments[2];else if(arguments.length>=4){var e=arguments[2];"object"==typeof e&&e||(e={});var o=arguments[3]}e.method=arguments[0];var r=arguments[1];"undefined"==typeof e.path&&(e.path=r);var n=arguments[4],a=this._methodPathMatches(e.method,r);t()},Router.prototype.use=function(){var t="string"==typeof arguments[0]?arguments[0]:"",e=Router._validHandler(arguments[0])?arguments[0]:arguments[1];return this._addRouteToArray(this.useRoutes,Router._normalizePath(t),e)},Router.prototype.useFirst=function(){var t="string"==typeof arguments[0]?arguments[0]:"",e=Router._validHandler(arguments[0])?arguments[0]:arguments[1];return this._addRouteToArray(this.useRoutes,Router._normalizePath(t),e,!0)},Router.prototype.method=function(t,e,o){return this.methodRoutes[t]instanceof Array||(this.methodRoutes[t]=[]),this._addRouteToArray(this.methodRoutes[t],Router._normalizePath(e),o)},Router._validHandler=function(t){return"function"==typeof t||Router._isRouter(t)},Router._isRouter=function(t){return"object"==typeof t&&"function"==typeof t.route},Router._normalizePath=function(t){return t.replace(/\/$/,"")},Router.prototype._methodPathMatches=function(t,e){var o=Router._normalizePath(e),r=[],n=this;return n.useRoutes.forEach(function(t){var e=new UrlPattern(t.path+"(/*)").match(o);null!==e&&r.push({path:t.path,handler:t.handler,params:e})}),n.methodRoutes[t]instanceof Array&&n.methodRoutes[t].forEach(function(t){var e=new UrlPattern(t.path).match(o);null!==e&&r.push({path:t.path,handler:t.handler,params:e})}),r},Router.prototype._addRouteToArray=function(t,e,o,r){var n={path:e,handler:o};"boolean"==typeof r?t.unshift(n):t.push(n)},module.exports=function(){return new Router};
function Router(){this.useRoutes=[],this.methodRoutes={},this.index=0,this.UrlPattern=UrlPattern}var UrlPattern=require("url-pattern");Router.prototype.route=function(){function t(){var o=n.shift();void 0!==o?(e.params=o.params,"function"==typeof o.handler?o.handler(e,r,t):Router._isRouter(o.handler)?o.handler.route(e.method,"/"+e.params._,e,r,t):t()):"function"==typeof a&&a()}if(3==arguments.length)var e={},r=arguments[2];else if(arguments.length>=4){var e=arguments[2];"object"==typeof e&&e||(e={});var r=arguments[3]}e.method=arguments[0];var o=arguments[1];void 0===e.path&&(e.path=o);var a=arguments[4],n=this._methodPathMatches(e.method,o);t()},Router.prototype.use=function(){var t="string"==typeof arguments[0]?arguments[0]:"",e=Router._validHandler(arguments[0])?arguments[0]:arguments[1];return this._addRouteToArray(this.useRoutes,Router._normalizePath(t),e)},Router.prototype.useFirst=function(){var t="string"==typeof arguments[0]?arguments[0]:"",e=Router._validHandler(arguments[0])?arguments[0]:arguments[1];return this._addRouteToArray(this.useRoutes,Router._normalizePath(t),e,!0)},Router.prototype.method=function(t,e,r){return this.methodRoutes[t]instanceof Array||(this.methodRoutes[t]=[]),this._addRouteToArray(this.methodRoutes[t],Router._normalizePath(e),r)},Router._validHandler=function(t){return"function"==typeof t||Router._isRouter(t)},Router._isRouter=function(t){return"object"==typeof t&&"function"==typeof t.route},Router._normalizePath=function(t){return t.replace(/\/$/,"")},Router.prototype._methodPathMatches=function(t,e){var r=Router._normalizePath(e),o=[],a=this;return a.useRoutes.forEach(function(t){var e=new UrlPattern(t.path+"(/*)").match(r);null!==e&&o.push({path:t.path,handler:t.handler,params:e})}),a.methodRoutes[t]instanceof Array&&a.methodRoutes[t].forEach(function(t){var e=new UrlPattern(t.path).match(r);null!==e&&o.push({path:t.path,handler:t.handler,params:e})}),o},Router.prototype._addRouteToArray=function(t,e,r,o){var a={path:e,handler:r};"boolean"==typeof o?t.unshift(a):t.push(a)},module.exports=function(){return new Router};
},{"url-pattern":1}]},{},[2])(2)

@@ -6,0 +6,0 @@ });

@@ -7,2 +7,3 @@ var UrlPattern = require('url-pattern');

this.index = 0;
this.UrlPattern = UrlPattern;
}

@@ -9,0 +10,0 @@

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