Skip to content

Instantly share code, notes, and snippets.

@choonkeat
Created May 5, 2010 06:26
Show Gist options
  • Select an option

  • Save choonkeat/390453 to your computer and use it in GitHub Desktop.

Select an option

Save choonkeat/390453 to your computer and use it in GitHub Desktop.
// modified from http://javascript.crockford.com/remedial.html
String.prototype.safe_supplant = function (o) {
return this.replace(/{([^{}]*)}/g, function (a, b) {
var r = o[b];
if (typeof r === 'string') {
return r.replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
} else {
return (typeof r === 'number') ? r : a;
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment