-
-
Save eugene-eeo/c6b2e27814998e466d035dff69ae88bb to your computer and use it in GitHub Desktop.
micro templating
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
/* | |
* 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