@threebow/axis
Advanced tools
Comparing version 1.1.6 to 1.1.7
@@ -80,2 +80,3 @@ const express = require("express"), | ||
//Creating a route helper function | ||
router.use((req, res, next) => { | ||
@@ -89,2 +90,15 @@ let routeFn = (...args) => self.getNamedRoutePath(...args); | ||
}); | ||
//Dumping the route names into the request's locals | ||
router.use((req, res, next) => { | ||
if(self.routeNameCache.size < 1) { | ||
self.buildRouteNameCache(); | ||
} | ||
let obj = {}; | ||
self.routeNameCache.forEach((v, k) => obj[k] = v); | ||
res.locals.routeNameCache = obj; | ||
next(); | ||
}); | ||
} | ||
@@ -91,0 +105,0 @@ |
{ | ||
"name": "@threebow/axis", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"description": "An expressive web framework for node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
12
util.js
@@ -0,1 +1,3 @@ | ||
const pathToRegexp = require("path-to-regexp"); | ||
/*--------------------------------------------------------------------------- | ||
@@ -6,2 +8,12 @@ Make sure our route names always start with a slash internally | ||
return str.startsWith("/") ? str : "/" + str; | ||
}; | ||
module.exports.ResolveRoute = (name, params) => { | ||
//Return the plain path if there are no arguments | ||
let path = RouteList[name]; | ||
if(!params) return path; | ||
//Compile the path with the given parameters if they are given | ||
let compiled = pathToRegexp.compile(path); | ||
return compiled(params); | ||
}; |
17570
425