function expandRewrittenRoutes(routes) {
	const nestedResourceRegex = /^\/(\w+)\/:(\w+)\/(\w+)$/;
	const optionalQueryParamsString = "(\\?[\\w\\W]+)?";

	var expandedRoutes = {};
	var keysToDelete = [];

	Object.keys(routes).forEach(function (key) {
		if (key.match(nestedResourceRegex)) {
			let expandedKey = key + optionalQueryParamsString;
			expandedRoutes[expandedKey] = routes[key]; // add new key with the expanded route
			keysToDelete.push(key); // keep the original route that was expanded to delete it afterwards
		}
	});

	if (keysToDelete.length) {
		// deleting routes that were expanded
		keysToDelete.forEach(function (key) {
			delete routes[key];
		});

		// merging expandedRoutes into routes object
		Object.assign(routes, expandedRoutes);
	}

	return routes;
}
/**
 * Add to the original routes for nested resources (those that will be rewritten with a '_expand' query parameter)
 * with an optional query param regex so that the route can match regardless of whether it has or not query params
 * @param routes : Routes to be rewritten (in order to support nested resources)
 */
Add to the original routes for nested resources (those that will be rewritten with a '_expand' query parameter)
with an optional query param regex so that the route can match regardless of whether it has or not query params
@param routes : Routes to be rewritten (in order to support nested resources)
Add to the original routes for nested resources ( those that will be rewritten with a ' _expand ' query parameter ) with an optional query param regex so that the route can match regardless of whether it has or not query params @param routes : Routes to be rewritten ( in order to support nested resources )
function expandRewrittenRoutes(routes) {
	const nestedResourceRegex = /^\/(\w+)\/:(\w+)\/(\w+)$/;
	const optionalQueryParamsString = "(\\?[\\w\\W]+)?";
	var expandedRoutes = {};
	var keysToDelete = [];
	Object.keys(routes).forEach(function (key) {
		if (key.match(nestedResourceRegex)) {
			let expandedKey = key + optionalQueryParamsString;
			expandedRoutes[expandedKey] = routes[key]; 
			keysToDelete.push(key); 
		}
	});
	if (keysToDelete.length) {
		keysToDelete.forEach(function (key) {
			delete routes[key];
		});
		Object.assign(routes, expandedRoutes);
	}
	return routes;
}
function expandRewrittenRoutes ( routes ) { const nestedResourceRegex = / ^\/(\w+)\/:(\w+)\/(\w+)$ / ; const optionalQueryParamsString = "(\\?[\\w\\W]+)?" ; var expandedRoutes = { } ; var keysToDelete = [ ] ; Object . keys ( routes ) . forEach ( function ( key ) { if ( key . match ( nestedResourceRegex ) ) { let expandedKey = key + optionalQueryParamsString ; expandedRoutes [ expandedKey ] = routes [ key ] ; keysToDelete . push ( key ) ; } } ) ; if ( keysToDelete . length ) { keysToDelete . forEach ( function ( key ) { delete routes [ key ] ; } ) ; Object . assign ( routes , expandedRoutes ) ; } return routes ; }
Add to the original routes for nested resources (those that will be rewritten with a '_expand' query parameter)
 with an optional query param regex so that the route can match regardless of whether it has or not query params
 @param routes : Routes to be rewritten (in order to support nested resources)
Add to the original routes for nested resources ( those that will be rewritten with a ' _expand ' query parameter ) with an optional query param regex so that the route can match regardless of whether it has or not query params @param routes : Routes to be rewritten ( in order to support nested resources )
// add new key with the expanded route // keep the original route that was expanded to delete it afterwards // deleting routes that were expanded // merging expandedRoutes into routes object