Skip to content

Instantly share code, notes, and snippets.

@eerne
Forked from ibolmo/String.substitute.js
Created July 19, 2011 15:38
Show Gist options
  • Save eerne/1092813 to your computer and use it in GitHub Desktop.
Save eerne/1092813 to your computer and use it in GitHub Desktop.
Add support for paths in String.substitute
/*
---
...
*/
String.implement({
substitute: function(object, regexp){
return this.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
if (match.charAt(0) == '\\') return match.slice(1);
return Object.getFromPath(object, name) || '';
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment