Created
June 24, 2022 04:57
-
-
Save rndme/bf3e2079384058d9e2ca0b4d8d8b4114 to your computer and use it in GitHub Desktop.
string formatter native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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