Skip to content

Instantly share code, notes, and snippets.

@ourmaninamsterdam
Created April 5, 2013 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ourmaninamsterdam/5319295 to your computer and use it in GitHub Desktop.
Save ourmaninamsterdam/5319295 to your computer and use it in GitHub Desktop.
Dustin Diaz object string supplanter
function substitute(s, o){
return s.replace( /{([^{}]*)}/g ,
function (a, b) {
var r = o[b];
return typeof r === 'string' || typeof r === 'number' ? r : a;
}
);
}
substitute("My name is {name} and I work at {workplace}",{
name: "Justin Perry",
workplace: "I || X"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment