Created
June 6, 2016 10:46
-
-
Save suside/9a053cf63f6f02df3316009d9831fcf7 to your computer and use it in GitHub Desktop.
One line RamdaJS template 'engine'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const R = require('ramda'); | |
const _ = R.curry((tpl, data) => R.reduce((ac, k) => R.replace(`{{${k}}}`, data[k], ac), tpl, R.keys(data))); | |
_('Hello {{var}}', {var: 'world'}); // => Hello world | |
const compiled = _('{{var1}} {{var2}}'); | |
compiled({var1: 'Hello', var2: 'world'}); // => Hello world |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment