Created
April 19, 2016 07:57
-
-
Save designeng/7e6ca9a91a2caf1f481a073adf5162f1 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
/** | |
* Map object keys in string to its values | |
* | |
* @param {String} text | |
* @param {Object} data | |
* @return {String} | |
*/ | |
template: function (text, data) { | |
return !text ? '' : text.replace(/\{([^\}]+)\}/g, function (value, key) { | |
return key in data ? data[key] : value; | |
}); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: