I have a function which receives an object and a string. How can I nicely put values from an object into a string
const str = "/api/items/%id%/%name%";
let obj = { id : 20, name: 'John Dow'};
function path(obj, str){
let res = //some code
return res
}
the function should return "/api/items/20/John%20Dow"
does not come up with a good solution. help me please