You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
willaengine/resources/js/Global/services/url.service.js

26 lines
892 B

const urlGenerator = (urls) => {
return function(routeAddress, parameters) {
let urlPath = urls[routeAddress].split("/");
let newPath = [];
for (const iterator of urlPath) {
if (iterator.startsWith(":")) {
if (iterator.endsWith("?")) {
if (parameters.hasOwnProperty(iterator.slice(1, -1))) {
newPath.push(parameters[iterator.slice(1, -1)]);
}
} else {
console.assert(parameters.hasOwnProperty(iterator.slice(1)), 'parameter "' + iterator.slice(1) + '" not specified in parameters.')
newPath.push(parameters[iterator.slice(1)]);
}
} else {
newPath.push(iterator);
}
}
return '/api/v1/' + newPath.join("/");
}
};
export {
urlGenerator
}