Last active
April 5, 2017 18:02
-
-
Save fakenickels/882441328b95dfb3a125b2355eb3776c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function simpleTemplate(string, object){ | |
return string.replace(/({[^{]+})/g, (group) => object[group.replace(/[{}]/g, '')]) | |
} | |
simpleTemplate('Something something: {foo} => {bar}', { foo: 'Thing 1', bar: 'Thing 2' }) | |
// => 'Something something: Thing 1 => Thing 2' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment