Skip to content

Instantly share code, notes, and snippets.

@eugene-eeo
Last active August 9, 2016 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eugene-eeo/c6b2e27814998e466d035dff69ae88bb to your computer and use it in GitHub Desktop.
Save eugene-eeo/c6b2e27814998e466d035dff69ae88bb to your computer and use it in GitHub Desktop.
micro templating
/*
* lo and behold, in all its glory:
*/
var t = (s,d) => s.replace(/{(.+?)}/, (_,k) => k.split('.').reduce((o,g) => o[g], d))
t('{name}', {name: 'me'})
// => 'me'
t('@{user.name}', {user: {name: 'me'}})
// => '@me'
t('{0}', [1])
// => 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment