Last active
August 29, 2015 14:02
-
-
Save asika32764/3a135d47fe39676a7b43 to your computer and use it in GitHub Desktop.
If we use `parseVariable('Hi {{name}}~~~', {name: Simon})`, this function will return `Hi Simon~~~`.
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
/** | |
* Parse variable {{name}}. | |
* | |
* Example: If we use `parseVariable('Hi {{name}}~~~', {name: 'Simon'})`, this function will return `Hi Simon~~~`. | |
* | |
* @param {string} string | |
* @param {Object} data | |
* | |
* @returns {string} | |
*/ | |
parseVariable: function(string, data) | |
{ | |
string = string.replace(/\{\{\s*(.+?)\s*\}\}/gm, function(match, contents, offset, s) | |
{ | |
return data[contents]; | |
}); | |
return string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment