JSFiddle - React, Tailwind, and code Playground
JavaScript
function Prop(obj,is,value) {
if (typeof is == 'string')
is=is.split('.');
if (is.length==1 && value!==undefined)
return obj[is[0]] = value;
else if (is.length==0)
return obj;
else{
var prop=is.shift();
//Forge a path of nested objects if there is a value to set
if(value!==undefined&&obj[prop]==undefined)obj[prop]={}
return Prop(obj[prop],is, value);
}
}
function render(str,obj){
return str.replace(/\$\{(.+?)\}/g,(match,p1)=>{return Prop(obj,p1)})
}
console.log(render('abc${a}asdas',{a:23,b:44})) //abc23asdas
console.log(render('abc${a.c}asdas',{a:{c:22,d:55},b:44})) //abc22asdas