Comparing version 1.3.0 to 1.4.0
{ | ||
"name": "anumargak", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Amazing fast multipurpose web/ HTTP router", | ||
@@ -5,0 +5,0 @@ "main": "./src/letsRoute.js", |
@@ -9,3 +9,2 @@ # anumargak (अनुमार्गक) | ||
[](https://coveralls.io/github/NaturalIntelligence/anumargak?branch=master) | ||
[](https://www.bithound.io/github/NaturalIntelligence/anumargak/master/dependencies/npm) | ||
[](https://www.bithound.io/github/NaturalIntelligence/anumargak) | ||
@@ -35,2 +34,4 @@ [](https://npm.im/anumargak) | ||
* `\this\is\:age([0-9]+)` and `\this\is\:name([a-zA-Z]+)` | ||
* Support of shorthand methods | ||
* You can always have a count on registered routes | ||
@@ -45,2 +46,3 @@ ## Usage | ||
}); | ||
anumargak.on("GET", "/this/is/static", handler); | ||
@@ -101,2 +103,14 @@ anumargak.on(["POST","PUT"], "/this/is/static", handler);//supports array | ||
**shorthand methods** | ||
```js | ||
var router = Anumargak(); | ||
router.get("/this/is/:dynamic", () => 30); | ||
router.head("/this/is/:dynamic", () => 30); | ||
router.post("/this/is/:dynamic", () => 30); | ||
router.put("/this/is/:dynamic", () => 30); | ||
router.delete("/this/is/:dynamic", () => 30); | ||
``` | ||
## Similar but not same URLs | ||
@@ -139,2 +153,2 @@ | ||
- [Grapes](https://github.com/amitguptagwl/grapes) : Flexible Regular expression engine (for java) which can be applied on char stream. (under development) | ||
- [Muneem (मुनीम)](https://github.com/muneem4node/muneem): A framework to write fast web services in easy way. Designed specially for developers, QAs, Maintainers, and BAs. | ||
- [Muneem (मुनीम)](https://github.com/muneem4node/muneem): A framework to write fast web services in easy way. Designed specially for developers, QAs, Maintainers, and BAs. |
@@ -207,2 +207,43 @@ | ||
/** | ||
* Adds routes for GET method and URL | ||
* @param {string} url | ||
* @param {function} fn | ||
*/ | ||
Anumargak.prototype.get = function(url,fn){ | ||
this.on("GET",url,fn); | ||
} | ||
/** | ||
* Adds routes for HEAD method and URL | ||
* @param {string} url | ||
* @param {function} fn | ||
*/ | ||
Anumargak.prototype.head = function(url,fn){ | ||
this.on("HEAD",url,fn); | ||
} | ||
/** | ||
* Adds routes for PUT method and URL | ||
* @param {string} url | ||
* @param {function} fn | ||
*/ | ||
Anumargak.prototype.put = function(url,fn){ | ||
this.on("PUT",url,fn); | ||
} | ||
/** | ||
* Adds routes for POST method and URL | ||
* @param {string} url | ||
* @param {function} fn | ||
*/ | ||
Anumargak.prototype.post = function(url,fn){ | ||
this.on("POST",url,fn); | ||
} | ||
/** | ||
* Adds routes for DELETE method and URL | ||
* @param {string} url | ||
* @param {function} fn | ||
*/ | ||
Anumargak.prototype.delete = function(url,fn){ | ||
this.on("DELETE",url,fn); | ||
} | ||
function Anumargak(options){ | ||
@@ -209,0 +250,0 @@ if(!(this instanceof Anumargak )) return new Anumargak(options); |
@@ -23,3 +23,3 @@ const RandExp = require('randexp'); | ||
}else{ | ||
return exports.doesMatch(a,bRand) && exports.doesMatch(aRand,b); | ||
return exports.doesMatch(a,bRand) || exports.doesMatch(aRand,b); | ||
} | ||
@@ -26,0 +26,0 @@ |
@@ -325,3 +325,47 @@ var Anumargak = require("./../src/letsRoute"); | ||
}); | ||
it("should register static routes for 'GET, POST, DELETE, PUT, HEAD' methods", function(){ | ||
var anumargak = Anumargak(); | ||
anumargak.get("/this/is/static", () => 50); | ||
anumargak.post("/this/is/static", () => 50); | ||
anumargak.delete("/this/is/static", () => 50); | ||
anumargak.put("/this/is/static", () => 50); | ||
anumargak.head("/this/is/static", () => 50); | ||
expect(Object.keys(anumargak.staticRoutes.GET).length).toEqual(1); | ||
expect(Object.keys(anumargak.staticRoutes.POST).length).toEqual(1); | ||
expect(Object.keys(anumargak.staticRoutes.DELETE).length).toEqual(1); | ||
expect(Object.keys(anumargak.staticRoutes.PUT).length).toEqual(1); | ||
expect(Object.keys(anumargak.staticRoutes.HEAD).length).toEqual(1); | ||
expect(anumargak.count).toEqual(5); | ||
expect(anumargak.find("GET","/this/is/static")()).toEqual(50); | ||
expect(anumargak.find("POST","/this/is/static")()).toEqual(50); | ||
expect(anumargak.find("DELETE","/this/is/static")()).toEqual(50); | ||
expect(anumargak.find("PUT","/this/is/static")()).toEqual(50); | ||
expect(anumargak.find("HEAD","/this/is/static")()).toEqual(50); | ||
}); | ||
it("should register dynamic routes for 'GET, POST, DELETE, PUT, HEAD' methods", function() { | ||
var anumargak = Anumargak(); | ||
anumargak.get("/this/is/:dynamic", () => 30); | ||
anumargak.head("/this/is/:dynamic", () => 30); | ||
anumargak.post("/this/is/:dynamic", () => 30); | ||
anumargak.put("/this/is/:dynamic", () => 30); | ||
anumargak.delete("/this/is/:dynamic", () => 30); | ||
expect(Object.keys(anumargak.dynamicRoutes.GET).length).toEqual(1); | ||
expect(Object.keys(anumargak.dynamicRoutes.HEAD).length).toEqual(1); | ||
expect(Object.keys(anumargak.dynamicRoutes.POST).length).toEqual(1); | ||
expect(Object.keys(anumargak.dynamicRoutes.PUT).length).toEqual(1); | ||
expect(Object.keys(anumargak.dynamicRoutes.DELETE).length).toEqual(1); | ||
expect(anumargak.count).toEqual(5); | ||
expect(anumargak.find("GET","/this/is/dynamic")()).toEqual(30); | ||
expect(anumargak.find("HEAD","/this/is/dynamic")()).toEqual(30); | ||
expect(anumargak.find("POST","/this/is/dynamic")()).toEqual(30); | ||
expect(anumargak.find("PUT","/this/is/dynamic")()).toEqual(30); | ||
expect(anumargak.find("DELETE","/this/is/dynamic")()).toEqual(30); | ||
}); | ||
/* const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); | ||
@@ -328,0 +372,0 @@ |
const RandExp = require('randexp'); | ||
RandExp.prototype.randInt = (a,b) => { | ||
if(b>a) b =1; | ||
return a+b; | ||
/* if(b>a) b =1; | ||
return a+b; */ | ||
return a; | ||
} | ||
@@ -40,2 +41,6 @@ | ||
console.log(new RandExp(/b/).gen());//a | ||
console.log(new RandExp(/a/).gen());//0000 | ||
console.log(new RandExp(/\/this\/is\/[^\\/]+\/dynamic/).gen());//0000 | ||
@@ -42,0 +47,0 @@ |
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
1165
150
71979