Skip to content

Instantly share code, notes, and snippets.

@sebmarkbage
Created December 12, 2010 23:36
Show Gist options
  • Select an option

  • Save sebmarkbage/738466 to your computer and use it in GitHub Desktop.

Select an option

Save sebmarkbage/738466 to your computer and use it in GitHub Desktop.
String.implement({
substitute: function(object, regexp){
return this.replace(regexp || (/\\?\{([^{}:]+)(?::([^{}:]+))?\}/g), function(match, name, format){
if (match.charAt(0) == '\\') return match.slice(1);
var value = (object[name] != null) ? object[name] : '';
if (format && typeof value.format == 'function') value = value.format(format);
return value;
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment