Skip to content

Instantly share code, notes, and snippets.

@mpenet
Created March 29, 2011 13:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpenet/892394 to your computer and use it in GitHub Desktop.
Save mpenet/892394 to your computer and use it in GitHub Desktop.
jQuery.format = function(s, args) {
return s.replace(/\{([^}]+)\}/g, function(_, match){return args[match] || '';});
};
>> $.format('Hello {world}, {again}', {world: "universe", again: "testing"});
"Hello universe, testing"
>> $.format('Hello {0}, {1}', ["foo", "bar"]);
"Hello foo, bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment