New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

susanin

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

susanin - npm Package Compare versions

Comparing version 0.1.9 to 0.1.10

2

package.json
{
"name" : "susanin",
"version" : "0.1.9",
"version" : "0.1.10",
"author" : {

@@ -5,0 +5,0 @@ "name" : "Ruslan Kerimov",

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

# Susanin [![Build Status](https://travis-ci.org/ruslankerimov/susanin.png?branch=master)](https://travis-ci.org/ruslankerimov/susanin)
# Susanin [![Build Status](https://travis-ci.org/nodules/susanin.png?branch=master)](https://travis-ci.org/nodules/susanin)
Susanin is a routing library which can be used in any JavaScript environments.
## [Demo](http://nodules.github.io/susanin)
## Getting Started

@@ -102,3 +104,3 @@

conditions : {
category : [ 'shoes', 'jeans', 'shirt' ]
category : [ 'shoes', 'jeans', 'shirt' ],
id : '\\d{3,4}'

@@ -105,0 +107,0 @@ }

@@ -137,3 +137,3 @@ (function(global) {

var PARAM_NAME_REGEXP_SOURCE = '[a-zA-Z_][\\w\\-]*';
var PARAM_VALUE_REGEXP_SOURCE = '[\\w\\-]+';
var PARAM_VALUE_REGEXP_SOURCE = '[\\w\\-\\.~]+';

@@ -430,3 +430,3 @@ var PARSE_PARAMS_REGEXP =

} else if ( ! matchObject) {
matchObject = {};
return ret;
}

@@ -675,2 +675,2 @@

})(this);
})(this);

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

(function(e){function p(e,t){if(!(this instanceof p))return new p(e,t);if(t){this._defaults=t[0],this._paramsMap=t[1],this._parseRegExpSource=t[2],this._buildFnSource=t[3],this._data=t[4],this._buildFn=new Function("p",this._buildFnSource),this._parseRegExp=new RegExp(this._parseRegExpSource);return}typeof e=="string"&&(e={pattern:e});if(!e||typeof e!="object")throw new Error("You must specify options");if(typeof e.pattern!="string")throw new Error("You must specify the pattern of the route");this._pattern=e.pattern,this._conditions=e.conditions&&typeof e.conditions=="object"?e.conditions:{},this._defaults=e.defaults&&typeof e.defaults=="object"?e.defaults:{},this._data=e.data&&typeof e.data=="object"?e.data:{},typeof e.name=="string"&&(this._data.name=e.name),this._pattern+=a+"?"+o+"query_string"+u+f,this._conditions.query_string=".*",this._parts=this._parsePattern(this._pattern),this._buildParseRegExp()._buildBuildFn()}function d(e){if(!(this instanceof d))return new d(e);this._routes=[],this._routesByName={},e&&this.addRoutesFromBundle(e)}var t=Object.prototype.hasOwnProperty,n=Object.prototype.toString,r=function(e){return n.call(e)==="[object Array]"},i={decode:function(e){var t;try{t=decodeURIComponent(e.replace(/\+/g,"%20"))}catch(n){t=e}return t},parse:function(e,t,n){var s={},o,u,a,f,l,c;arguments.length||(e=location.search.substr(1));if(!e)return s;t||(t="&"),n||(n="="),o=e.split(t);for(l=0,c=o.length;l<c;++l)u=o[l].split(n),a=typeof u[1]!="undefined"?i.decode(u[1]):"",f=i.decode(u[0]),s.hasOwnProperty(f)?r(s[f])?s[f].push(a):s[f]=[s[f],a]:s[f]=a;return s},stringify:function(e,n,r){var i="",s,o,u,a,f,l;if(!e)return i;n||(n="&"),r||(r="=");for(l in e)if(t.call(e,l)){u=[].concat(e[l]);for(a=0,f=u.length;a<f;++a)o=typeof u[a],o==="object"||o==="undefined"?s="":s=encodeURIComponent(u[a]),i+=n+encodeURIComponent(l)+r+s}return i.substr(n.length)}},s=function(){var e=["/",".","*","+","?","|","(",")","[","]","{","}","\\"],t=new RegExp("(\\"+e.join("|\\")+")","g");return function(e){return e.replace(t,"\\$1")}}(),o="<",u=">",a="(",f=")",l="[a-zA-Z_][\\w\\-]*",c="[\\w\\-]+",h=new RegExp("("+s(o)+l+s(u)+"|"+"[^"+s(o)+s(u)+"]+"+"|"+s(o)+"|"+s(u)+")","g");p.prototype._parsePattern=function(e){var t=[],n="",r,i=0,s,o,u=0,l=!1,c=e.length;while(i<c){r=e.charAt(i++);if(r===a)l?(++u,n+=r):(this._parseParams(n,t),n="",u=0,l=!0);else if(r===f)if(l)if(u===0){n={what:"optional",dependOnParams:[],parts:this._parsePattern(n)},t.push(n);for(s=0,o=n.parts.length;s<o;++s)n.parts[s]&&n.parts[s].what==="param"&&n.dependOnParams.push(n.parts[s].name);n="",l=!1}else--u,n+=r;else n+=r;else n+=r}return this._parseParams(n,t),t},p.prototype._parseParams=function(e,t){var n=e.match(h),r,i,s;if(n)for(r=0,i=n.length;r<i;++r)s=n[r],s.charAt(0)===o&&s.charAt(s.length-1)===u?t.push({what:"param",name:s.substr(1,s.length-2)}):t.push(s)},p.prototype._buildParseRegExp=function(){return this._paramsMap=[],this._parseRegExpSource="^"+this._buildParseRegExpParts(this._parts)+"$",this._parseRegExp=new RegExp(this._parseRegExpSource),this},p.prototype._buildParseRegExpParts=function(e){var t="",n,r,i;for(n=0,r=e.length;n<r;++n)i=e[n],typeof i=="string"?t+=s(i):i&&i.what==="param"?(this._paramsMap.push(i.name),t+="("+this._buildParamValueRegExpSource(i.name)+")"):i&&i.what==="optional"&&(t+="(?:"+this._buildParseRegExpParts(i.parts)+")?");return t},p.prototype._buildParamValueRegExpSource=function(e){var t,n=this._conditions[e];return n?r(n)?t="(?:"+n.join("|")+")":t=n+"":t=c,t},p.prototype._buildBuildFn=function(){return this._buildFnSource="var h=({}).hasOwnProperty;return "+this._buildBuildFnParts(this._parts)+";",this._buildFn=new Function("p",this._buildFnSource),this},p.prototype._buildBuildFnParts=function(e){var n='""',r,i,o,u,a,f;for(r=0,i=e.length;r<i;++r){a=e[r];if(typeof a=="string")n+='+"'+s(a)+'"';else if(a&&a.what==="param")n+='+(h.call(p,"'+s(a.name)+'")?'+'p["'+s(a.name)+'"]:'+(this._defaults&&t.call(this._defaults,a.name)?'"'+s(this._defaults[a.name])+'"':'""')+")";else if(a&&a.what==="optional"){n+="+((false";for(o=0,u=a.dependOnParams.length;o<u;++o)f=a.dependOnParams[o],n+='||(h.call(p,"'+s(f)+'")'+(this._defaults&&t.call(this._defaults,f)?'&&p["'+s(f)+'"]!=="'+s(this._defaults[f])+'"':"")+")";n+=")?("+this._buildBuildFnParts(a.parts)+'):"")'}}return n},p.prototype.match=function(e){var n=null,r,s,o,u,a;typeof e=="string"?e={path:e}:e||(e={});for(u in e)if(t.call(e,u)&&u!=="path"&&this._data[u]!==e[u])return n;if(typeof e.path=="string"){r=e.path.match(this._parseRegExp);if(r){n={};for(s=1,o=r.length;s<o;++s)typeof r[s]!="undefined"&&r[s]!==""&&(n[this._paramsMap[s-1]]=r[s]);for(u in this._defaults)t.call(this._defaults,u)&&!t.call(n,u)&&(n[u]=this._defaults[u]);a=i.parse(n.query_string);for(u in a)t.call(a,u)&&!t.call(n,u)&&(n[u]=a[u]);delete n.query_string}}else n={};return n},p.prototype.build=function(e){var n={},r={},s,o,u,a,f;for(o in e)if(t.call(e,o)&&e[o]!==null&&typeof e[o]!="undefined"){u=!1;for(a=0,f=this._paramsMap.length;a<f;++a)if(this._paramsMap[a]===o){u=!0;break}u?n[o]=e[o]:r[o]=e[o]}return s=i.stringify(r),s&&(n.query_string=s),this._buildFn(n)},p.prototype.getData=function(){return this._data},p.prototype.getName=function(){return this._data.name},p.prototype.bundle=function(){return[this._defaults,this._paramsMap,this._parseRegExpSource,this._buildFnSource,this._data]},d.prototype.addRoute=function(e,t){var n,r;return n=new p(e,t),this._routes.push(n),r=n.getName(),r&&(this._routesByName[r]=n),n},d.prototype.find=function(e){var t=[],n,r,i,s=this._routes;for(r=0,i=s.length;r<i;++r)n=s[r].match(e),n!==null&&t.push([s[r],n]);return t},d.prototype.findFirst=function(e){var t,n,r,i=this._routes;for(n=0,r=i.length;n<r;++n){t=i[n].match(e);if(t!==null)return[i[n],t]}return null},d.prototype.getRouteByName=function(e){return this._routesByName[e]||null},d.prototype.bundle=function(){var e=[],t,n,r=this._routes;for(t=0,n=r.length;t<n;++t)e.push(r[t].bundle());return e},d.prototype.addRoutesFromBundle=function(e){var t,n;for(t=0,n=e.length;t<n;++t)this.addRoute(null,e[t]);return this},d.Route=p,typeof module!="undefined"&&typeof module.exports=="object"?module.exports=d:e.Susanin=d})(this);
(function(e){function p(e,t){if(!(this instanceof p))return new p(e,t);if(t){this._defaults=t[0],this._paramsMap=t[1],this._parseRegExpSource=t[2],this._buildFnSource=t[3],this._data=t[4],this._buildFn=new Function("p",this._buildFnSource),this._parseRegExp=new RegExp(this._parseRegExpSource);return}typeof e=="string"&&(e={pattern:e});if(!e||typeof e!="object")throw new Error("You must specify options");if(typeof e.pattern!="string")throw new Error("You must specify the pattern of the route");this._pattern=e.pattern,this._conditions=e.conditions&&typeof e.conditions=="object"?e.conditions:{},this._defaults=e.defaults&&typeof e.defaults=="object"?e.defaults:{},this._data=e.data&&typeof e.data=="object"?e.data:{},typeof e.name=="string"&&(this._data.name=e.name),this._pattern+=a+"?"+o+"query_string"+u+f,this._conditions.query_string=".*",this._parts=this._parsePattern(this._pattern),this._buildParseRegExp()._buildBuildFn()}function d(e){if(!(this instanceof d))return new d(e);this._routes=[],this._routesByName={},e&&this.addRoutesFromBundle(e)}var t=Object.prototype.hasOwnProperty,n=Object.prototype.toString,r=function(e){return n.call(e)==="[object Array]"},i={decode:function(e){var t;try{t=decodeURIComponent(e.replace(/\+/g,"%20"))}catch(n){t=e}return t},parse:function(e,t,n){var s={},o,u,a,f,l,c;arguments.length||(e=location.search.substr(1));if(!e)return s;t||(t="&"),n||(n="="),o=e.split(t);for(l=0,c=o.length;l<c;++l)u=o[l].split(n),a=typeof u[1]!="undefined"?i.decode(u[1]):"",f=i.decode(u[0]),s.hasOwnProperty(f)?r(s[f])?s[f].push(a):s[f]=[s[f],a]:s[f]=a;return s},stringify:function(e,n,r){var i="",s,o,u,a,f,l;if(!e)return i;n||(n="&"),r||(r="=");for(l in e)if(t.call(e,l)){u=[].concat(e[l]);for(a=0,f=u.length;a<f;++a)o=typeof u[a],o==="object"||o==="undefined"?s="":s=encodeURIComponent(u[a]),i+=n+encodeURIComponent(l)+r+s}return i.substr(n.length)}},s=function(){var e=["/",".","*","+","?","|","(",")","[","]","{","}","\\"],t=new RegExp("(\\"+e.join("|\\")+")","g");return function(e){return e.replace(t,"\\$1")}}(),o="<",u=">",a="(",f=")",l="[a-zA-Z_][\\w\\-]*",c="[\\w\\-]+",h=new RegExp("("+s(o)+l+s(u)+"|"+"[^"+s(o)+s(u)+"]+"+"|"+s(o)+"|"+s(u)+")","g");p.prototype._parsePattern=function(e){var t=[],n="",r,i=0,s,o,u=0,l=!1,c=e.length;while(i<c){r=e.charAt(i++);if(r===a)l?(++u,n+=r):(this._parseParams(n,t),n="",u=0,l=!0);else if(r===f)if(l)if(u===0){n={what:"optional",dependOnParams:[],parts:this._parsePattern(n)},t.push(n);for(s=0,o=n.parts.length;s<o;++s)n.parts[s]&&n.parts[s].what==="param"&&n.dependOnParams.push(n.parts[s].name);n="",l=!1}else--u,n+=r;else n+=r;else n+=r}return this._parseParams(n,t),t},p.prototype._parseParams=function(e,t){var n=e.match(h),r,i,s;if(n)for(r=0,i=n.length;r<i;++r)s=n[r],s.charAt(0)===o&&s.charAt(s.length-1)===u?t.push({what:"param",name:s.substr(1,s.length-2)}):t.push(s)},p.prototype._buildParseRegExp=function(){return this._paramsMap=[],this._parseRegExpSource="^"+this._buildParseRegExpParts(this._parts)+"$",this._parseRegExp=new RegExp(this._parseRegExpSource),this},p.prototype._buildParseRegExpParts=function(e){var t="",n,r,i;for(n=0,r=e.length;n<r;++n)i=e[n],typeof i=="string"?t+=s(i):i&&i.what==="param"?(this._paramsMap.push(i.name),t+="("+this._buildParamValueRegExpSource(i.name)+")"):i&&i.what==="optional"&&(t+="(?:"+this._buildParseRegExpParts(i.parts)+")?");return t},p.prototype._buildParamValueRegExpSource=function(e){var t,n=this._conditions[e];return n?r(n)?t="(?:"+n.join("|")+")":t=n+"":t=c,t},p.prototype._buildBuildFn=function(){return this._buildFnSource="var h=({}).hasOwnProperty;return "+this._buildBuildFnParts(this._parts)+";",this._buildFn=new Function("p",this._buildFnSource),this},p.prototype._buildBuildFnParts=function(e){var n='""',r,i,o,u,a,f;for(r=0,i=e.length;r<i;++r){a=e[r];if(typeof a=="string")n+='+"'+s(a)+'"';else if(a&&a.what==="param")n+='+(h.call(p,"'+s(a.name)+'")?'+'p["'+s(a.name)+'"]:'+(this._defaults&&t.call(this._defaults,a.name)?'"'+s(this._defaults[a.name])+'"':'""')+")";else if(a&&a.what==="optional"){n+="+((false";for(o=0,u=a.dependOnParams.length;o<u;++o)f=a.dependOnParams[o],n+='||(h.call(p,"'+s(f)+'")'+(this._defaults&&t.call(this._defaults,f)?'&&p["'+s(f)+'"]!=="'+s(this._defaults[f])+'"':"")+")";n+=")?("+this._buildBuildFnParts(a.parts)+'):"")'}}return n},p.prototype.match=function(e){var n=null,r,s,o,u,a;if(typeof e=="string")e={path:e};else if(!e)return n;for(u in e)if(t.call(e,u)&&u!=="path"&&this._data[u]!==e[u])return n;if(typeof e.path=="string"){r=e.path.match(this._parseRegExp);if(r){n={};for(s=1,o=r.length;s<o;++s)typeof r[s]!="undefined"&&r[s]!==""&&(n[this._paramsMap[s-1]]=r[s]);for(u in this._defaults)t.call(this._defaults,u)&&!t.call(n,u)&&(n[u]=this._defaults[u]);a=i.parse(n.query_string);for(u in a)t.call(a,u)&&!t.call(n,u)&&(n[u]=a[u]);delete n.query_string}}else n={};return n},p.prototype.build=function(e){var n={},r={},s,o,u,a,f;for(o in e)if(t.call(e,o)&&e[o]!==null&&typeof e[o]!="undefined"){u=!1;for(a=0,f=this._paramsMap.length;a<f;++a)if(this._paramsMap[a]===o){u=!0;break}u?n[o]=e[o]:r[o]=e[o]}return s=i.stringify(r),s&&(n.query_string=s),this._buildFn(n)},p.prototype.getData=function(){return this._data},p.prototype.getName=function(){return this._data.name},p.prototype.bundle=function(){return[this._defaults,this._paramsMap,this._parseRegExpSource,this._buildFnSource,this._data]},d.prototype.addRoute=function(e,t){var n,r;return n=new p(e,t),this._routes.push(n),r=n.getName(),r&&(this._routesByName[r]=n),n},d.prototype.find=function(e){var t=[],n,r,i,s=this._routes;for(r=0,i=s.length;r<i;++r)n=s[r].match(e),n!==null&&t.push([s[r],n]);return t},d.prototype.findFirst=function(e){var t,n,r,i=this._routes;for(n=0,r=i.length;n<r;++n){t=i[n].match(e);if(t!==null)return[i[n],t]}return null},d.prototype.getRouteByName=function(e){return this._routesByName[e]||null},d.prototype.bundle=function(){var e=[],t,n,r=this._routes;for(t=0,n=r.length;t<n;++t)e.push(r[t].bundle());return e},d.prototype.addRoutesFromBundle=function(e){var t,n;for(t=0,n=e.length;t<n;++t)this.addRoute(null,e[t]);return this},d.Route=p,typeof module!="undefined"&&typeof module.exports=="object"?module.exports=d:e.Susanin=d})(this);

@@ -6,7 +6,14 @@ var Susanin = require('../../'),

'undefined' : function(test, undefined) {
var route = Route('/opa');
test.deepEqual(route.match(undefined), null);
test.done();
},
'/opa' : function(test) {
var route = Route('/opa')
;
var route = Route('/opa');
test.deepEqual(route.match('/opapa'), null);
test.deepEqual(route.match('/opapa'), null);
test.deepEqual(route.match('/opa'), {});

@@ -210,2 +217,2 @@ test.deepEqual(route.match('/opa?foo'), { foo : '' });

};
};

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