JSFiddle - React, Tailwind, and code Playground

by jiggle

HTML

<script>
    function sub(str, data) {
    //console.log(str);
   return str.replace(/\{([^\}]+?)\}/g, function(match, key) {
    //console.log(match);
    // console.log(key);
    console.log(typeof data[key] === 'function');
    console.log((key in data) ? (typeof data[key] === 'function' ? data[key](key, str) : data[key]) : match);
    return (key in data) ? (typeof data[key] === 'function' ? data[key](key, str) : data[key]) : match;
  
   });
  
  }
  
  
  
  var obj = {
   url: 'http://www.yahoo.com',
   subject: 'The subject, what else',
   content: 'The content, should takes about 100 characters? Not sure, hot this string is representative. OK?',
   date: '2011/04/26',
   time: '3:30PM',
   fred: function(k, s){
    console.log('fred function');
    console.log(k);
    console.log(s);
    return 'george';
    }
  };

    function runTest(){
    // console.log($("#txtText").val());
        var result=sub($("#txtText").val(),obj);
    
        $("#Result").html(result);
    }
    
    function clear(){
        console.log('clear');
        $("#Results").html("<br>");
    }
</script>

<body>

<div id="Result">test</div>
<textarea rows="4" cols="50" id="txtText">
    <div><a class="title" target="_blank" href="{url}">{subject}</a><div class="desc">{content}</div><span>{date}:{time}{fred}</span></div>
</textarea>
<input type="button" value="Run" onclick="runTest()"/>
    
<input type="button" value="Clear" onclick="clear()"/>
    
</body>

JavaScript

$(function() {    
  
    
    
});