Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const user = {
- id: 20,
- name: "John Dow",
- role: "QA",
- salary: 100
- }
- const apiTemplatesSet1 = [
- "/api/items/%id%/%name%",
- "/api/items/%id%/%role%",
- "/api/items/%id%/%salary%"
- ];
- const apiPathes = apiTemplatesSet1.map(apiPathTemplate => {
- return getApiPath(user, apiPathTemplate);
- });
- function getApiPath(obj, template) {
- let result = template
- template.match(/%(.*?)%/g).map(function(val){
- let currValue = val.replace(/%/g, '');
- result = result.replace(val, obj[currValue])
- });
- return result;
- }
- console.log(encodeURI(apiPathes));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement