Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Susanin is a routing library which can be used in any JavaScript environments.
susanin.js
- uncompressed source code with commentssusanin.min.js
- compressed codeIn the browsers just include the file in your document:
<script src="/path/to/susanin.min.js"></script>
You can install Susanin on Node.js using NPM:
npm install susanin
var route = Susanin.Route('/products');
console.log(route.match('/produc')); // => null
console.log(route.match('/products')); // => {}
var route = Susanin.Route('/products/<id>');
console.log(route.match('/products')); // => null
console.log(route.match('/products/321')); // => { id : '321' }
console.log(route.match('/products/321?id=123')); // => { id : '321' }
var route = Susanin.Route('/products');
console.log(route.match('/products?id=321&category=shoes&category=new'));
// => { id : '321', category : [ 'shoes', 'new' ] }
var route = Susanin.Route('/products(/<id>)'));
console.log(route.match('/products')); // => {}
console.log(route.match('/products/321')); // => { id : '321' }
var route = Susanin.Route({
pattern : '/products(/<id>)',
defaults : {
id : '123'
}
});
console.log(route.match('/products')); // => { id : '123' }
console.log(route.match('/products/321')); // => { id : '321' }
var route = Susanin.Route({
pattern : '/products(/<id>)',
defaults : {
id : '123'
},
conditions : {
id : '\\d{3,4}'
}
});
console.log(route.match('/products')); // => { id : '123' }
console.log(route.match('/products/321')); // => { id : '321' }
console.log(route.match('/products/a321')); // => null
console.log(route.match('/products/32')); // => null
var route = Susanin.Route({
pattern : '/products(/<category>(/<id>))(/)',
defaults : {
category : 'shoes',
id : '123'
},
conditions : {
category : [ 'shoes', 'jeans', 'shirt' ],
id : '\\d{3,4}'
}
});
console.log(route.match('/prod')); // => null
console.log(route.match('/products')); // => { category : 'shoes', id : '123' }
console.log(route.match('/products/')); // => { category : 'shoes', id : '123' }
console.log(route.match('/products/jeans')); // => { category : 'jeans', id : '123' }
console.log(route.match('/products/skirt')); // => null
console.log(route.match('/products/shirt/321')); // => { category : 'shirt', id : '321' }
console.log(route.match('/products/shirt/32')); // => null
console.log(route.match('/products/shoes/')); // => { category : 'shoes', id : '123' }
var route = Susanin.Route({
pattern : '/products/<category>',
data : {
method : 'GET',
controller : 'products'
}
});
console.log(route.getData()); // => { method : 'GET', controller : 'products' }
console.log(route.match({ method : 'POST' }); // => null
console.log(route.match({ method : 'GET' }); // => {}
console.log(route.match({
path : '/products/shoes',
method : 'GET'
}); // => { category : 'shoes' }
var susanin = Susanin();
susanin.addRoute('/contacts');
susanin.addRoute('/products/<category>');
susanin.addRoute({
pattern : '/(<controller>(/<action>(/<id>)))',
defaults : {
controller : 'index',
action : 'build'
}
});
console.log(susanin.findFirst('/')); // => [ #route, { controller : 'index', action : 'build' } ]
console.log(susanin.findFirst('/products')); // => [ #route, { controller : 'products', action : 'build' } ]
console.log(susanin.findFirst('/products/shoes')); // => [ #route, { category : 'shoes' } ]
var route = Susanin.Route({
pattern : '/products(/cat_<category>)(/)',
defaults : { category : 'shoes' }
});
console.log(route.build()); // => '/products'
console.log(route.build({ category : 'jeans' })); // => '/products/cat_jeans'
console.log(route.build({ category : 'shoes' })); // => '/products'
FAQs
Router system which can be used in any JavaScript environments
The npm package susanin receives a total of 570 weekly downloads. As such, susanin popularity was classified as not popular.
We found that susanin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.