Hacker News new | past | comments | ask | show | jobs | submit login

I've been doing something very similar for templating static HTML sites amongst other things - you can interpret any string as a JS template string:

    function jstsEngine(string = '', environment = {}) {
      return new Function(
        ...Object.keys(environment),
        'output={}',
        'return [`' + string + '`, output]'
      )(...Object.values(environment))
    }
Link with examples: https://github.com/tomhodgins/jsts-engine



That's what I'm using it for as well! I believe our functions here are isomorphic, though I'm a couple lines shorter ;)

You've got an excellent username btw. <3


<3 you have a nice username too :D




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: