Comparing version 0.3.0 to 1.0.0
{ | ||
"author" : "Ruslan Kerimov <rus.kerimov@gmail.com>", | ||
"name" : "susanin", | ||
"version" : "0.3.0", | ||
"version" : "1.0.0", | ||
"author" : { | ||
"name" : "Ruslan Kerimov", | ||
"email" : "rus.kerimov@gmail.com" | ||
}, | ||
"description" : "Router system which can be used in any JavaScript environments", | ||
"keywords" : [ "router", "routes", "routing" ], | ||
"repository" : { | ||
"type" : "git", | ||
"url" : "git://github.com/ruslankerimov/susanin.git" | ||
"url" : "git://github.com/nodules/susanin.git" | ||
}, | ||
@@ -14,12 +19,20 @@ "scripts" : { | ||
"devDependencies" : { | ||
"jshint" : "", | ||
"uglify-js" : "1.3.4", | ||
"nodeunit" : "", | ||
"istanbul" : "" | ||
"jshint" : "2.1.10", | ||
"jscs" : "1.0.5", | ||
"istanbul" : "0.1.x", | ||
"mocha" : "1.11.x", | ||
"chai" : "1.7.x", | ||
"borschik" : "0.3.x", | ||
"karma" : "~0.12.24", | ||
"karma-chrome-launcher" : "~0.1.5", | ||
"karma-firefox-launcher" : "~0.1.3", | ||
"karma-phantomjs-launcher" : "~0.1.4", | ||
"karma-mocha" : "~0.1.9" | ||
}, | ||
"optionalDependencies" : {}, | ||
"main" : "susanin", | ||
"engines" : { | ||
"node" : "*" | ||
} | ||
"main" : "lib/router.js", | ||
"bugs" : { | ||
"url" : "https://github.com/nodules/susanin/issues" | ||
}, | ||
"license" : "MIT" | ||
} |
173
README.md
@@ -1,1 +0,172 @@ | ||
[![Build Status](https://secure.travis-ci.org/ruslankerimov/susanin.png)](http://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 | ||
* `susanin.js` - uncompressed source code with comments | ||
* `susanin.min.js` - compressed code | ||
In the browsers just include the file in your document: | ||
```html | ||
<script src="/path/to/susanin.min.js"></script> | ||
``` | ||
You can install Susanin on Node.js using [NPM](http://npmjs.org): | ||
``` | ||
npm install susanin | ||
``` | ||
## Examples | ||
* The simplest: | ||
```javascript | ||
var route = Susanin.Route('/products'); | ||
console.log(route.match('/produc')); // => null | ||
console.log(route.match('/products')); // => {} | ||
``` | ||
* More complex, with a param in pattern: | ||
```javascript | ||
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' } | ||
``` | ||
* With query params in path: | ||
```javascript | ||
var route = Susanin.Route('/products'); | ||
console.log(route.match('/products?id=321&category=shoes&category=new')); | ||
// => { id : '321', category : [ 'shoes', 'new' ] } | ||
``` | ||
* With an optional group: | ||
```javascript | ||
var route = Susanin.Route('/products(/<id>)')); | ||
console.log(route.match('/products')); // => {} | ||
console.log(route.match('/products/321')); // => { id : '321' } | ||
``` | ||
* With a default value of param: | ||
```javascript | ||
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' } | ||
``` | ||
* If you want to specify a regexp for param: | ||
```javascript | ||
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 | ||
``` | ||
* The most complex: | ||
```javascript | ||
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' } | ||
``` | ||
* You can bind any data with a route and match on these: | ||
```javascript | ||
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' } | ||
``` | ||
* Set of routes: | ||
```javascript | ||
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' } ] | ||
``` | ||
* Susanin can build a path: | ||
```javascript | ||
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' | ||
``` | ||
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
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
109517
35
2447
1
1
173
11
3