JSFiddle - React, Tailwind, and code Playground
by userdude
JavaScript
if (typeof String.prototype.supplant !== 'function') {
String.prototype.supplant = function (o) {
console.log(o);
return this.replace(/{([^{}]*)}/g, function (a, b) {
var r = o[b];
console.log(a, ' - ', b, ' - ', r);
return typeof r === 'string' ? r : a;
});
};
}
window.onload = function(){
var html = '<div>{title}<h3>{time}</h3><p>{content}</p></div>',
obj = {
title: "my title",
time: "12h00m",
content:"blablabla"
},
supplanted = html.supplant(obj);
document.body.innerHTML = supplanted;
};