Skip to content

Instantly share code, notes, and snippets.

@rndme
Created June 24, 2022 04:57
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 rndme/bf3e2079384058d9e2ca0b4d8d8b4114 to your computer and use it in GitHub Desktop.
Save rndme/bf3e2079384058d9e2ca0b4d8d8b4114 to your computer and use it in GitHub Desktop.
string formatter native
function fmt(String) { // modernized version of dean's tool in ie7.js
// Replace %n with arguments[n].
// e.g. fmt("%1 %2%3 %2a %1%3", "she", "se", "lls") == "she sells sea shells";
return String.replace(/%([\d])/g, fmt.call.bind([].at.bind(arguments)));
};
// fmt("this is a %2 script, ain't it %1?", "cool", "dan");
// fmt("this is a %2 script, ain't it %1?", "dan", "cool");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment