node.js fast-router
A fast & simple O(log n) URL router for node.js that can be used for almost anything.
Runtime: O(log n), where n is the total number of routes. The runtime is O(n) if you consider n the length of your longest route.
Usage:
//Require the module...var Router = Router;//Create a new routervar router = ;
That's all. Now you can begin to add routes:
router;router; //Keys are used and indicated by ':' . They will capture that part in the URL.router; //A wildcard is indicated by a '*' and will capture the rest of the URLrouter; //Exact matches always take precendence over wildcards and paths with keys
To match some URL against the route tree:
var result = router;var result = router;var result = router;
Result
A result is a javascript object with the following properties:
url: <url> //contains the URL as parsed with node.js's built-in url.parse(_url, true) value: <value> //The value that was supplied when the route was inserted. You could use //a function for it to emulate the behavior of some other routers. parts: ... //The parts of the URL as the result of url.pathname.split('/') keys: key: value ... //The keys used in the URL with their respective values, //for the first example this would be {user: "tim", thing: "lamp"} extra: "<etc>/<etc>/<etc>..." //The text matched by the wildcard if the route contained one