Created
February 21, 2012 20:33
-
-
Save malko/1878729 to your computer and use it in GitHub Desktop.
string placeholder replacement function
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
printReplace=function(str,vars){ | |
if( typeof vars !== 'object' ){ | |
return str; | |
} | |
return str.replace(/(%+)([a-z0-9_-]+)/g,function(m,p,k){ | |
if( p.length === 1 && typeof vars[k] !== 'undefined'){ | |
return vars[k] || ''; | |
} | |
return m; | |
}); | |
} | |
String.prototype.printReplace = function(vars){ return printReplace(this,vars); }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment